1<?php
2
3namespace Kanboard\Controller;
4
5use Kanboard\Filter\TaskProjectFilter;
6use Kanboard\Model\TaskModel;
7
8/**
9 * Task List Controller
10 *
11 * @package  Kanboard\Controller
12 * @author   Frederic Guillot
13 */
14class TaskListController extends BaseController
15{
16    /**
17     * Show list view for projects
18     *
19     * @access public
20     */
21    public function show()
22    {
23        $project = $this->getProject();
24        $search = $this->helper->projectHeader->getSearchQuery($project);
25
26        if ($this->request->getIntegerParam('show_subtasks') !== 0 ||
27            $this->request->getIntegerParam('hide_subtasks') !== 0 ||
28            $this->request->getStringParam('direction') !== '' ||
29            $this->request->getStringParam('order') !== '') {
30            $this->checkReusableGETCSRFParam();
31        }
32
33        if ($this->request->getIntegerParam('show_subtasks')) {
34            session_set('subtaskListToggle', true);
35        } elseif ($this->request->getIntegerParam('hide_subtasks')) {
36            session_set('subtaskListToggle', false);
37        }
38
39        if ($this->userSession->hasSubtaskListActivated()) {
40            $formatter = $this->taskListSubtaskFormatter;
41        } else {
42            $formatter = $this->taskListFormatter;
43        }
44
45        list($order, $direction) = $this->userSession->getListOrder($project['id']);
46        $direction = $this->request->getStringParam('direction', $direction);
47        $order = $this->request->getStringParam('order', $order);
48        $this->userSession->setListOrder($project['id'], $order, $direction);
49
50        $paginator = $this->paginator
51            ->setUrl('TaskListController', 'show', array('project_id' => $project['id'], 'csrf_token' => $this->token->getReusableCSRFToken()))
52            ->setMax(30)
53            ->setOrder($order)
54            ->setDirection($direction)
55            ->setFormatter($formatter)
56            ->setQuery($this->taskLexer
57                ->build($search)
58                ->withFilter(new TaskProjectFilter($project['id']))
59                ->getQuery()
60            )
61            ->calculate();
62
63        $this->response->html($this->helper->layout->app('task_list/listing', array(
64            'project'     => $project,
65            'title'       => $project['name'],
66            'description' => $this->helper->projectHeader->getDescription($project),
67            'paginator'   => $paginator,
68        )));
69    }
70}
71