summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Project.php34
-rw-r--r--app/Model/ProjectAnalytic.php2
-rw-r--r--app/Model/ProjectPaginator.php49
-rw-r--r--app/Model/SubTask.php32
-rw-r--r--app/Model/SubtaskPaginator.php68
-rw-r--r--app/Model/TaskFinder.php94
-rw-r--r--app/Model/TaskPaginator.php139
7 files changed, 260 insertions, 158 deletions
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 2abee2aa..8b842519 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -96,40 +96,6 @@ class Project extends Base
}
/**
- * Get project summary for a list of project (number of tasks for each column)
- *
- * @access public
- * @param array $project_ids List of project id
- * @param integer $status Project status
- * @param string $order Sort on this column
- * @param string $direction Sorting direction
- * @return array Project properties
- */
- public function getSummary(array $project_ids, $status = self::ACTIVE, $order = 'name', $direction = 'asc')
- {
- if (empty($project_ids)) {
- return array();
- }
-
- $projects = $this->db->table(self::TABLE)
- ->in('id', $project_ids)
- ->eq('is_active', $status)
- ->orderby($order, $direction)
- ->findAll();
-
- foreach ($projects as &$project) {
-
- $project['columns'] = $this->board->getColumns($project['id']);
-
- foreach ($project['columns'] as &$column) {
- $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
- }
- }
-
- return $projects;
- }
-
- /**
* Get all projects, optionaly fetch stats for each project and can check users permissions
*
* @access public
diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php
index 8ecbf1f0..b62248eb 100644
--- a/app/Model/ProjectAnalytic.php
+++ b/app/Model/ProjectAnalytic.php
@@ -57,7 +57,7 @@ class ProjectAnalytic extends Base
foreach ($tasks as $task) {
- $user = $users[$task['owner_id']];
+ $user = isset($users[$task['owner_id']]) ? $users[$task['owner_id']] : $users[0];
$total++;
if (! isset($metrics[$user])) {
diff --git a/app/Model/ProjectPaginator.php b/app/Model/ProjectPaginator.php
new file mode 100644
index 00000000..9f1c39f0
--- /dev/null
+++ b/app/Model/ProjectPaginator.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Model;
+
+/**
+ * Project Paginator
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class ProjectPaginator extends Base
+{
+ /**
+ * Get project summary for a list of project (number of tasks for each column)
+ *
+ * @access public
+ * @param array $project_ids List of project id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function projectSummaries(array $project_ids, $offset = 0, $limit = 25, $column = 'name', $direction = 'asc')
+ {
+ if (empty($project_ids)) {
+ return array();
+ }
+
+ $projects = $this->db
+ ->table(Project::TABLE)
+ ->in('id', $project_ids)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+
+ foreach ($projects as &$project) {
+
+ $project['columns'] = $this->board->getColumns($project['id']);
+
+ foreach ($project['columns'] as &$column) {
+ $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
+ }
+ }
+
+ return $projects;
+ }
+}
diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php
index f414da7f..886ad1f3 100644
--- a/app/Model/SubTask.php
+++ b/app/Model/SubTask.php
@@ -93,38 +93,6 @@ class SubTask extends Base
}
/**
- * Get all subtasks assigned to a user
- *
- * @access public
- * @param integer $user_id User id
- * @param array $status List of status
- * @return array
- */
- public function getAllByUser($user_id, array $status)
- {
- $status_list = $this->getStatusList();
- $subtasks = $this->db->table(self::TABLE)
- ->columns(
- self::TABLE.'.*',
- Task::TABLE.'.project_id',
- Task::TABLE.'.color_id',
- Project::TABLE.'.name AS project_name'
- )
- ->eq('user_id', $user_id)
- ->in(self::TABLE.'.status', $status)
- ->join(Task::TABLE, 'id', 'task_id')
- ->join(Project::TABLE, 'id', 'project_id', Task::TABLE)
- ->asc(Task::TABLE.'.id')
- ->findAll();
-
- foreach ($subtasks as &$subtask) {
- $subtask['status_name'] = $status_list[$subtask['status']];
- }
-
- return $subtasks;
- }
-
- /**
* Get a subtask by the id
*
* @access public
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();
+ }
+}
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 56795152..0e581025 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -15,10 +15,10 @@ class TaskFinder extends Base
/**
* Common request to fetch a list of tasks
*
- * @access private
+ * @access public
* @return \PicoDb\Table
*/
- private function prepareRequestList()
+ public function getQuery()
{
return $this->db
->table(Task::TABLE)
@@ -51,51 +51,6 @@ class TaskFinder extends Base
}
/**
- * Task search with pagination
- *
- * @access public
- * @param integer $project_id Project id
- * @param string $search Search terms
- * @param integer $offset Offset
- * @param integer $limit Limit
- * @param string $column Sorting column
- * @param string $direction Sorting direction
- * @return array
- */
- public function search($project_id, $search, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'DESC')
- {
- return $this->prepareRequestList()
- ->eq('project_id', $project_id)
- ->like('title', '%'.$search.'%')
- ->offset($offset)
- ->limit($limit)
- ->orderBy($column, $direction)
- ->findAll();
- }
-
- /**
- * Get all completed tasks with pagination
- *
- * @access public
- * @param integer $project_id Project id
- * @param integer $offset Offset
- * @param integer $limit Limit
- * @param string $column Sorting column
- * @param string $direction Sorting direction
- * @return array
- */
- public function getClosedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC')
- {
- return $this->prepareRequestList()
- ->eq('project_id', $project_id)
- ->eq('is_active', Task::STATUS_CLOSED)
- ->offset($offset)
- ->limit($limit)
- ->orderBy($column, $direction)
- ->findAll();
- }
-
- /**
* Get all tasks shown on the board (sorted by position)
*
* @access public
@@ -104,7 +59,7 @@ class TaskFinder extends Base
*/
public function getTasksOnBoard($project_id)
{
- return $this->prepareRequestList()
+ return $this->getQuery()
->eq('project_id', $project_id)
->eq('is_active', Task::STATUS_OPEN)
->asc('tasks.position')
@@ -112,33 +67,6 @@ class TaskFinder extends Base
}
/**
- * Get all open tasks for a given user
- *
- * @access public
- * @param integer $user_id User id
- * @return array
- */
- public function getAllTasksByUser($user_id)
- {
- return $this->db
- ->table(Task::TABLE)
- ->columns(
- 'tasks.id',
- 'tasks.title',
- 'tasks.date_due',
- 'tasks.date_creation',
- 'tasks.project_id',
- 'tasks.color_id',
- 'projects.name AS project_name'
- )
- ->join(Project::TABLE, 'id', 'project_id')
- ->eq('tasks.owner_id', $user_id)
- ->eq('tasks.is_active', Task::STATUS_OPEN)
- ->asc('tasks.id')
- ->findAll();
- }
-
- /**
* Get all tasks for a given project and status
*
* @access public
@@ -296,22 +224,6 @@ class TaskFinder extends Base
}
/**
- * Count the number of tasks for a custom search
- *
- * @access public
- * @param integer $project_id Project id
- * @param string $search Search terms
- * @return integer
- */
- public function countSearch($project_id, $search)
- {
- return $this->db->table(Task::TABLE)
- ->eq('project_id', $project_id)
- ->like('title', '%'.$search.'%')
- ->count();
- }
-
- /**
* Return true if the task exists
*
* @access public
diff --git a/app/Model/TaskPaginator.php b/app/Model/TaskPaginator.php
new file mode 100644
index 00000000..4ae3566c
--- /dev/null
+++ b/app/Model/TaskPaginator.php
@@ -0,0 +1,139 @@
+<?php
+
+namespace Model;
+
+/**
+ * Task Paginator model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class TaskPaginator extends Base
+{
+ /**
+ * Task search with pagination
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param string $search Search terms
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function searchTasks($project_id, $search, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'DESC')
+ {
+ return $this->taskFinder->getQuery()
+ ->eq('project_id', $project_id)
+ ->like('title', '%'.$search.'%')
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count the number of tasks for a custom search
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param string $search Search terms
+ * @return integer
+ */
+ public function countSearchTasks($project_id, $search)
+ {
+ return $this->db->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->like('title', '%'.$search.'%')
+ ->count();
+ }
+
+ /**
+ * Get all completed tasks with pagination
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function closedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC')
+ {
+ return $this->taskFinder->getQuery()
+ ->eq('project_id', $project_id)
+ ->eq('is_active', Task::STATUS_CLOSED)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count all closed tasks
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param array $status List of status id
+ * @return integer
+ */
+ public function countClosedTasks($project_id)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('is_active', Task::STATUS_CLOSED)
+ ->count();
+ }
+
+ /**
+ * Get all open tasks for a given user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function userTasks($user_id, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'ASC')
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->columns(
+ 'tasks.id',
+ 'tasks.title',
+ 'tasks.date_due',
+ 'tasks.date_creation',
+ 'tasks.project_id',
+ 'tasks.color_id',
+ 'projects.name AS project_name'
+ )
+ ->join(Project::TABLE, 'id', 'project_id')
+ ->eq('tasks.owner_id', $user_id)
+ ->eq('tasks.is_active', Task::STATUS_OPEN)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count all tasks assigned to the user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @return integer
+ */
+ public function countUserTasks($user_id)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('owner_id', $user_id)
+ ->eq('is_active', Task::STATUS_OPEN)
+ ->count();
+ }
+}