diff options
Diffstat (limited to 'app/Model/SubtaskPaginator.php')
-rw-r--r-- | app/Model/SubtaskPaginator.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/app/Model/SubtaskPaginator.php b/app/Model/SubtaskPaginator.php new file mode 100644 index 00000000..8ccbd696 --- /dev/null +++ b/app/Model/SubtaskPaginator.php @@ -0,0 +1,68 @@ +<?php + +namespace Model; + +/** + * Subtask Paginator + * + * @package model + * @author Frederic Guillot + */ +class SubtaskPaginator extends Base +{ + /** + * Get all subtasks assigned to a user + * + * @access public + * @param integer $user_id User id + * @param array $status List of status + * @param integer $offset Offset + * @param integer $limit Limit + * @param string $column Sorting column + * @param string $direction Sorting direction + * @return array + */ + public function userSubtasks($user_id, array $status, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'asc') + { + $status_list = $this->subTask->getStatusList(); + + $subtasks = $this->db->table(SubTask::TABLE) + ->columns( + SubTask::TABLE.'.*', + Task::TABLE.'.project_id', + Task::TABLE.'.color_id', + Project::TABLE.'.name AS project_name' + ) + ->eq('user_id', $user_id) + ->in(SubTask::TABLE.'.status', $status) + ->join(Task::TABLE, 'id', 'task_id') + ->join(Project::TABLE, 'id', 'project_id', Task::TABLE) + ->offset($offset) + ->limit($limit) + ->orderBy($column, $direction) + ->findAll(); + + foreach ($subtasks as &$subtask) { + $subtask['status_name'] = $status_list[$subtask['status']]; + } + + return $subtasks; + } + + /** + * Count all subtasks assigned to the user + * + * @access public + * @param integer $user_id User id + * @param array $status List of status + * @return integer + */ + public function countUserSubtasks($user_id, array $status) + { + return $this->db + ->table(SubTask::TABLE) + ->eq('user_id', $user_id) + ->in('status', $status) + ->count(); + } +} |