diff --git a/controller/index_controller.php b/controller/index_controller.php index dabe106..a01f499 100644 --- a/controller/index_controller.php +++ b/controller/index_controller.php @@ -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 diff --git a/factory/ideas.php b/factory/ideas.php index e357754..e5efe9d 100644 --- a/factory/ideas.php +++ b/factory/ideas.php @@ -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'], + ]; + } } diff --git a/language/en/common.php b/language/en/common.php index d06b64e..11be312 100644 --- a/language/en/common.php +++ b/language/en/common.php @@ -101,6 +101,7 @@ 1 => '%s point.', 2 => '%s points.', ], + 'TOTAL_POSTED_IDEAS' => 'Total ideas posted', 'UPDATED_VOTE' => 'Successfully updated vote!', diff --git a/styles/prosilver/template/index_body.html b/styles/prosilver/template/index_body.html index 05403f5..240a16d 100644 --- a/styles/prosilver/template/index_body.html +++ b/styles/prosilver/template/index_body.html @@ -40,6 +40,11 @@
+ {{ lang('TOTAL_POSTED_IDEAS') }} {{ STATISTICS.total }} • {{ lang('LIST_IMPLEMENTED') }} {{ STATISTICS.implemented }} • {{ lang('LIST_IN_PROGRESS') }} {{ STATISTICS.in_progress }} +
+