summaryrefslogtreecommitdiff
path: root/app/Model/ProjectPaginator.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-15 21:49:06 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-15 21:49:06 -0500
commitaa6fffb05a7d84a36991341610675499b6ea8a79 (patch)
treee0eb08e76e61dfc5cc56ae0bfb7daf7dda49fc99 /app/Model/ProjectPaginator.php
parentaf93754ec99d8748677dc2cfd92137a8698a90fa (diff)
Add pagination and sorting to the dashboard
Diffstat (limited to 'app/Model/ProjectPaginator.php')
-rw-r--r--app/Model/ProjectPaginator.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/Model/ProjectPaginator.php b/app/Model/ProjectPaginator.php
new file mode 100644
index 00000000..9f1c39f0
--- /dev/null
+++ b/app/Model/ProjectPaginator.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Model;
+
+/**
+ * Project Paginator
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class ProjectPaginator extends Base
+{
+ /**
+ * 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 $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function projectSummaries(array $project_ids, $offset = 0, $limit = 25, $column = 'name', $direction = 'asc')
+ {
+ if (empty($project_ids)) {
+ return array();
+ }
+
+ $projects = $this->db
+ ->table(Project::TABLE)
+ ->in('id', $project_ids)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $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;
+ }
+}