Improve comments

This commit is contained in:
Frédéric Guillot
2014-03-04 21:57:12 -05:00
parent ccc54c65cf
commit 19409360ca
10 changed files with 162 additions and 91 deletions

View File

@@ -15,6 +15,7 @@ require __DIR__.'/../models/user.php';
require __DIR__.'/../models/project.php';
require __DIR__.'/../models/task.php';
require __DIR__.'/../models/board.php';
require __DIR__.'/../models/comment.php';
abstract class Base
{
@@ -28,6 +29,7 @@ abstract class Base
protected $board;
protected $config;
protected $acl;
protected $comment;
public function __construct()
{
@@ -41,6 +43,7 @@ abstract class Base
$this->task = new \Model\Task;
$this->board = new \Model\Board;
$this->acl = new \Model\Acl;
$this->comment = new \Model\Comment;
}
public function beforeAction($controller, $action)

View File

@@ -45,43 +45,53 @@ class Task extends Base
$task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
if (! $task) $this->notfound();
$this->checkProjectPermissions($task['project_id']);
$values = $values = $this->request->getValues();
$errors = $this->comment($values, $task['id']);
$comments = $this->task->getCommentsByTask($task['id']);
$this->response->html($this->template->layout('task_show', array(
'comments' => $this->comment->getAll($task['id']),
'comment_errors' => array(),
'comment_values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()),
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->task->getColors(),
'menu' => 'tasks',
'title' => $task['title'],
'comments' => $comments,
'errors' => $errors,
'values' => $values
)));
}
//add a comment
public function comment(array $values, $task_id)
// Add a comment
public function comment()
{
$errors = array();
$task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
$values = $this->request->getValues();
if ($_POST) {
list($valid, $errors) = $this->task->validateComment($values);
if (! $task) $this->notfound();
$this->checkProjectPermissions($task['project_id']);
if ($valid) {
$this->task->addComment(array(
'task_id' => $task_id,
'comment' => $values['comment'],
'user_id' => $this->acl->getUserId()
));
list($valid, $errors) = $this->comment->validateCreation($values);
if ($valid) {
if ($this->comment->create($values)) {
$this->session->flash(t('Comment added successfully.'));
}
else {
$this->session->flashError(t('Unable to create your comment.'));
}
$this->response->redirect('?controller=task&action=show&task_id='.$task['id']);
}
return $errors;
$this->response->html($this->template->layout('task_show', array(
'comments' => $this->comment->getAll($task['id']),
'comment_errors' => $errors,
'comment_values' => $values,
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->task->getColors(),
'menu' => 'tasks',
'title' => $task['title'],
)));
}
// Display a form to create a new task