Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions controller/index_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function index()
'U_VIEW_IN_PROGRESS'=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_DATE, 'status' => ext::$statuses['IN_PROGRESS']]),
'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'),
'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) : '',
'STATISTICS' => $this->entity->get_statistics(),
));

// Assign breadcrumb template vars
Expand Down
31 changes: 31 additions & 0 deletions factory/ideas.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,35 @@ public function get_idea_count()
{
return $this->idea_count ?? 0;
}

/**
* Get statistics - counts of total ideas and of each status type
*
* @return array
*/
public function get_statistics()
{
// the CASE/WHEN SQL approach is better for performance than processing in PHP
$sql = 'SELECT
COUNT(*) as total,
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['IMPLEMENTED'] . ' THEN 1 ELSE 0 END) as implemented,
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['IN_PROGRESS'] . ' THEN 1 ELSE 0 END) as in_progress,
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['DUPLICATE'] . ' THEN 1 ELSE 0 END) as duplicate,
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['INVALID'] . ' THEN 1 ELSE 0 END) as invalid,
SUM(CASE WHEN idea_status = ' . (int) ext::$statuses['NEW'] . ' THEN 1 ELSE 0 END) as new
FROM ' . $this->table_ideas;

$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

return [
'total' => (int) $row['total'],
'implemented' => (int) $row['implemented'],
'in_progress' => (int) $row['in_progress'],
'duplicate' => (int) $row['duplicate'],
'invalid' => (int) $row['invalid'],
'new' => (int) $row['new'],
];
}
}
1 change: 1 addition & 0 deletions language/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
1 => '%s point.',
2 => '%s points.',
],
'TOTAL_POSTED_IDEAS' => 'Total ideas posted',

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

Expand Down
7 changes: 6 additions & 1 deletion styles/prosilver/template/index_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ <h2>{{ lang('IDEAS_TITLE') }}</h2>
{# IN PROGRESS IDEAS #}
{{ _self.ideas_section(lang('IN_PROGRESS_IDEAS'), in_progress_ideas, U_VIEW_IN_PROGRESS, 'fa-clock-o', lang('VIEW_IN_PROGRESS')) }}

<br><br>
<div class="stat-block statistics">
<h3>{{ lang('STATISTICS') }}</h3>
<p>
{{ 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>
</p>
</div>

{% include 'overall_footer.html' %}
28 changes: 28 additions & 0 deletions tests/ideas/get_statistics_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
*
* Ideas extension for the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace phpbb\ideas\tests\ideas;

class get_statistics_test extends ideas_base
{
public function test_get_statistics()
{
$object = $this->get_ideas_object();

$stats = $object->get_statistics();

self::assertEquals(7, $stats['total']);
self::assertEquals(1, $stats['implemented']);
self::assertEquals(1, $stats['in_progress']);
self::assertEquals(0, $stats['duplicate']);
self::assertEquals(0, $stats['invalid']);
self::assertEquals(5, $stats['new']);
}
}