diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
commit | 19409360ca7d4c00d070b16bbfcc6cd02543cdca (patch) | |
tree | 3eb3a3d0fce2d74c550135f3119182e1d1aa0fe2 /models | |
parent | ccc54c65cf2191e35bd0294c0ffbae761b29f151 (diff) |
Improve comments
Diffstat (limited to 'models')
-rw-r--r-- | models/acl.php | 2 | ||||
-rw-r--r-- | models/comment.php | 50 | ||||
-rw-r--r-- | models/task.php | 35 |
3 files changed, 51 insertions, 36 deletions
diff --git a/models/acl.php b/models/acl.php index 7c363272..468022cb 100644 --- a/models/acl.php +++ b/models/acl.php @@ -16,7 +16,7 @@ class Acl extends Base 'app' => array('index'), 'board' => array('index', 'show', 'assign', 'assigntask', 'save'), 'project' => array('tasks', 'index', 'forbidden'), - 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'confirmclose', 'open', 'confirmopen'), + 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'confirmclose', 'open', 'confirmopen', 'comment'), 'user' => array('index', 'edit', 'update', 'forbidden', 'logout', 'index'), 'config' => array('index'), ); diff --git a/models/comment.php b/models/comment.php new file mode 100644 index 00000000..e0944249 --- /dev/null +++ b/models/comment.php @@ -0,0 +1,50 @@ +<?php + +namespace Model; + +use \SimpleValidator\Validator; +use \SimpleValidator\Validators; + +class Comment extends Base +{ + const TABLE = 'comments'; + + public function getAll($task_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.date', + self::TABLE.'.comment', + \Model\User::TABLE.'.username' + ) + ->join(\Model\User::TABLE, 'id', 'user_id') + ->orderBy(self::TABLE.'.date', 'ASC') + ->eq(self::TABLE.'.task_id', $task_id) + ->findAll(); + } + + public function create(array $values) + { + $values['date'] = time(); + + return (bool) $this->db->table(self::TABLE)->save($values); + } + + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\Required('task_id', t('This value is required')), + new Validators\Integer('task_id', t('This value must be an integer')), + new Validators\Required('user_id', t('This value is required')), + new Validators\Integer('user_id', t('This value must be an integer')), + new Validators\Required('comment', t('Comment is required')) + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} diff --git a/models/task.php b/models/task.php index 5ee202c3..e542e8e0 100644 --- a/models/task.php +++ b/models/task.php @@ -8,7 +8,6 @@ use \SimpleValidator\Validators; class Task extends Base { const TABLE = 'tasks'; - const COMMENTS = 'comments'; public function getColors() { @@ -58,21 +57,6 @@ 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) @@ -188,25 +172,6 @@ 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( |