summaryrefslogtreecommitdiff
path: root/app/Pagination/DashboardPagination.php
blob: 0149a42bff0fee96e63ce0d1d5bf36ee04cd95b1 (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
50
51
52
53
54
<?php

namespace Kanboard\Pagination;

use Kanboard\Core\Base;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskModel;

/**
 * Class DashboardPagination
 *
 * @package Kanboard\Pagination
 * @author  Frederic Guillot
 */
class DashboardPagination extends Base
{
    /**
     * Get user listing pagination
     *
     * @access public
     * @param  integer $userId
     * @return array
     */
    public function getOverview($userId)
    {
        $paginators = array();
        $projects = $this->projectUserRoleModel->getActiveProjectsByUser($userId);

        foreach ($projects as $projectId => $projectName) {

            $query = $this->taskFinderModel->getUserQuery($userId)->eq(ProjectModel::TABLE.'.id', $projectId);
            $this->hook->reference('pagination:dashboard:task:query', $query);

            $paginator = $this->paginator
                ->setUrl('DashboardController', 'show', array('user_id' => $userId))
                ->setMax(50)
                ->setOrder(TaskModel::TABLE.'.priority')
                ->setDirection('DESC')
                ->setFormatter($this->taskListSubtaskAssigneeFormatter->withUserId($userId))
                ->setQuery($query)
                ->calculate();

            if ($paginator->getTotal() > 0) {
                $paginators[] = array(
                    'project_id'   => $projectId,
                    'project_name' => $projectName,
                    'paginator'    => $paginator,
                );
            }
        }

        return $paginators;
    }
}