summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-03-12 21:36:52 -0400
committerFrederic Guillot <fred@kanboard.net>2017-03-12 21:36:52 -0400
commit9b34631135f29480dda3ed2df463fbb5aab7c9e4 (patch)
tree46da2f342a440cc699b7aa9c61bd18d0d2ea01f5 /app/Model
parentf6b42eb8024b7db959f6d75118b3de0f96301262 (diff)
Simplify dashboard to use new tasks list view
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/ProjectModel.php21
-rw-r--r--app/Model/SubtaskModel.php67
-rw-r--r--app/Model/TaskFinderModel.php24
3 files changed, 22 insertions, 90 deletions
diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php
index aa7c002d..f59cae85 100644
--- a/app/Model/ProjectModel.php
+++ b/app/Model/ProjectModel.php
@@ -297,27 +297,6 @@ class ProjectModel extends Base
}
/**
- * Get project summary for a list of project
- *
- * @access public
- * @param array $project_ids List of project id
- * @return \PicoDb\Table
- */
- public function getQueryColumnStats(array $project_ids)
- {
- if (empty($project_ids)) {
- return $this->db->table(ProjectModel::TABLE)->eq(ProjectModel::TABLE.'.id', 0);
- }
-
- return $this->db
- ->table(ProjectModel::TABLE)
- ->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name')
- ->join(UserModel::TABLE, 'id', 'owner_id')
- ->in(self::TABLE.'.id', $project_ids)
- ->callback(array($this, 'applyColumnStats'));
- }
-
- /**
* Get query for list of project without column statistics
*
* @access public
diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php
index c62ddb53..9d047d90 100644
--- a/app/Model/SubtaskModel.php
+++ b/app/Model/SubtaskModel.php
@@ -70,35 +70,6 @@ class SubtaskModel extends Base
}
/**
- * Get the query to fetch subtasks assigned to a user
- *
- * @access public
- * @param integer $userId
- * @param array $status
- * @return \PicoDb\Table
- */
- public function getUserQuery($userId, array $status)
- {
- return $this->db->table(SubtaskModel::TABLE)
- ->columns(
- SubtaskModel::TABLE.'.*',
- TaskModel::TABLE.'.project_id',
- TaskModel::TABLE.'.color_id',
- TaskModel::TABLE.'.title AS task_name',
- ProjectModel::TABLE.'.name AS project_name'
- )
- ->subquery($this->subtaskTimeTrackingModel->getTimerQuery($userId), 'timer_start_date')
- ->eq('user_id', $userId)
- ->eq(ProjectModel::TABLE.'.is_active', ProjectModel::ACTIVE)
- ->eq(ColumnModel::TABLE.'.hide_in_dashboard', 0)
- ->in(SubtaskModel::TABLE.'.status', $status)
- ->join(TaskModel::TABLE, 'id', 'task_id')
- ->join(ProjectModel::TABLE, 'id', 'project_id', TaskModel::TABLE)
- ->join(ColumnModel::TABLE, 'id', 'column_id', TaskModel::TABLE)
- ->callback(array($this, 'addStatusName'));
- }
-
- /**
* Get common query
*
* @return \PicoDb\Table
@@ -149,6 +120,24 @@ class SubtaskModel extends Base
}
/**
+ * Get subtasks for a list of tasks and a given assignee
+ *
+ * @param array $taskIds
+ * @param integer $userId
+ * @return array
+ */
+ public function getAllByTaskIdsAndAssignee(array $taskIds, $userId)
+ {
+ if (empty($taskIds)) {
+ return array();
+ }
+
+ return $this->subtaskListFormatter
+ ->withQuery($this->getQuery()->in('task_id', $taskIds)->eq(self::TABLE.'.user_id', $userId))
+ ->format();
+ }
+
+ /**
* Get a subtask by the id
*
* @access public
@@ -310,24 +299,4 @@ class SubtaskModel extends Base
$values['user_id'] = isset($values['user_id']) ? $values['user_id'] : 0;
$this->hook->reference('model:subtask:creation:prepare', $values);
}
-
- /**
- * Add subtask status status to the resultset
- *
- * @access public
- * @param array $subtasks Subtasks
- * @return array
- */
- public function addStatusName(array $subtasks)
- {
- $status = $this->getStatusList();
-
- foreach ($subtasks as &$subtask) {
- $subtask['status_name'] = $status[$subtask['status']];
- $subtask['timer_start_date'] = isset($subtask['timer_start_date']) ? $subtask['timer_start_date'] : 0;
- $subtask['is_timer_started'] = ! empty($subtask['timer_start_date']);
- }
-
- return $subtasks;
- }
}
diff --git a/app/Model/TaskFinderModel.php b/app/Model/TaskFinderModel.php
index b610a371..09193a41 100644
--- a/app/Model/TaskFinderModel.php
+++ b/app/Model/TaskFinderModel.php
@@ -59,27 +59,11 @@ class TaskFinderModel extends Base
*/
public function getUserQuery($user_id)
{
- return $this->db
- ->table(TaskModel::TABLE)
- ->columns(
- TaskModel::TABLE.'.id',
- TaskModel::TABLE.'.title',
- TaskModel::TABLE.'.date_due',
- TaskModel::TABLE.'.date_creation',
- TaskModel::TABLE.'.project_id',
- TaskModel::TABLE.'.column_id',
- TaskModel::TABLE.'.color_id',
- TaskModel::TABLE.'.priority',
- TaskModel::TABLE.'.time_spent',
- TaskModel::TABLE.'.time_estimated',
- TaskModel::TABLE.'.is_active',
- TaskModel::TABLE.'.creator_id',
- ProjectModel::TABLE.'.name AS project_name',
- ColumnModel::TABLE.'.title AS column_title'
- )
- ->join(ProjectModel::TABLE, 'id', 'project_id')
- ->join(ColumnModel::TABLE, 'id', 'column_id')
+ return $this->getExtendedQuery()
+ ->beginOr()
->eq(TaskModel::TABLE.'.owner_id', $user_id)
+ ->addCondition(TaskModel::TABLE.".id IN (SELECT task_id FROM ".SubtaskModel::TABLE." WHERE ".SubtaskModel::TABLE.".user_id='$user_id')")
+ ->closeOr()
->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN)
->eq(ProjectModel::TABLE.'.is_active', ProjectModel::ACTIVE)
->eq(ColumnModel::TABLE.'.hide_in_dashboard', 0);