Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game limits #65

Merged
merged 3 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Display progress against limits on player page
  • Loading branch information
ejk committed Jun 11, 2020
commit 1524b210535d45e528d266e7c687c1c8783fd3d8
19 changes: 17 additions & 2 deletions src/Controller/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public function index($pid) {
}

if ($player) {
$db = \Drupal::database();
$summergame_settings = \Drupal::config('summergame.settings');
$player_access = summergame_player_access($player['pid']);
$current_game_term = $summergame_settings->get('summergame_current_game_term');

// Check if player's score card is private and we don't have access
if (!$player['show_myscore'] && !$player_access) {
Expand Down Expand Up @@ -132,7 +134,6 @@ public function index($pid) {
*/
// Determine Classic Reading Game status
$completion_gamecode = $summergame_settings->get('summergame_completion_gamecode');
$db = \Drupal::database();
$row = $db->query("SELECT * FROM sg_ledger WHERE pid = " . $player['pid'] .
" AND metadata LIKE '%gamecode:$completion_gamecode%'")->fetchObject();
if ($row->lid) {
Expand Down Expand Up @@ -165,6 +166,19 @@ public function index($pid) {
$balances = uc_summergame_get_player_balances($player['pid']);
}

// Get player progress against limits
$progress = [];
$game_limits = json_decode($summergame_settings->get('summergame_game_limits'), TRUE);

foreach ($game_limits as $ledger_type => $game_limit) {
$sql = "SELECT SUM(points) AS total FROM sg_ledger " .
"WHERE pid = :pid " .
"AND type = :type " .
"AND game_term = :game_term";
$type_total = $db->query($sql, [':pid' => $pid, ':type' => $ledger_type, ':game_term' => $current_game_term])->fetchField();
$progress[] = ['type' => $ledger_type, 'total' => ($type_total ?? 0), 'limit' => $game_limit];
}

// Prepare Scorecards
$render[] = [
'#cache' => [
Expand All @@ -178,7 +192,8 @@ public function index($pid) {
'#other_players' => $other_players,
'#points' => summergame_get_player_points($player['pid']),
'#balances' => $balances,
'#summergame_current_game_term' => $summergame_settings->get('summergame_current_game_term'),
'#progress' => $progress,
'#summergame_current_game_term' => $current_game_term,
'#summergame_shop_message_threshold' => $summergame_settings->get('summergame_shop_message_threshold'),
'#summergame_shop_message' => $summergame_settings->get('summergame_shop_message'),
'#completed_classic' => $completed_classic,
Expand Down
1 change: 1 addition & 0 deletions summergame.module
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function summergame_theme() {
'other_players' => NULL,
'points' => NULL,
'balances' => NULL,
'progress' => NULL,
'summergame_current_game_term' => NULL,
'summergame_shop_message_threshold' => NULL,
'summergame_shop_message' => NULL,
Expand Down
12 changes: 12 additions & 0 deletions templates/summergame-player-info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<p>{{ summergame_shop_message|raw }}</p>
{% endif %}
{% endif %}
{% if progress|length %}
<h2>Game Point Limit Progress</h2>
<table class="account-summary not-fixed-table">
<tr><td><strong>Point Type</strong></td><td><strong>Progress</strong></td></tr>
{% for row in progress %}
<tr><td>{{ row.type }}</td><td>{{ row.total }} / {{ row.limit }}</td></tr>
{% endfor %}
</table>
{% if (summergame_shop_message_threshold > 0) and (attribute(points, summergame_current_game_term).total > summergame_shop_message_threshold) %}
<p>{{ summergame_shop_message|raw }}</p>
{% endif %}
{% endif %}
</div>
<div id="player-info-table">
<h2>Player Details (<a href="/summergame/player/{{ player.pid }}/edit">Edit Player Info</a>)</h2>
Expand Down