Added basic comments on tasks

This commit is contained in:
rzeka
2014-03-04 20:17:26 +01:00
parent 86bee36784
commit ccc54c65cf
8 changed files with 128 additions and 4 deletions

View File

@@ -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;

View File

@@ -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("

View File

@@ -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(