summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorrzeka <piotr@rzeka.net>2014-03-04 20:17:26 +0100
committerrzeka <piotr@rzeka.net>2014-03-04 20:17:26 +0100
commitccc54c65cf2191e35bd0294c0ffbae761b29f151 (patch)
tree98040c247f1a3165c83266ceeccc7b618f6f2303 /models
parent86bee367846491be2a7f703affc1052318dac63d (diff)
Added basic comments on tasks
Diffstat (limited to 'models')
-rw-r--r--models/base.php2
-rw-r--r--models/schema.php15
-rw-r--r--models/task.php35
3 files changed, 51 insertions, 1 deletions
diff --git a/models/base.php b/models/base.php
index 44a8b6b2..2ecf4280 100644
--- a/models/base.php
+++ b/models/base.php
@@ -18,7 +18,7 @@ require __DIR__.'/schema.php';
abstract class Base
{
const APP_VERSION = 'master';
- const DB_VERSION = 7;
+ const DB_VERSION = 8;
private static $dbInstance = null;
protected $db;
diff --git a/models/schema.php b/models/schema.php
index f98f0e69..2c3ba7e8 100644
--- a/models/schema.php
+++ b/models/schema.php
@@ -2,6 +2,21 @@
namespace Schema;
+function version_8($pdo)
+{
+ $pdo->exec(
+ 'CREATE TABLE comments (
+ id INTEGER PRIMARY KEY,
+ task_id INTEGER,
+ user_id INTEGER,
+ date INTEGER,
+ comment TEXT,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(user_id) REFERENCES tasks(id) ON DELETE CASCADE
+ )'
+ );
+}
+
function version_7($pdo)
{
$pdo->exec("
diff --git a/models/task.php b/models/task.php
index e542e8e0..5ee202c3 100644
--- a/models/task.php
+++ b/models/task.php
@@ -8,6 +8,7 @@ use \SimpleValidator\Validators;
class Task extends Base
{
const TABLE = 'tasks';
+ const COMMENTS = 'comments';
public function getColors()
{
@@ -57,6 +58,21 @@ class Task extends Base
}
}
+ public function getCommentsByTask($task_id)
+ {
+ return $this->db
+ ->table(self::COMMENTS)
+ ->columns(
+ self::COMMENTS.'.date',
+ self::COMMENTS.'.comment',
+ \Model\User::TABLE.'.username'
+ )
+ ->join(\Model\User::TABLE, 'id', 'user_id')
+ ->orderBy(self::COMMENTS.'.date', 'ASC')
+ ->eq(self::COMMENTS.'.task_id', $task_id)
+ ->findAll();
+ }
+
public function getAllByProjectId($project_id, array $status = array(1, 0))
{
return $this->db->table(self::TABLE)
@@ -172,6 +188,25 @@ class Task extends Base
->update(array('column_id' => $column_id, 'position' => $position));
}
+ public function addComment($values)
+ {
+ $values['date'] = time();
+
+ return (bool) $this->db->table(self::COMMENTS)->save($values);
+ }
+
+ public function validateComment(array $values)
+ {
+ $v = new Validator($values, array(
+ new Validators\Required('comment', t('Comment is required'))
+ ));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
public function validateCreation(array $values)
{
$v = new Validator($values, array(