From 3df63e051fac84cec98c912668722f87d6e8183e Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 9 Nov 2014 12:47:49 -0500 Subject: Add projects to the dashboard and rename some methods --- app/Model/Project.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'app/Model/Project.php') diff --git a/app/Model/Project.php b/app/Model/Project.php index 32b7fcbe..ad64edcd 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -95,6 +95,40 @@ class Project extends Base return (bool) $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->count(); } + /** + * Get project summary for a list of project (number of tasks for each column) + * + * @access public + * @param array $project_ids List of project id + * @param integer $status Project status + * @param string $order Sort on this column + * @param string $direction Sorting direction + * @return array Project properties + */ + public function getSummary(array $project_ids, $status = self::ACTIVE, $order = 'last_modified', $direction = 'desc') + { + if (empty($project_ids)) { + return array(); + } + + $projects = $this->db->table(self::TABLE) + ->in('id', $project_ids) + ->eq('is_active', $status) + ->orderby($order, $direction) + ->findAll(); + + foreach ($projects as &$project) { + + $project['columns'] = $this->board->getColumns($project['id']); + + foreach ($project['columns'] as &$column) { + $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']); + } + } + + return $projects; + } + /** * Get all projects, optionaly fetch stats for each project and can check users permissions * @@ -192,7 +226,7 @@ class Project extends Base public function getStats($project_id) { $stats = array(); - $columns = $this->board->getcolumns($project_id); + $columns = $this->board->getColumns($project_id); $stats['nb_active_tasks'] = 0; foreach ($columns as &$column) { -- cgit v1.2.3