summaryrefslogtreecommitdiff
path: root/app/Model/ProjectTaskPriorityModel.php
blob: c1a0257afa5aa826304acc6a522576bfbf678094 (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
<?php

namespace Kanboard\Model;

use Kanboard\Core\Base;

/**
 * Project Task Priority Model
 *
 * @package  Kanboard\Model
 * @author   Frederic Guillot
 */
class ProjectTaskPriorityModel extends Base
{
    /**
     * Get Priority range from a project
     *
     * @access public
     * @param  array $project
     * @return array
     */
    public function getPriorities(array $project)
    {
        $range = range($project['priority_start'], $project['priority_end']);
        return array_combine($range, $range);
    }

    /**
     * Get task priority settings
     *
     * @access public
     * @param  int $project_id
     * @return array|null
     */
    public function getPrioritySettings($project_id)
    {
        return $this->db
            ->table(ProjectModel::TABLE)
            ->columns('priority_default', 'priority_start', 'priority_end')
            ->eq('id', $project_id)
            ->findOne();
    }

    /**
     * Get default task priority
     *
     * @access public
     * @param  int $project_id
     * @return int
     */
    public function getDefaultPriority($project_id)
    {
        return $this->db->table(ProjectModel::TABLE)->eq('id', $project_id)->findOneColumn('priority_default') ?: 0;
    }

    /**
     * Get priority for a destination project
     *
     * @access public
     * @param  integer $dst_project_id
     * @param  integer $priority
     * @return integer
     */
    public function getPriorityForProject($dst_project_id, $priority)
    {
        $settings = $this->getPrioritySettings($dst_project_id);

        if ($priority >= $settings['priority_start'] && $priority <= $settings['priority_end']) {
            return $priority;
        }

        return $settings['priority_default'];
    }
}