summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/css/app.css18
-rw-r--r--controllers/task.php30
-rw-r--r--locales/fr_FR/translations.php4
-rw-r--r--locales/pl_PL/translations.php5
-rw-r--r--models/base.php2
-rw-r--r--models/schema.php15
-rw-r--r--models/task.php35
-rw-r--r--templates/task_show.php23
8 files changed, 128 insertions, 4 deletions
diff --git a/assets/css/app.css b/assets/css/app.css
index 93a29e47..270b5c13 100644
--- a/assets/css/app.css
+++ b/assets/css/app.css
@@ -532,6 +532,24 @@ article .task-score {
top: 5px;
}
+ul#comments {
+ list-style-type: none;
+}
+
+ul#comments li {
+ margin: 10px 0;
+ padding: 10px 0 10px 10px;
+ border-left: 5px solid #000;
+}
+
+ul#comments li:nth-child(odd) {
+ background-color: #f0f0f0;
+}
+
+ul#comments li p:first-child {
+ font-size: .8em;
+}
+
/* task colors */
tr td.task-blue,
.task-blue {
diff --git a/controllers/task.php b/controllers/task.php
index 0057a531..75d08958 100644
--- a/controllers/task.php
+++ b/controllers/task.php
@@ -45,17 +45,45 @@ 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(
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->task->getColors(),
'menu' => 'tasks',
- 'title' => $task['title']
+ 'title' => $task['title'],
+ 'comments' => $comments,
+ 'errors' => $errors,
+ 'values' => $values
)));
}
+ //add a comment
+ public function comment(array $values, $task_id)
+ {
+ $errors = array();
+
+ if ($_POST) {
+ list($valid, $errors) = $this->task->validateComment($values);
+
+ if ($valid) {
+ $this->task->addComment(array(
+ 'task_id' => $task_id,
+ 'comment' => $values['comment'],
+ 'user_id' => $this->acl->getUserId()
+ ));
+ }
+ }
+
+ return $errors;
+ }
+
// Display a form to create a new task
public function create()
{
diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php
index 3a64f0c7..fb9ce4bc 100644
--- a/locales/fr_FR/translations.php
+++ b/locales/fr_FR/translations.php
@@ -201,4 +201,8 @@ return array(
'User' => 'Utilisateur',
'Everybody have access to this project.' => 'Tout le monde a accès au projet.',
'You are not allowed to access to this project.' => 'Vous n\'êtes pas autorisé à accéder à ce projet.',
+ '%B %e, %G at %k:%M %p' => '%e %B %G à %k:%M',
+ //Comments => '',
+ //'No comments' => '',
+ //'Post comment' => '',
);
diff --git a/locales/pl_PL/translations.php b/locales/pl_PL/translations.php
index de5cb23c..884f6262 100644
--- a/locales/pl_PL/translations.php
+++ b/locales/pl_PL/translations.php
@@ -205,5 +205,8 @@ return array(
'User' => 'Użytkownik',
'Everybody have access to this project.' => 'Każdy ma dostęp do tego projektu.',
'You are not allowed to access to this project.' => 'Nie masz dostępu do tego projektu.',
+ '%B %e, %G at %k:%M %p' => '%e %B %G o %k:%M',
+ 'Comments' => 'Komentarze',
+ 'No comments' => 'Brak komentarzy',
+ 'Post comment' => 'Dodaj komentarz',
);
-
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(
diff --git a/templates/task_show.php b/templates/task_show.php
index fffacf74..e910c951 100644
--- a/templates/task_show.php
+++ b/templates/task_show.php
@@ -60,5 +60,26 @@
</article>
<?php endif ?>
+ <h3><?= t('Comments') ?></h3>
+ <?php if ($comments): ?>
+ <ul id="comments">
+ <?php foreach ($comments as $comment): ?>
+ <li>
+ <p><?= $comment['username'] ?> @ <?= dt('%B %e, %G at %k:%M %p', $comment['date']) ?></p>
+ <?= Helper\markdown($comment['comment']) ?>
+ </li>
+ <?php endforeach ?>
+ </ul>
+ <?php else: ?>
+ <p><?= t('No comments') ?></p>
+ <?php endif ?>
+
+ <form method="post" action="?controller=task&amp;action=show&amp;task_id=<?= $task['id'] ?>" autocomplete="off">
+ <?= Helper\form_textarea('comment', $values, $errors) ?><br/>
+
+ <div class="form-actions">
+ <input type="submit" value="<?= t('Post comment') ?>" class="btn btn-blue"/>
+ </div>
+ </form>
</section>
-</section> \ No newline at end of file
+</section>