Skip to content

Commit dd2ba62

Browse files
authored
Merge pull request #166 from iMattPro/ticket/162
Show ideas statistics at bottom of ideas page
2 parents 6b14985 + 3cf004c commit dd2ba62

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

controller/index_controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function index()
5454
'U_VIEW_IN_PROGRESS'=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_DATE, 'status' => ext::$statuses['IN_PROGRESS']]),
5555
'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'),
5656
'U_MCP' => ($this->auth->acl_get('m_', $this->config['ideas_forum_id'])) ? append_sid("{$this->root_path}mcp.$this->php_ext", "f={$this->config['ideas_forum_id']}&i=main&mode=forum_view", true, $this->user->session_id) : '',
57+
'STATISTICS' => $this->entity->get_statistics(),
5758
));
5859

5960
// Assign breadcrumb template vars

factory/ideas.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,35 @@ public function get_idea_count()
296296
{
297297
return $this->idea_count ?? 0;
298298
}
299+
300+
/**
301+
* Get statistics - counts of total ideas and of each status type
302+
*
303+
* @return array
304+
*/
305+
public function get_statistics()
306+
{
307+
// the CASE/WHEN SQL approach is better for performance than processing in PHP
308+
$sql = 'SELECT
309+
COUNT(*) as total,
310+
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['IMPLEMENTED'] . ' THEN 1 ELSE 0 END) as implemented,
311+
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['IN_PROGRESS'] . ' THEN 1 ELSE 0 END) as in_progress,
312+
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['DUPLICATE'] . ' THEN 1 ELSE 0 END) as duplicate,
313+
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['INVALID'] . ' THEN 1 ELSE 0 END) as invalid,
314+
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['NEW'] . ' THEN 1 ELSE 0 END) as new
315+
FROM ' . $this->table_ideas;
316+
317+
$result = $this->db->sql_query($sql);
318+
$row = $this->db->sql_fetchrow($result);
319+
$this->db->sql_freeresult($result);
320+
321+
return [
322+
'total' => (int) $row['total'],
323+
'implemented' => (int) $row['implemented'],
324+
'in_progress' => (int) $row['in_progress'],
325+
'duplicate' => (int) $row['duplicate'],
326+
'invalid' => (int) $row['invalid'],
327+
'new' => (int) $row['new'],
328+
];
329+
}
299330
}

language/en/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
1 => '%s point.',
102102
2 => '%s points.',
103103
],
104+
'TOTAL_POSTED_IDEAS' => 'Total ideas posted',
104105

105106
'UPDATED_VOTE' => 'Successfully updated vote!',
106107

styles/prosilver/template/index_body.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ <h2>{{ lang('IDEAS_TITLE') }}</h2>
4040
{# IN PROGRESS IDEAS #}
4141
{{ _self.ideas_section(lang('IN_PROGRESS_IDEAS'), in_progress_ideas, U_VIEW_IN_PROGRESS, 'fa-clock-o', lang('VIEW_IN_PROGRESS')) }}
4242

43-
<br><br>
43+
<div class="stat-block statistics">
44+
<h3>{{ lang('STATISTICS') }}</h3>
45+
<p>
46+
{{ lang('TOTAL_POSTED_IDEAS') }} <strong>{{ STATISTICS.total }}</strong> &bull; {{ lang('LIST_IMPLEMENTED') }} <strong>{{ STATISTICS.implemented }}</strong> &bull; {{ lang('LIST_IN_PROGRESS') }} <strong>{{ STATISTICS.in_progress }}</strong>
47+
</p>
48+
</div>
4449

4550
{% include 'overall_footer.html' %}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\tests\ideas;
12+
13+
class get_statistics_test extends ideas_base
14+
{
15+
public function test_get_statistics()
16+
{
17+
$object = $this->get_ideas_object();
18+
19+
$stats = $object->get_statistics();
20+
21+
self::assertEquals(7, $stats['total']);
22+
self::assertEquals(1, $stats['implemented']);
23+
self::assertEquals(1, $stats['in_progress']);
24+
self::assertEquals(0, $stats['duplicate']);
25+
self::assertEquals(0, $stats['invalid']);
26+
self::assertEquals(5, $stats['new']);
27+
}
28+
}

0 commit comments

Comments
 (0)