diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-02-22 13:37:06 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-02-22 13:37:06 -0500 |
commit | a1923d3d7f9276e859d6fd6bee339f0ea00f6544 (patch) | |
tree | 84caca943de5d0e016455ea2f6896d0b697fdf05 /models | |
parent | fd28d50597d4f255ba9514e0fc03c8cb67c86f22 (diff) |
Add a page to display completed tasks and add the completion date column for tasks
Diffstat (limited to 'models')
-rw-r--r-- | models/base.php | 2 | ||||
-rw-r--r-- | models/project.php | 1 | ||||
-rw-r--r-- | models/schema.php | 8 | ||||
-rw-r--r-- | models/task.php | 40 |
4 files changed, 46 insertions, 5 deletions
diff --git a/models/base.php b/models/base.php index 1029074d..981c7839 100644 --- a/models/base.php +++ b/models/base.php @@ -17,7 +17,7 @@ require __DIR__.'/schema.php'; abstract class Base { const APP_VERSION = 'master'; - const DB_VERSION = 1; + const DB_VERSION = 2; const DB_FILENAME = 'data/db.sqlite'; private static $dbInstance = null; diff --git a/models/project.php b/models/project.php index b0c2b2ca..10d7c572 100644 --- a/models/project.php +++ b/models/project.php @@ -49,6 +49,7 @@ class Project extends Base $project['columns'] = $columns; $project['nb_tasks'] = $taskModel->countByProjectId($project['id']); + $project['nb_inactive_tasks'] = $project['nb_tasks'] - $project['nb_active_tasks']; } $this->db->closeTransaction(); diff --git a/models/schema.php b/models/schema.php index 3217663a..9ccb500f 100644 --- a/models/schema.php +++ b/models/schema.php @@ -2,6 +2,14 @@ namespace Schema; +function version_2($pdo) +{ + $pdo->exec('ALTER TABLE tasks ADD column date_completed INTEGER'); + + // For all existing completed tasks, set the date of creation as a date of completion + $pdo->exec('UPDATE tasks SET date_completed=date_creation WHERE is_active=0'); +} + function version_1($pdo) { $pdo->exec(" diff --git a/models/task.php b/models/task.php index db27c650..9d23baf0 100644 --- a/models/task.php +++ b/models/task.php @@ -33,6 +33,7 @@ class Task extends Base self::TABLE.'.title', self::TABLE.'.description', self::TABLE.'.date_creation', + self::TABLE.'.date_completed', self::TABLE.'.color_id', self::TABLE.'.project_id', self::TABLE.'.column_id', @@ -55,9 +56,30 @@ class Task extends Base } } - public function getAllByProjectId($project_id) + public function getAllByProjectId($project_id, array $status = array(1, 0)) { - return $this->db->table(self::TABLE)->eq('project_id', $project_id)->findAll(); + return $this->db->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.title', + self::TABLE.'.description', + self::TABLE.'.date_creation', + self::TABLE.'.date_completed', + self::TABLE.'.color_id', + self::TABLE.'.project_id', + self::TABLE.'.column_id', + self::TABLE.'.owner_id', + self::TABLE.'.position', + self::TABLE.'.is_active', + \Model\Board::TABLE.'.title AS column_title', + \Model\User::TABLE.'.username' + ) + ->join(\Model\Board::TABLE, 'id', 'column_id') + ->join(\Model\User::TABLE, 'id', 'owner_id') + ->eq(self::TABLE.'.project_id', $project_id) + ->in('is_active', $status) + ->desc('date_completed') + ->findAll(); } public function countByProjectId($project_id, $status = array(1, 0)) @@ -117,12 +139,22 @@ class Task extends Base public function close($task_id) { - return $this->db->table(self::TABLE)->eq('id', $task_id)->update(array('is_active' => 0)); + return $this->db->table(self::TABLE) + ->eq('id', $task_id) + ->update(array( + 'is_active' => 0, + 'date_completed' => time() + )); } public function open($task_id) { - return $this->db->table(self::TABLE)->eq('id', $task_id)->update(array('is_active' => 1)); + return $this->db->table(self::TABLE) + ->eq('id', $task_id) + ->update(array( + 'is_active' => 1, + 'date_completed' => '' + )); } public function remove($task_id) |