summaryrefslogtreecommitdiff
path: root/app/Pagination/TaskPagination.php
blob: 29706cd5af6e3436d91c353a1a0f463688300a69 (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\Core\Paginator;
use Kanboard\Model\TaskModel;

/**
 * Class TaskPagination
 *
 * @package Kanboard\Pagination
 * @author  Frederic Guillot
 */
class TaskPagination extends Base
{
    /**
     * Get dashboard pagination
     *
     * @access public
     * @param  integer $userId
     * @param  string  $method
     * @param  integer $max
     * @return Paginator
     */
    public function getDashboardPaginator($userId, $method, $max)
    {
        $query = $this->taskFinderModel->getUserQuery($userId);
        $this->hook->reference('pagination:dashboard:task:query', $query);

        return $this->paginator
            ->setUrl('DashboardController', $method, array('pagination' => 'tasks', 'user_id' => $userId))
            ->setMax($max)
            ->setOrder(TaskModel::TABLE.'.id')
            ->setQuery($query)
            ->setFormatter($this->taskListFormatter)
            ->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks');
    }

    public function getDashboardPerProjectPaginator($userId, $method, $max)
    {
        $query = $this->taskFinderModel->getUserQuery($userId);
        $this->hook->reference('pagination:dashboard:task:query', $query);

        return $this->paginator
            ->setUrl('DashboardController', $method, array('pagination' => 'tasks', 'user_id' => $userId))
            ->setMax($max)
            ->setOrder(TaskModel::TABLE.'.project_id, '.TaskModel::TABLE.'.id')
            ->setQuery($query)
            ->setFormatter($this->taskListProjectFormatter)
            ->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks');
    }

}