summaryrefslogtreecommitdiff
path: root/app/Model/ProjectPaginator.php
blob: 9f1c39f0d592fe0b65bbff44132f2d3ad72c67b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
    }
}