summaryrefslogtreecommitdiff
path: root/app/Controller/Projectinfo.php
blob: a9498f4340eb8226334f2824780ca32870da4cd5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php

namespace Controller;

/**
 * Project Info controller (ActivityStream + completed tasks)
 *
 * @package controller
 * @author  Frederic Guillot
 */
class Projectinfo extends Base
{
    /**
     * Activity page for a project
     *
     * @access public
     */
    public function activity()
    {
        $project = $this->getProject();

        $this->response->html($this->template->layout('projectinfo/activity', array(
            'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
            'events' => $this->projectActivity->getProject($project['id']),
            'project' => $project,
            'title' => t('%s\'s activity', $project['name'])
        )));
    }

    /**
     * Task search for a given project
     *
     * @access public
     */
    public function search()
    {
        $project = $this->getProject();
        $search = $this->request->getStringParam('search');
        $nb_tasks = 0;

        $paginator = $this->paginator
                ->setUrl('projectinfo', 'search', array('search' => $search, 'project_id' => $project['id']))
                ->setMax(30)
                ->setOrder('tasks.id')
                ->setDirection('DESC');

        if ($search !== '') {

            $paginator
                ->setQuery($this->taskFinder->getSearchQuery($project['id'], $search))
                ->calculate();

            $nb_tasks = $paginator->getTotal();
        }

        $this->response->html($this->template->layout('projectinfo/search', array(
            'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
            'values' => array(
                'search' => $search,
                'controller' => 'projectinfo',
                'action' => 'search',
                'project_id' => $project['id'],
            ),
            'paginator' => $paginator,
            'project' => $project,
            'columns' => $this->board->getColumnsList($project['id']),
            'categories' => $this->category->getList($project['id'], false),
            'title' => t('Search in the project "%s"', $project['name']).($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '')
        )));
    }

    /**
     * List of completed tasks for a given project
     *
     * @access public
     */
    public function tasks()
    {
        $project = $this->getProject();
        $paginator = $this->paginator
                ->setUrl('projectinfo', 'tasks', array('project_id' => $project['id']))
                ->setMax(30)
                ->setOrder('tasks.id')
                ->setDirection('DESC')
                ->setQuery($this->taskFinder->getClosedTaskQuery($project['id']))
                ->calculate();

        $this->response->html($this->template->layout('projectinfo/tasks', array(
            'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
            'project' => $project,
            'columns' => $this->board->getColumnsList($project['id']),
            'categories' => $this->category->getList($project['id'], false),
            'paginator' => $paginator,
            'title' => t('Completed tasks for "%s"', $project['name']).' ('.$paginator->getTotal().')'
        )));
    }
}