summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-12 15:32:35 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-12 15:32:35 -0400
commit4061927d215c846ff8eb196301bf61532018042b (patch)
tree0e14a0e458ee8739754f75f8c158cc42a9b593a4 /app
parentb7060b33ef317eeac576c504b1fb840d4471e411 (diff)
Move some Task model methods to the TaskFinder class
Diffstat (limited to 'app')
-rw-r--r--app/Action/TaskDuplicateAnotherProject.php2
-rw-r--r--app/Action/TaskMoveAnotherProject.php2
-rw-r--r--app/Controller/Base.php2
-rw-r--r--app/Controller/Project.php2
-rw-r--r--app/Controller/Task.php2
-rw-r--r--app/Event/CommentHistoryListener.php2
-rw-r--r--app/Event/CommentNotificationListener.php2
-rw-r--r--app/Event/FileNotificationListener.php2
-rw-r--r--app/Event/SubTaskNotificationListener.php2
-rw-r--r--app/Event/SubtaskHistoryListener.php2
-rw-r--r--app/Event/TaskNotificationListener.php2
-rw-r--r--app/Model/Board.php2
-rw-r--r--app/Model/GithubWebhook.php14
-rw-r--r--app/Model/Project.php4
-rw-r--r--app/Model/Task.php189
-rw-r--r--app/Model/TaskFinder.php243
16 files changed, 259 insertions, 215 deletions
diff --git a/app/Action/TaskDuplicateAnotherProject.php b/app/Action/TaskDuplicateAnotherProject.php
index b76b3884..4ab88534 100644
--- a/app/Action/TaskDuplicateAnotherProject.php
+++ b/app/Action/TaskDuplicateAnotherProject.php
@@ -64,7 +64,7 @@ class TaskDuplicateAnotherProject extends Base
*/
public function doAction(array $data)
{
- $task = $this->task->getById($data['task_id']);
+ $task = $this->taskFinder->getById($data['task_id']);
$this->task->duplicateToAnotherProject($this->getParam('project_id'), $task);
return true;
}
diff --git a/app/Action/TaskMoveAnotherProject.php b/app/Action/TaskMoveAnotherProject.php
index 9922a981..d852f56d 100644
--- a/app/Action/TaskMoveAnotherProject.php
+++ b/app/Action/TaskMoveAnotherProject.php
@@ -64,7 +64,7 @@ class TaskMoveAnotherProject extends Base
*/
public function doAction(array $data)
{
- $task = $this->task->getById($data['task_id']);
+ $task = $this->taskFinder->getById($data['task_id']);
$this->task->moveToAnotherProject($this->getParam('project_id'), $task);
return true;
}
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 9fab0752..ac88df04 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -276,7 +276,7 @@ abstract class Base
*/
protected function getTask()
{
- $task = $this->task->getDetails($this->request->getIntegerParam('task_id'));
+ $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id'));
if (! $task) {
$this->notfound();
diff --git a/app/Controller/Project.php b/app/Controller/Project.php
index f998e5d6..39d8d1b0 100644
--- a/app/Controller/Project.php
+++ b/app/Controller/Project.php
@@ -447,7 +447,7 @@ class Project extends Base
$limit = 25;
$tasks = $this->taskFinder->getClosedTasks($project['id'], $offset, $limit, $order, $direction);
- $nb_tasks = $this->task->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED));
+ $nb_tasks = $this->taskFinder->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED));
$this->response->html($this->template->layout('project_tasks', array(
'pagination' => array(
diff --git a/app/Controller/Task.php b/app/Controller/Task.php
index 4c15d8df..1b20cf15 100644
--- a/app/Controller/Task.php
+++ b/app/Controller/Task.php
@@ -26,7 +26,7 @@ class Task extends Base
$this->forbidden(true);
}
- $task = $this->task->getDetails($this->request->getIntegerParam('task_id'));
+ $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id'));
if (! $task) {
$this->notfound(true);
diff --git a/app/Event/CommentHistoryListener.php b/app/Event/CommentHistoryListener.php
index e5e92b01..ec826615 100644
--- a/app/Event/CommentHistoryListener.php
+++ b/app/Event/CommentHistoryListener.php
@@ -56,7 +56,7 @@ class CommentHistoryListener implements Listener
if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
- $task = $this->model->task->getById($data['task_id']);
+ $task = $this->model->taskFinder->getById($data['task_id']);
$this->model->create(
$task['project_id'],
diff --git a/app/Event/CommentNotificationListener.php b/app/Event/CommentNotificationListener.php
index 36b7ea4b..13803874 100644
--- a/app/Event/CommentNotificationListener.php
+++ b/app/Event/CommentNotificationListener.php
@@ -23,7 +23,7 @@ class CommentNotificationListener extends BaseNotificationListener
{
$values = array();
$values['comment'] = $this->notification->comment->getById($data['id']);
- $values['task'] = $this->notification->task->getDetails($values['comment']['task_id']);
+ $values['task'] = $this->notification->taskFinder->getDetails($values['comment']['task_id']);
return $values;
}
diff --git a/app/Event/FileNotificationListener.php b/app/Event/FileNotificationListener.php
index ed5d78ed..2366ce5d 100644
--- a/app/Event/FileNotificationListener.php
+++ b/app/Event/FileNotificationListener.php
@@ -23,7 +23,7 @@ class FileNotificationListener extends BaseNotificationListener
{
$values = array();
$values['file'] = $data;
- $values['task'] = $this->notification->task->getDetails($data['task_id']);
+ $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']);
return $values;
}
diff --git a/app/Event/SubTaskNotificationListener.php b/app/Event/SubTaskNotificationListener.php
index 299ae00b..2b35d757 100644
--- a/app/Event/SubTaskNotificationListener.php
+++ b/app/Event/SubTaskNotificationListener.php
@@ -23,7 +23,7 @@ class SubTaskNotificationListener extends BaseNotificationListener
{
$values = array();
$values['subtask'] = $this->notification->subtask->getById($data['id'], true);
- $values['task'] = $this->notification->task->getDetails($data['task_id']);
+ $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']);
return $values;
}
diff --git a/app/Event/SubtaskHistoryListener.php b/app/Event/SubtaskHistoryListener.php
index 8cc7a7fd..6b4f1c2d 100644
--- a/app/Event/SubtaskHistoryListener.php
+++ b/app/Event/SubtaskHistoryListener.php
@@ -56,7 +56,7 @@ class SubtaskHistoryListener implements Listener
if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
- $task = $this->model->task->getById($data['task_id']);
+ $task = $this->model->taskFinder->getById($data['task_id']);
$this->model->create(
$task['project_id'],
diff --git a/app/Event/TaskNotificationListener.php b/app/Event/TaskNotificationListener.php
index 466a8eb4..119e61e5 100644
--- a/app/Event/TaskNotificationListener.php
+++ b/app/Event/TaskNotificationListener.php
@@ -22,7 +22,7 @@ class TaskNotificationListener extends BaseNotificationListener
public function getTemplateData(array $data)
{
$values = array();
- $values['task'] = $this->notification->task->getDetails($data['task_id']);
+ $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']);
return $values;
}
diff --git a/app/Model/Board.php b/app/Model/Board.php
index de47e6b9..4c78b0f6 100644
--- a/app/Model/Board.php
+++ b/app/Model/Board.php
@@ -235,7 +235,7 @@ class Board extends Base
public function get($project_id, array $filters = array())
{
$columns = $this->getColumns($project_id);
- $tasks = $this->taskFinder->getOpenTasks($project_id);
+ $tasks = $this->taskFinder->getTasksOnBoard($project_id);
foreach ($columns as &$column) {
diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php
index b5f95eeb..6624a782 100644
--- a/app/Model/GithubWebhook.php
+++ b/app/Model/GithubWebhook.php
@@ -77,7 +77,7 @@ class GithubWebhook extends Base
continue;
}
- $task = $this->task->getById($task_id);
+ $task = $this->taskFinder->getById($task_id);
if (! $task) {
continue;
@@ -148,7 +148,7 @@ class GithubWebhook extends Base
*/
public function handleIssueClosed(array $issue)
{
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($task) {
$event = array(
@@ -169,7 +169,7 @@ class GithubWebhook extends Base
*/
public function handleIssueReopened(array $issue)
{
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($task) {
$event = array(
@@ -191,7 +191,7 @@ class GithubWebhook extends Base
public function handleIssueAssigned(array $issue)
{
$user = $this->user->getByUsername($issue['assignee']['login']);
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($user && $task) {
@@ -214,7 +214,7 @@ class GithubWebhook extends Base
*/
public function handleIssueUnassigned(array $issue)
{
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($task) {
@@ -238,7 +238,7 @@ class GithubWebhook extends Base
*/
public function handleIssueLabeled(array $issue, array $label)
{
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($task) {
@@ -262,7 +262,7 @@ class GithubWebhook extends Base
*/
public function handleIssueUnlabeled(array $issue, array $label)
{
- $task = $this->task->getByReference($issue['number']);
+ $task = $this->taskFinder->getByReference($issue['number']);
if ($task) {
diff --git a/app/Model/Project.php b/app/Model/Project.php
index b60ba567..ad0afa82 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -196,12 +196,12 @@ class Project extends Base
$stats['nb_active_tasks'] = 0;
foreach ($columns as &$column) {
- $column['nb_active_tasks'] = $this->task->countByColumnId($project_id, $column['id']);
+ $column['nb_active_tasks'] = $this->taskFinder->countByColumnId($project_id, $column['id']);
$stats['nb_active_tasks'] += $column['nb_active_tasks'];
}
$stats['columns'] = $columns;
- $stats['nb_tasks'] = $this->task->countByProjectId($project_id);
+ $stats['nb_tasks'] = $this->taskFinder->countByProjectId($project_id);
$stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks'];
return $stats;
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 4536ba5c..a0090641 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -2,8 +2,6 @@
namespace Model;
-use PDO;
-
/**
* Task model
*
@@ -42,163 +40,6 @@ class Task extends Base
const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change';
/**
- * Get a list of due tasks for all projects
- *
- * @access public
- * @return array
- */
- public function getOverdueTasks()
- {
- $tasks = $this->db->table(self::TABLE)
- ->columns(
- self::TABLE.'.id',
- self::TABLE.'.title',
- self::TABLE.'.date_due',
- self::TABLE.'.project_id',
- Project::TABLE.'.name AS project_name',
- User::TABLE.'.username AS assignee_username',
- User::TABLE.'.name AS assignee_name'
- )
- ->join(Project::TABLE, 'id', 'project_id')
- ->join(User::TABLE, 'id', 'owner_id')
- ->eq(Project::TABLE.'.is_active', 1)
- ->eq(self::TABLE.'.is_active', 1)
- ->neq(self::TABLE.'.date_due', 0)
- ->lte(self::TABLE.'.date_due', mktime(23, 59, 59))
- ->findAll();
-
- return $tasks;
- }
-
- /**
- * Get task details (fetch more information from other tables)
- *
- * @access public
- * @param integer $task_id Task id
- * @return array
- */
- public function getDetails($task_id)
- {
- $sql = '
- SELECT
- tasks.id,
- tasks.reference,
- tasks.title,
- tasks.description,
- tasks.date_creation,
- tasks.date_completed,
- tasks.date_modification,
- tasks.date_due,
- tasks.date_started,
- tasks.time_estimated,
- tasks.time_spent,
- tasks.color_id,
- tasks.project_id,
- tasks.column_id,
- tasks.owner_id,
- tasks.creator_id,
- tasks.position,
- tasks.is_active,
- tasks.score,
- tasks.category_id,
- project_has_categories.name AS category_name,
- projects.name AS project_name,
- columns.title AS column_title,
- users.username AS assignee_username,
- users.name AS assignee_name,
- creators.username AS creator_username,
- creators.name AS creator_name
- FROM tasks
- LEFT JOIN users ON users.id = tasks.owner_id
- LEFT JOIN users AS creators ON creators.id = tasks.creator_id
- LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id
- LEFT JOIN projects ON projects.id = tasks.project_id
- LEFT JOIN columns ON columns.id = tasks.column_id
- WHERE tasks.id = ?
- ';
-
- $rq = $this->db->execute($sql, array($task_id));
- return $rq->fetch(PDO::FETCH_ASSOC);
- }
-
- /**
- * Fetch a task by the id
- *
- * @access public
- * @param integer $task_id Task id
- * @return array
- */
- public function getById($task_id)
- {
- return $this->db->table(self::TABLE)->eq('id', $task_id)->findOne();
- }
-
- /**
- * Fetch a task by the reference (external id)
- *
- * @access public
- * @param string $reference Task reference
- * @return array
- */
- public function getByReference($reference)
- {
- return $this->db->table(self::TABLE)->eq('reference', $reference)->findOne();
- }
-
- /**
- * Get all tasks for a given project and status
- *
- * @access public
- * @param integer $project_id Project id
- * @param integer $status_id Status id
- * @return array
- */
- public function getAll($project_id, $status_id = self::STATUS_OPEN)
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->eq('is_active', $status_id)
- ->findAll();
- }
-
- /**
- * Count all tasks for a given project and status
- *
- * @access public
- * @param integer $project_id Project id
- * @param array $status List of status id
- * @return integer
- */
- public function countByProjectId($project_id, array $status = array(self::STATUS_OPEN, self::STATUS_CLOSED))
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->in('is_active', $status)
- ->count();
- }
-
- /**
- * Count the number of tasks for a given column and status
- *
- * @access public
- * @param integer $project_id Project id
- * @param integer $column_id Column id
- * @param array $status List of status id
- * @return integer
- */
- public function countByColumnId($project_id, $column_id, array $status = array(self::STATUS_OPEN))
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->eq('column_id', $column_id)
- ->in('is_active', $status)
- ->count();
- }
-
- /**
* Prepare data before task creation or modification
*
* @access public
@@ -233,7 +74,7 @@ class Task extends Base
$values['date_creation'] = time();
$values['date_modification'] = $values['date_creation'];
- $values['position'] = $this->countByColumnId($values['project_id'], $values['column_id']) + 1;
+ $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1;
}
/**
@@ -288,7 +129,7 @@ class Task extends Base
public function update(array $values, $trigger_events = true)
{
// Fetch original task
- $original_task = $this->getById($values['id']);
+ $original_task = $this->taskFinder->getById($values['id']);
if (! $original_task) {
return false;
@@ -341,18 +182,6 @@ class Task extends Base
}
/**
- * Return true if the project exists
- *
- * @access public
- * @param integer $task_id Task id
- * @return boolean
- */
- public function exists($task_id)
- {
- return $this->db->table(self::TABLE)->eq('id', $task_id)->count() === 1;
- }
-
- /**
* Mark a task closed
*
* @access public
@@ -361,7 +190,7 @@ class Task extends Base
*/
public function close($task_id)
{
- if (! $this->exists($task_id)) {
+ if (! $this->taskFinder->exists($task_id)) {
return false;
}
@@ -374,7 +203,7 @@ class Task extends Base
));
if ($result) {
- $this->event->trigger(self::EVENT_CLOSE, array('task_id' => $task_id) + $this->getById($task_id));
+ $this->event->trigger(self::EVENT_CLOSE, array('task_id' => $task_id) + $this->taskFinder->getById($task_id));
}
return $result;
@@ -389,7 +218,7 @@ class Task extends Base
*/
public function open($task_id)
{
- if (! $this->exists($task_id)) {
+ if (! $this->taskFinder->exists($task_id)) {
return false;
}
@@ -402,7 +231,7 @@ class Task extends Base
));
if ($result) {
- $this->event->trigger(self::EVENT_OPEN, array('task_id' => $task_id) + $this->getById($task_id));
+ $this->event->trigger(self::EVENT_OPEN, array('task_id' => $task_id) + $this->taskFinder->getById($task_id));
}
return $result;
@@ -417,7 +246,7 @@ class Task extends Base
*/
public function remove($task_id)
{
- if (! $this->exists($task_id)) {
+ if (! $this->taskFinder->exists($task_id)) {
return false;
}
@@ -541,7 +370,7 @@ class Task extends Base
// We use the first column of the new project
$values['column_id'] = $this->board->getFirstColumn($project_id);
- $values['position'] = $this->countByColumnId($project_id, $values['column_id']) + 1;
+ $values['position'] = $this->taskFinder->countByColumnId($project_id, $values['column_id']) + 1;
$values['project_id'] = $project_id;
// The task will be open (close event binding)
@@ -583,7 +412,7 @@ class Task extends Base
$values['column_id'] = $task['column_id'];
$values['owner_id'] = 0;
$values['creator_id'] = $task['creator_id'];
- $values['position'] = $this->countByColumnId($values['project_id'], $values['column_id']) + 1;
+ $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1;
$values['score'] = $task['score'];
$values['category_id'] = 0;
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 43537e2d..5bf8c139 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -2,6 +2,8 @@
namespace Model;
+use PDO;
+
/**
* Task Finder model
*
@@ -10,7 +12,13 @@ namespace Model;
*/
class TaskFinder extends Base
{
- private function prepareRequest()
+ /**
+ * Common request to fetch a list of tasks
+ *
+ * @access private
+ * @return \PicoDb\Table
+ */
+ private function prepareRequestList()
{
return $this->db
->table(Task::TABLE)
@@ -42,9 +50,21 @@ class TaskFinder extends Base
->join(User::TABLE, 'id', 'owner_id');
}
+ /**
+ * 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->prepareRequest()
+ return $this->prepareRequestList()
->eq('project_id', $project_id)
->like('title', '%'.$search.'%')
->offset($offset)
@@ -53,17 +73,20 @@ class TaskFinder extends Base
->findAll();
}
- public function countSearch($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 getClosedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC')
{
- return $this->prepareRequest()
+ return $this->prepareRequestList()
->eq('project_id', $project_id)
->eq('is_active', Task::STATUS_CLOSED)
->offset($offset)
@@ -72,12 +95,204 @@ class TaskFinder extends Base
->findAll();
}
- public function getOpenTasks($project_id, $column = 'tasks.position', $direction = 'ASC')
+ /**
+ * Get all tasks shown on the board (sorted by position)
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function getTasksOnBoard($project_id)
{
- return $this->prepareRequest()
+ return $this->prepareRequestList()
->eq('project_id', $project_id)
->eq('is_active', Task::STATUS_OPEN)
- ->orderBy($column, $direction)
+ ->asc('tasks.position')
+ ->findAll();
+ }
+
+ /**
+ * Get all tasks for a given project and status
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $status_id Status id
+ * @return array
+ */
+ public function getAll($project_id, $status_id = Task::STATUS_OPEN)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('is_active', $status_id)
+ ->findAll();
+ }
+
+ /**
+ * Get a list of overdue tasks for all projects
+ *
+ * @access public
+ * @return array
+ */
+ public function getOverdueTasks()
+ {
+ $tasks = $this->db->table(Task::TABLE)
+ ->columns(
+ Task::TABLE.'.id',
+ Task::TABLE.'.title',
+ Task::TABLE.'.date_due',
+ Task::TABLE.'.project_id',
+ Project::TABLE.'.name AS project_name',
+ User::TABLE.'.username AS assignee_username',
+ User::TABLE.'.name AS assignee_name'
+ )
+ ->join(Project::TABLE, 'id', 'project_id')
+ ->join(User::TABLE, 'id', 'owner_id')
+ ->eq(Project::TABLE.'.is_active', 1)
+ ->eq(Task::TABLE.'.is_active', 1)
+ ->neq(Task::TABLE.'.date_due', 0)
+ ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59))
->findAll();
+
+ return $tasks;
+ }
+
+ /**
+ * Fetch a task by the id
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return array
+ */
+ public function getById($task_id)
+ {
+ return $this->db->table(Task::TABLE)->eq('id', $task_id)->findOne();
+ }
+
+ /**
+ * Fetch a task by the reference (external id)
+ *
+ * @access public
+ * @param string $reference Task reference
+ * @return array
+ */
+ public function getByReference($reference)
+ {
+ return $this->db->table(Task::TABLE)->eq('reference', $reference)->findOne();
+ }
+
+ /**
+ * Get task details (fetch more information from other tables)
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return array
+ */
+ public function getDetails($task_id)
+ {
+ $sql = '
+ SELECT
+ tasks.id,
+ tasks.reference,
+ tasks.title,
+ tasks.description,
+ tasks.date_creation,
+ tasks.date_completed,
+ tasks.date_modification,
+ tasks.date_due,
+ tasks.date_started,
+ tasks.time_estimated,
+ tasks.time_spent,
+ tasks.color_id,
+ tasks.project_id,
+ tasks.column_id,
+ tasks.owner_id,
+ tasks.creator_id,
+ tasks.position,
+ tasks.is_active,
+ tasks.score,
+ tasks.category_id,
+ project_has_categories.name AS category_name,
+ projects.name AS project_name,
+ columns.title AS column_title,
+ users.username AS assignee_username,
+ users.name AS assignee_name,
+ creators.username AS creator_username,
+ creators.name AS creator_name
+ FROM tasks
+ LEFT JOIN users ON users.id = tasks.owner_id
+ LEFT JOIN users AS creators ON creators.id = tasks.creator_id
+ LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id
+ LEFT JOIN projects ON projects.id = tasks.project_id
+ LEFT JOIN columns ON columns.id = tasks.column_id
+ WHERE tasks.id = ?
+ ';
+
+ $rq = $this->db->execute($sql, array($task_id));
+ return $rq->fetch(PDO::FETCH_ASSOC);
+ }
+
+ /**
+ * Count all tasks for a given project and status
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param array $status List of status id
+ * @return integer
+ */
+ public function countByProjectId($project_id, array $status = array(Task::STATUS_OPEN, Task::STATUS_CLOSED))
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->in('is_active', $status)
+ ->count();
+ }
+
+ /**
+ * Count the number of tasks for a given column and status
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $column_id Column id
+ * @param array $status List of status id
+ * @return integer
+ */
+ public function countByColumnId($project_id, $column_id, array $status = array(Task::STATUS_OPEN))
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('column_id', $column_id)
+ ->in('is_active', $status)
+ ->count();
+ }
+
+ /**
+ * 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
+ * @param integer $task_id Task id
+ * @return boolean
+ */
+ public function exists($task_id)
+ {
+ return $this->db->table(Task::TABLE)->eq('id', $task_id)->count() === 1;
}
}