summaryrefslogtreecommitdiff
path: root/app/Helper/Task.php
blob: d2c59ee956c82ca9bb6be2bc976b51f574e36da4 (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
<?php

namespace Kanboard\Helper;

use Kanboard\Core\Base;

/**
 * Task helpers
 *
 * @package helper
 * @author  Frederic Guillot
 */
class Task extends Base
{
    /**
     * Local cache for project columns
     *
     * @access private
     * @var array
     */
    private $columns = array();

    public function getColors()
    {
        return $this->color->getList();
    }

    public function recurrenceTriggers()
    {
        return $this->task->getRecurrenceTriggerList();
    }

    public function recurrenceTimeframes()
    {
        return $this->task->getRecurrenceTimeframeList();
    }

    public function recurrenceBasedates()
    {
        return $this->task->getRecurrenceBasedateList();
    }

    public function canRemove(array $task)
    {
        return $this->taskPermission->canRemoveTask($task);
    }

    public function selectPriority(array $project, array $values)
    {
        $html = '';

        if ($project['priority_end'] > $project['priority_start']) {
            $range = range($project['priority_start'], $project['priority_end']);
            $options = array_combine($range, $range);
            $values += array('priority' => $project['priority_default']);

            $html .= $this->helper->form->label(t('Priority'), 'priority');
            $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"'));
        }

        return $html;
    }

    public function formatPriority(array $project, array $task)
    {
        $html = '';

        if ($project['priority_end'] > $project['priority_start']) {
            $html .= '<span class="task-board-priority" title="'.t('Task priority').'">';
            $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']);
            $html .= '</span>';
        }

        return $html;
    }

    public function getProgress($task)
    {
        if (! isset($this->columns[$task['project_id']])) {
            $this->columns[$task['project_id']] = $this->board->getColumnsList($task['project_id']);
        }

        return $this->task->getProgress($task, $this->columns[$task['project_id']]);
    }
}