diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Filter/TaskCommentFilter.php | 14 | ||||
-rw-r--r-- | app/Filter/TaskLinkFilter.php | 11 | ||||
-rw-r--r-- | app/Filter/TaskSubtaskAssigneeFilter.php | 15 | ||||
-rw-r--r-- | app/Filter/TaskTagFilter.php | 22 |
4 files changed, 17 insertions, 45 deletions
diff --git a/app/Filter/TaskCommentFilter.php b/app/Filter/TaskCommentFilter.php index 1bb230e9..e5d91117 100644 --- a/app/Filter/TaskCommentFilter.php +++ b/app/Filter/TaskCommentFilter.php @@ -55,13 +55,7 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface */ public function apply() { - $task_ids = $this->getTaskIdsWithGivenComment(); - - if (empty($task_ids)) { - $task_ids = array(-1); - } - - $this->query->in(TaskModel::TABLE.'.id', $task_ids); + $this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery()); return $this; } @@ -72,11 +66,11 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface * @access public * @return array */ - protected function getTaskIdsWithGivenComment() + protected function getSubQuery() { return $this->db ->table(CommentModel::TABLE) - ->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%') - ->findAllByColumn(CommentModel::TABLE.'.task_id'); + ->columns(CommentModel::TABLE.'.task_id') + ->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%'); } } diff --git a/app/Filter/TaskLinkFilter.php b/app/Filter/TaskLinkFilter.php index 98cd597f..0fa80d5c 100644 --- a/app/Filter/TaskLinkFilter.php +++ b/app/Filter/TaskLinkFilter.php @@ -57,13 +57,7 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface */ public function apply() { - $task_ids = $this->getSubQuery()->findAllByColumn('task_id'); - - if (! empty($task_ids)) { - $this->query->in(TaskModel::TABLE.'.id', $task_ids); - } else { - $this->query->eq(TaskModel::TABLE.'.id', 0); // No match - } + $this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery()); } /** @@ -76,8 +70,7 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface { return $this->db->table(TaskLinkModel::TABLE) ->columns( - TaskLinkModel::TABLE.'.task_id', - LinkModel::TABLE.'.label' + TaskLinkModel::TABLE.'.task_id' ) ->join(LinkModel::TABLE, 'id', 'link_id', TaskLinkModel::TABLE) ->ilike(LinkModel::TABLE.'.label', $this->value); diff --git a/app/Filter/TaskSubtaskAssigneeFilter.php b/app/Filter/TaskSubtaskAssigneeFilter.php index 46553a3d..1096bf64 100644 --- a/app/Filter/TaskSubtaskAssigneeFilter.php +++ b/app/Filter/TaskSubtaskAssigneeFilter.php @@ -78,13 +78,7 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface */ public function apply() { - $task_ids = $this->getSubQuery()->findAllByColumn('task_id'); - - if (! empty($task_ids)) { - $this->query->in(TaskModel::TABLE.'.id', $task_ids); - } else { - $this->query->eq(TaskModel::TABLE.'.id', 0); // No match - } + $this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery()); } /** @@ -96,12 +90,7 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface protected function getSubQuery() { $subquery = $this->db->table(SubtaskModel::TABLE) - ->columns( - SubtaskModel::TABLE.'.user_id', - SubtaskModel::TABLE.'.task_id', - UserModel::TABLE.'.name', - UserModel::TABLE.'.username' - ) + ->columns(SubtaskModel::TABLE.'.task_id') ->join(UserModel::TABLE, 'id', 'user_id', SubtaskModel::TABLE) ->neq(SubtaskModel::TABLE.'.status', SubtaskModel::STATUS_DONE); diff --git a/app/Filter/TaskTagFilter.php b/app/Filter/TaskTagFilter.php index 98be5554..e07f65cc 100644 --- a/app/Filter/TaskTagFilter.php +++ b/app/Filter/TaskTagFilter.php @@ -57,37 +57,33 @@ class TaskTagFilter extends BaseFilter implements FilterInterface public function apply() { if ($this->value === 'none') { - $task_ids = $this->getTaskIdsWithoutTags(); + $sub_query = $this->getQueryOfTaskIdsWithoutTags(); } else { - $task_ids = $this->getTaskIdsWithGivenTag(); + $sub_query = $this->getQueryOfTaskIdsWithGivenTag(); } - if (empty($task_ids)) { - $task_ids = array(-1); - } - - $this->query->in(TaskModel::TABLE.'.id', $task_ids); + $this->query->inSubquery(TaskModel::TABLE.'.id', $sub_query); return $this; } - protected function getTaskIdsWithoutTags() + protected function getQueryOfTaskIdsWithoutTags() { return $this->db ->table(TaskModel::TABLE) + ->columns(TaskModel::TABLE . '.id') ->asc(TaskModel::TABLE . '.project_id') ->left(TaskTagModel::TABLE, 'tg', 'task_id', TaskModel::TABLE, 'id') - ->isNull('tg.tag_id') - ->findAllByColumn(TaskModel::TABLE . '.id'); + ->isNull('tg.tag_id'); } - protected function getTaskIdsWithGivenTag() + protected function getQueryOfTaskIdsWithGivenTag() { return $this->db ->table(TagModel::TABLE) + ->columns(TaskTagModel::TABLE.'.task_id') ->ilike(TagModel::TABLE.'.name', $this->value) ->asc(TagModel::TABLE.'.project_id') - ->join(TaskTagModel::TABLE, 'tag_id', 'id') - ->findAllByColumn(TaskTagModel::TABLE.'.task_id'); + ->join(TaskTagModel::TABLE, 'tag_id', 'id'); } } |