From ba93061f4d844214851d5a22b5a34022ce37e925 Mon Sep 17 00:00:00 2001
From: Frédéric Guillot <fred@kanboard.net>
Date: Tue, 8 Jul 2014 15:07:07 -0300
Subject: Add fields: task creator and modification date

---
 app/Model/Task.php | 64 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 28 deletions(-)

(limited to 'app/Model')

diff --git a/app/Model/Task.php b/app/Model/Task.php
index f08eb910..8933cb14 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -73,34 +73,40 @@ class Task extends Base
     {
         if ($more) {
 
-            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.'.date_due',
-                        self::TABLE.'.color_id',
-                        self::TABLE.'.project_id',
-                        self::TABLE.'.column_id',
-                        self::TABLE.'.owner_id',
-                        self::TABLE.'.position',
-                        self::TABLE.'.is_active',
-                        self::TABLE.'.score',
-                        self::TABLE.'.category_id',
-                        Category::TABLE.'.name AS category_name',
-                        Project::TABLE.'.name AS project_name',
-                        Board::TABLE.'.title AS column_title',
-                        User::TABLE.'.username'
-                    )
-                    ->join(Category::TABLE, 'id', 'category_id')
-                    ->join(Project::TABLE, 'id', 'project_id')
-                    ->join(Board::TABLE, 'id', 'column_id')
-                    ->join(User::TABLE, 'id', 'owner_id')
-                    ->eq(self::TABLE.'.id', $task_id)
-                    ->findOne();
+            $sql = '
+                SELECT
+                tasks.id,
+                tasks.title,
+                tasks.description,
+                tasks.date_creation,
+                tasks.date_completed,
+                tasks.date_modification,
+                tasks.date_due,
+                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,
+                creators.username AS creator_username
+                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);
         }
         else {
 
@@ -385,6 +391,7 @@ class Task extends Base
         }
 
         $updated_task = $values;
+        $updated_task['date_modification'] = time();
         unset($updated_task['id']);
 
         $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task);
@@ -514,6 +521,7 @@ class Task extends Base
             new Validators\Required('column_id', t('The column is required')),
             new Validators\Integer('column_id', t('This value must be an integer')),
             new Validators\Integer('owner_id', t('This value must be an integer')),
+            new Validators\Integer('creator_id', t('This value must be an integer')),
             new Validators\Integer('score', t('This value must be an integer')),
             new Validators\Required('title', t('The title is required')),
             new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200),
-- 
cgit v1.2.3