diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-02 16:36:10 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-02 16:36:10 -0400 |
commit | 10d577ad9d1b2976cdb080a7d7df3944e0db170f (patch) | |
tree | 8346340a1855db3db6ec7d412e1d1a0cf6cdd17e /app/Model/ProjectTaskPriorityModel.php | |
parent | 8e56148a6dda1f6b1a78a759e69e600b79bdddd2 (diff) |
Handle priority for task and project duplication
Diffstat (limited to 'app/Model/ProjectTaskPriorityModel.php')
-rw-r--r-- | app/Model/ProjectTaskPriorityModel.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Model/ProjectTaskPriorityModel.php b/app/Model/ProjectTaskPriorityModel.php new file mode 100644 index 00000000..c1a0257a --- /dev/null +++ b/app/Model/ProjectTaskPriorityModel.php @@ -0,0 +1,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']; + } +} |