summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Base.php30
-rw-r--r--app/Controller/Project.php1
-rw-r--r--app/Core/Translator.php53
-rw-r--r--app/Event/CommentHistoryListener.php62
-rw-r--r--app/Event/SubtaskHistoryListener.php62
-rw-r--r--app/Event/TaskHistoryListener.php4
-rw-r--r--app/Model/BaseHistory.php70
-rw-r--r--app/Model/CommentHistory.php152
-rw-r--r--app/Model/Notification.php26
-rw-r--r--app/Model/Project.php22
-rw-r--r--app/Model/SubtaskHistory.php161
-rw-r--r--app/Model/Task.php32
-rw-r--r--app/Model/TaskHistory.php64
-rw-r--r--app/Schema/Mysql.php54
-rw-r--r--app/Schema/Postgres.php54
-rw-r--r--app/Schema/Sqlite.php37
-rw-r--r--app/Templates/event_comment_create.php7
-rw-r--r--app/Templates/event_comment_update.php7
-rw-r--r--app/Templates/event_subtask_create.php12
-rw-r--r--app/Templates/event_subtask_update.php12
-rw-r--r--app/Templates/event_task_close.php2
-rw-r--r--app/Templates/event_task_create.php2
-rw-r--r--app/Templates/event_task_move_column.php2
-rw-r--r--app/Templates/event_task_move_position.php2
-rw-r--r--app/Templates/event_task_open.php4
-rw-r--r--app/Templates/event_task_update.php2
-rw-r--r--app/Templates/project_activity.php4
-rw-r--r--app/translator.php7
28 files changed, 815 insertions, 132 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 4f920ab0..00bfb79b 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -28,6 +28,8 @@ use Model\LastLogin;
* @property \Model\SubTask $subTask
* @property \Model\Task $task
* @property \Model\TaskHistory $taskHistory
+ * @property \Model\CommentHistory $commentHistory
+ * @property \Model\SubtaskHistory $subtaskHistory
* @property \Model\User $user
* @property \Model\Webhook $webhook
*/
@@ -131,11 +133,29 @@ abstract class Base
}
// Attach events
- $this->action->attachEvents();
- $this->project->attachEvents();
- $this->webhook->attachEvents();
- $this->notification->attachEvents();
- $this->taskHistory->attachEvents();
+ $this->attachEvents();
+ }
+
+ /**
+ * Attach events
+ *
+ * @access private
+ */
+ private function attachEvents()
+ {
+ $models = array(
+ 'action',
+ 'project',
+ 'webhook',
+ 'notification',
+ 'taskHistory',
+ 'commentHistory',
+ 'subtaskHistory',
+ );
+
+ foreach ($models as $model) {
+ $this->$model->attachEvents();
+ }
}
/**
diff --git a/app/Controller/Project.php b/app/Controller/Project.php
index 26b241b9..6356a9c6 100644
--- a/app/Controller/Project.php
+++ b/app/Controller/Project.php
@@ -72,7 +72,6 @@ class Project extends Base
$to = $this->request->getStringParam('to');
if ($from && $to) {
- Translator::disableEscaping();
$data = $this->task->export($project['id'], $from, $to);
$this->response->forceDownload('Export_'.date('Y_m_d_H_i_S').'.csv');
$this->response->csv($data);
diff --git a/app/Core/Translator.php b/app/Core/Translator.php
index c34a40ba..43e934a9 100644
--- a/app/Core/Translator.php
+++ b/app/Core/Translator.php
@@ -27,58 +27,47 @@ class Translator
private static $locales = array();
/**
- * Flag to enable HTML escaping
+ * Get a translation
*
- * @static
- * @access private
- * @var boolean
- */
- private static $enable_escaping = true;
-
- /**
- * Disable HTML escaping for translations
+ * $translator->translate('I have %d kids', 5);
*
- * @static
* @access public
+ * @param string $identifier Default string
+ * @return string
*/
- public static function disableEscaping()
+ public function translate($identifier)
{
- self::$enable_escaping = false;
- }
+ $args = func_get_args();
- /**
- * Enable HTML escaping for translations
- *
- * @static
- * @access public
- */
- public static function enableEscaping()
- {
- self::$enable_escaping = true;
+ array_shift($args);
+ array_unshift($args, $this->get($identifier, $identifier));
+
+ foreach ($args as &$arg) {
+ $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
+ }
+
+ return call_user_func_array(
+ 'sprintf',
+ $args
+ );
}
/**
- * Get a translation
+ * Get a translation with no HTML escaping
*
- * $translator->translate('I have %d kids', 5);
+ * $translator->translateNoEscaping('I have %d kids', 5);
*
* @access public
- * @param $identifier
+ * @param string $identifier Default string
* @return string
*/
- public function translate($identifier)
+ public function translateNoEscaping($identifier)
{
$args = func_get_args();
array_shift($args);
array_unshift($args, $this->get($identifier, $identifier));
- if (self::$enable_escaping) {
- foreach ($args as &$arg) {
- $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
- }
- }
-
return call_user_func_array(
'sprintf',
$args
diff --git a/app/Event/CommentHistoryListener.php b/app/Event/CommentHistoryListener.php
new file mode 100644
index 00000000..a89ecbae
--- /dev/null
+++ b/app/Event/CommentHistoryListener.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Event;
+
+use Core\Listener;
+use Model\CommentHistory;
+
+/**
+ * Comment history listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class CommentHistoryListener implements Listener
+{
+ /**
+ * Comment History model
+ *
+ * @accesss private
+ * @var \Model\CommentHistory
+ */
+ private $model;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Model\CommentHistory $model Comment History model instance
+ */
+ public function __construct(CommentHistory $model)
+ {
+ $this->model = $model;
+ }
+
+ /**
+ * Execute the action
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function execute(array $data)
+ {
+ $creator_id = $this->model->acl->getUserId();
+
+ if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
+
+ $task = $this->model->task->getById($data['task_id']);
+
+ $this->model->create(
+ $task['project_id'],
+ $data['task_id'],
+ $data['id'],
+ $creator_id,
+ $this->model->event->getLastTriggeredEvent(),
+ $data['comment']
+ );
+ }
+
+ return false;
+ }
+}
diff --git a/app/Event/SubtaskHistoryListener.php b/app/Event/SubtaskHistoryListener.php
new file mode 100644
index 00000000..e859828c
--- /dev/null
+++ b/app/Event/SubtaskHistoryListener.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Event;
+
+use Core\Listener;
+use Model\SubtaskHistory;
+
+/**
+ * Subtask history listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class SubtaskHistoryListener implements Listener
+{
+ /**
+ * Comment History model
+ *
+ * @accesss private
+ * @var \Model\SubtaskHistory
+ */
+ private $model;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Model\SubtaskHistory $model Subtask History model instance
+ */
+ public function __construct(SubtaskHistory $model)
+ {
+ $this->model = $model;
+ }
+
+ /**
+ * Execute the action
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function execute(array $data)
+ {
+ $creator_id = $this->model->acl->getUserId();
+
+ if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
+
+ $task = $this->model->task->getById($data['task_id']);
+
+ $this->model->create(
+ $task['project_id'],
+ $data['task_id'],
+ $data['id'],
+ $creator_id,
+ $this->model->event->getLastTriggeredEvent(),
+ ''
+ );
+ }
+
+ return false;
+ }
+}
diff --git a/app/Event/TaskHistoryListener.php b/app/Event/TaskHistoryListener.php
index d6709f6e..c8a880e8 100644
--- a/app/Event/TaskHistoryListener.php
+++ b/app/Event/TaskHistoryListener.php
@@ -14,7 +14,7 @@ use Model\TaskHistory;
class TaskHistoryListener implements Listener
{
/**
- * TaskHistory model
+ * Task History model
*
* @accesss private
* @var \Model\TaskHistory
@@ -25,7 +25,7 @@ class TaskHistoryListener implements Listener
* Constructor
*
* @access public
- * @param \Model\TaskHistory $model TaskHistory model instance
+ * @param \Model\TaskHistory $model Task History model instance
*/
public function __construct(TaskHistory $model)
{
diff --git a/app/Model/BaseHistory.php b/app/Model/BaseHistory.php
new file mode 100644
index 00000000..31578a3b
--- /dev/null
+++ b/app/Model/BaseHistory.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Model;
+
+use PDO;
+use Core\Template;
+
+/**
+ * Task history model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+abstract class BaseHistory extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @access protected
+ * @var string
+ */
+ protected $table = '';
+
+ /**
+ * Remove old event entries to avoid a large table
+ *
+ * @access public
+ * @param integer $max Maximum number of items to keep in the table
+ */
+ public function cleanup($max)
+ {
+ if ($this->db->table($this->table)->count() > $max) {
+
+ $this->db->execute('
+ DELETE FROM '.$this->table.'
+ WHERE id <= (
+ SELECT id FROM (
+ SELECT id FROM '.$this->table.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.'
+ ) foo
+ )');
+ }
+ }
+
+ /**
+ * Get all events for a given project
+ *
+ * @access public
+ * @return array
+ */
+ public function getAllByProjectId($project_id)
+ {
+ return $this->db->table($this->table)
+ ->eq('project_id', $project_id)
+ ->desc('id')
+ ->findAll();
+ }
+
+ /**
+ * Get the event html content
+ *
+ * @access public
+ * @param array $params Event properties
+ * @return string
+ */
+ public function getContent(array $params)
+ {
+ $tpl = new Template;
+ return $tpl->load('event_'.str_replace('.', '_', $params['event_name']), $params);
+ }
+}
diff --git a/app/Model/CommentHistory.php b/app/Model/CommentHistory.php
new file mode 100644
index 00000000..5b94729c
--- /dev/null
+++ b/app/Model/CommentHistory.php
@@ -0,0 +1,152 @@
+<?php
+
+namespace Model;
+
+use PDO;
+use Core\Registry;
+use Event\CommentHistoryListener;
+
+/**
+ * Comment history model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class CommentHistory extends BaseHistory
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'comment_has_events';
+
+ /**
+ * Maximum number of events
+ *
+ * @var integer
+ */
+ const MAX_EVENTS = 5000;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Core\Registry $registry Registry instance
+ */
+ public function __construct(Registry $registry)
+ {
+ parent::__construct($registry);
+ $this->table = self::TABLE;
+ }
+
+ /**
+ * Create a new event
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $task_id Task id
+ * @param integer $comment_id Comment id
+ * @param integer $creator_id Author of the event (user id)
+ * @param string $event_name Task event name
+ * @param string $data Current comment
+ * @return boolean
+ */
+ public function create($project_id, $task_id, $comment_id, $creator_id, $event_name, $data)
+ {
+ $values = array(
+ 'project_id' => $project_id,
+ 'task_id' => $task_id,
+ 'comment_id' => $comment_id,
+ 'creator_id' => $creator_id,
+ 'event_name' => $event_name,
+ 'date_creation' => time(),
+ 'data' => $data,
+ );
+
+ $this->db->startTransaction();
+
+ $this->cleanup(self::MAX_EVENTS - 1);
+ $result = $this->db->table(self::TABLE)->insert($values);
+
+ $this->db->closeTransaction();
+
+ return $result;
+ }
+
+ /**
+ * Get all necessary content to display activity feed
+ *
+ * $author_name
+ * $author_username
+ * $task['id', 'title', 'position', 'column_name']
+ */
+ public function getAllContentByProjectId($project_id, $limit = 50)
+ {
+ $sql = '
+ SELECT
+ comment_has_events.id,
+ comment_has_events.date_creation,
+ comment_has_events.event_name,
+ comment_has_events.data as comment,
+ comment_has_events.task_id,
+ tasks.title as task_title,
+ users.username as author_username,
+ users.name as author_name
+ FROM comment_has_events
+ LEFT JOIN users ON users.id=comment_has_events.creator_id
+ LEFT JOIN tasks ON tasks.id=comment_has_events.task_id
+ WHERE comment_has_events.project_id = ?
+ ORDER BY comment_has_events.id DESC
+ LIMIT 0, '.$limit.'
+ ';
+
+ $rq = $this->db->execute($sql, array($project_id));
+ $events = $rq->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($events as &$event) {
+ $event['author'] = $event['author_name'] ?: $event['author_username'];
+ $event['event_title'] = $this->getTitle($event);
+ $event['event_content'] = $this->getContent($event);
+ $event['event_type'] = 'comment';
+ }
+
+ return $events;
+ }
+
+ /**
+ * Get the event title (translated)
+ *
+ * @access public
+ * @param array $event Event properties
+ * @return string
+ */
+ public function getTitle(array $event)
+ {
+ $titles = array(
+ Comment::EVENT_UPDATE => t('%s updated a comment on the task #%d', $event['author'], $event['task_id']),
+ Comment::EVENT_CREATE => t('%s commented on the task #%d', $event['author'], $event['task_id']),
+ );
+
+ return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
+ }
+
+ /**
+ * Attach events to be able to record the history
+ *
+ * @access public
+ */
+ public function attachEvents()
+ {
+ $events = array(
+ Comment::EVENT_UPDATE,
+ Comment::EVENT_CREATE,
+ );
+
+ $listener = new CommentHistoryListener($this);
+
+ foreach ($events as $event_name) {
+ $this->event->attach($event_name, $listener);
+ }
+ }
+}
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index a92ce73e..0cb17076 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -115,45 +115,41 @@ class Notification extends Base
*/
public function getMailSubject($template, array $data)
{
- Translator::disableEscaping();
-
switch ($template) {
case 'notification_file_creation':
- $subject = t('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_creation':
- $subject = t('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_update':
- $subject = t('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_creation':
- $subject = t('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_update':
- $subject = t('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_creation':
- $subject = t('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_update':
- $subject = t('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_close':
- $subject = t('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_open':
- $subject = t('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_due':
- $subject = t('[%s][Due tasks]', $data['project']);
+ $subject = e('[%s][Due tasks]', $data['project']);
break;
default:
- $subject = t('[Kanboard] Notification');
+ $subject = e('[Kanboard] Notification');
}
- Translator::enableEscaping();
-
return $subject;
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 1da5c164..9aef3c7e 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -720,7 +720,25 @@ class Project extends Base
*/
public function getActivity($project_id)
{
- // TODO: merge comments and subtasks activity
- return $this->taskHistory->getAllContentByProjectId($project_id);
+ $activity = array();
+ $tasks = $this->taskHistory->getAllContentByProjectId($project_id, 25);
+ $comments = $this->commentHistory->getAllContentByProjectId($project_id, 25);
+ $subtasks = $this->subtaskHistory->getAllContentByProjectId($project_id, 25);
+
+ foreach ($tasks as &$task) {
+ $activity[$task['date_creation'].'-'.$task['id']] = $task;
+ }
+
+ foreach ($subtasks as &$subtask) {
+ $activity[$subtask['date_creation'].'-'.$subtask['id']] = $subtask;
+ }
+
+ foreach ($comments as &$comment) {
+ $activity[$comment['date_creation'].'-'.$comment['id']] = $comment;
+ }
+
+ krsort($activity);
+
+ return $activity;
}
}
diff --git a/app/Model/SubtaskHistory.php b/app/Model/SubtaskHistory.php
new file mode 100644
index 00000000..bbf6ce3d
--- /dev/null
+++ b/app/Model/SubtaskHistory.php
@@ -0,0 +1,161 @@
+<?php
+
+namespace Model;
+
+use PDO;
+use Core\Registry;
+use Event\SubtaskHistoryListener;
+
+/**
+ * Comment history model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class SubtaskHistory extends BaseHistory
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'subtask_has_events';
+
+ /**
+ * Maximum number of events
+ *
+ * @var integer
+ */
+ const MAX_EVENTS = 5000;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Core\Registry $registry Registry instance
+ */
+ public function __construct(Registry $registry)
+ {
+ parent::__construct($registry);
+ $this->table = self::TABLE;
+ }
+
+ /**
+ * Create a new event
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $task_id Task id
+ * @param integer $subtask_id Subtask id
+ * @param integer $creator_id Author of the event (user id)
+ * @param string $event_name Task event name
+ * @param string $data Current comment
+ * @return boolean
+ */
+ public function create($project_id, $task_id, $subtask_id, $creator_id, $event_name, $data)
+ {
+ $values = array(
+ 'project_id' => $project_id,
+ 'task_id' => $task_id,
+ 'subtask_id' => $subtask_id,
+ 'creator_id' => $creator_id,
+ 'event_name' => $event_name,
+ 'date_creation' => time(),
+ 'data' => $data,
+ );
+
+ $this->db->startTransaction();
+
+ $this->cleanup(self::MAX_EVENTS - 1);
+ $result = $this->db->table(self::TABLE)->insert($values);
+
+ $this->db->closeTransaction();
+
+ return $result;
+ }
+
+ /**
+ * Get all necessary content to display activity feed
+ *
+ * $author_name
+ * $author_username
+ * $task['id', 'title', 'position', 'column_name']
+ */
+ public function getAllContentByProjectId($project_id, $limit = 50)
+ {
+ $sql = '
+ SELECT
+ subtask_has_events.id,
+ subtask_has_events.date_creation,
+ subtask_has_events.event_name,
+ subtask_has_events.task_id,
+ tasks.title as task_title,
+ users.username as author_username,
+ users.name as author_name,
+ assignees.name as subtask_assignee_name,
+ assignees.username as subtask_assignee_username,
+ task_has_subtasks.title as subtask_title,
+ task_has_subtasks.status as subtask_status,
+ task_has_subtasks.time_spent as subtask_time_spent,
+ task_has_subtasks.time_estimated as subtask_time_estimated
+ FROM subtask_has_events
+ LEFT JOIN users ON users.id=subtask_has_events.creator_id
+ LEFT JOIN tasks ON tasks.id=subtask_has_events.task_id
+ LEFT JOIN task_has_subtasks ON task_has_subtasks.id=subtask_has_events.subtask_id
+ LEFT JOIN users AS assignees ON assignees.id=task_has_subtasks.user_id
+ WHERE subtask_has_events.project_id = ?
+ ORDER BY subtask_has_events.id DESC
+ LIMIT 0, '.$limit.'
+ ';
+
+ $rq = $this->db->execute($sql, array($project_id));
+ $events = $rq->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($events as &$event) {
+ $event['author'] = $event['author_name'] ?: $event['author_username'];
+ $event['subtask_assignee'] = $event['subtask_assignee_name'] ?: $event['subtask_assignee_username'];
+ $event['subtask_status_list'] = $this->subTask->getStatusList();
+ $event['event_title'] = $this->getTitle($event);
+ $event['event_content'] = $this->getContent($event);
+ $event['event_type'] = 'subtask';
+ }
+
+ return $events;
+ }
+
+ /**
+ * Get the event title (translated)
+ *
+ * @access public
+ * @param array $event Event properties
+ * @return string
+ */
+ public function getTitle(array $event)
+ {
+ $titles = array(
+ SubTask::EVENT_UPDATE => t('%s updated a subtask for the task #%d', $event['author'], $event['task_id']),
+ SubTask::EVENT_CREATE => t('%s created a subtask for the task #%d', $event['author'], $event['task_id']),
+ );
+
+ return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
+ }
+
+ /**
+ * Attach events to be able to record the history
+ *
+ * @access public
+ */
+ public function attachEvents()
+ {
+ $events = array(
+ SubTask::EVENT_UPDATE,
+ SubTask::EVENT_CREATE,
+ );
+
+ $listener = new SubtaskHistoryListener($this);
+
+ foreach ($events as $event_name) {
+ $this->event->attach($event_name, $listener);
+ }
+ }
+}
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 7ebb4641..10d125d4 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -936,21 +936,21 @@ class Task extends Base
$tasks = $rq->fetchAll(PDO::FETCH_ASSOC);
$columns = array(
- t('Task Id'),
- t('Project'),
- t('Status'),
- t('Category'),
- t('Column'),
- t('Position'),
- t('Color'),
- t('Due date'),
- t('Creator'),
- t('Assignee'),
- t('Complexity'),
- t('Title'),
- t('Creation date'),
- t('Modification date'),
- t('Completion date'),
+ e('Task Id'),
+ e('Project'),
+ e('Status'),
+ e('Category'),
+ e('Column'),
+ e('Position'),
+ e('Color'),
+ e('Due date'),
+ e('Creator'),
+ e('Assignee'),
+ e('Complexity'),
+ e('Title'),
+ e('Creation date'),
+ e('Modification date'),
+ e('Completion date'),
);
$results = array($columns);
@@ -973,7 +973,7 @@ class Task extends Base
{
$colors = $this->getColors();
$task['score'] = $task['score'] ?: '';
- $task['is_active'] = $task['is_active'] == self::STATUS_OPEN ? t('Open') : t('Closed');
+ $task['is_active'] = $task['is_active'] == self::STATUS_OPEN ? e('Open') : e('Closed');
$task['color_id'] = $colors[$task['color_id']];
$task['date_creation'] = date('Y-m-d', $task['date_creation']);
$task['date_due'] = $task['date_due'] ? date('Y-m-d', $task['date_due']) : '';
diff --git a/app/Model/TaskHistory.php b/app/Model/TaskHistory.php
index 181e4181..35b7cb27 100644
--- a/app/Model/TaskHistory.php
+++ b/app/Model/TaskHistory.php
@@ -3,7 +3,7 @@
namespace Model;
use PDO;
-use Core\Template;
+use Core\Registry;
use Event\TaskHistoryListener;
/**
@@ -12,7 +12,7 @@ use Event\TaskHistoryListener;
* @package model
* @author Frederic Guillot
*/
-class TaskHistory extends Base
+class TaskHistory extends BaseHistory
{
/**
* SQL table name
@@ -29,6 +29,18 @@ class TaskHistory extends Base
const MAX_EVENTS = 5000;
/**
+ * Constructor
+ *
+ * @access public
+ * @param \Core\Registry $registry Registry instance
+ */
+ public function __construct(Registry $registry)
+ {
+ parent::__construct($registry);
+ $this->table = self::TABLE;
+ }
+
+ /**
* Create a new event
*
* @access public
@@ -59,40 +71,6 @@ class TaskHistory extends Base
}
/**
- * Remove old event entries to avoid a large table
- *
- * @access public
- * @param integer $max Maximum number of items to keep in the table
- */
- public function cleanup($max)
- {
- if ($this->db->table(self::TABLE)->count() > $max) {
-
- $this->db->execute('
- DELETE FROM '.self::TABLE.'
- WHERE id <= (
- SELECT id FROM (
- SELECT id FROM '.self::TABLE.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.'
- ) foo
- )');
- }
- }
-
- /**
- * Get all events for a given project
- *
- * @access public
- * @return array
- */
- public function getAllByProjectId($project_id)
- {
- return $this->db->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->desc('id')
- ->findAll();
- }
-
- /**
* Get all necessary content to display activity feed
*
* $author_name
@@ -103,6 +81,7 @@ class TaskHistory extends Base
{
$sql = '
SELECT
+ task_has_events.id,
task_has_events.date_creation,
task_has_events.event_name,
task_has_events.task_id,
@@ -155,19 +134,6 @@ class TaskHistory extends Base
}
/**
- * Get the event html content
- *
- * @access public
- * @param array $params Event properties
- * @return string
- */
- public function getContent(array $params)
- {
- $tpl = new Template;
- return $tpl->load('event_'.str_replace('.', '_', $params['event_name']), $params);
- }
-
- /**
* Attach events to be able to record the history
*
* @access public
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 9b202a69..9ab12a1a 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -4,7 +4,59 @@ namespace Schema;
use Core\Security;
-const VERSION = 24;
+const VERSION = 25;
+
+function version_25($pdo)
+{
+ $pdo->exec("
+ CREATE TABLE task_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ subtask_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ comment_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+}
function version_24($pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 99774a55..b58b9bb3 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -4,7 +4,59 @@ namespace Schema;
use Core\Security;
-const VERSION = 5;
+const VERSION = 6;
+
+function version_6($pdo)
+{
+ $pdo->exec("
+ CREATE TABLE task_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ subtask_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ comment_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+}
function version_5($pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index e18d35e9..ecd62c97 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -11,13 +11,48 @@ function version_25($pdo)
$pdo->exec("
CREATE TABLE task_has_events (
id INTEGER PRIMARY KEY,
- date_creation INTEGER,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id INTEGER PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ subtask_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id INTEGER PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
event_name TEXT NOT NULL,
creator_id INTEGER,
project_id INTEGER,
+ comment_id INTEGER,
task_id INTEGER,
+ data TEXT,
FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
);
");
diff --git a/app/Templates/event_comment_create.php b/app/Templates/event_comment_create.php
new file mode 100644
index 00000000..09d45ed0
--- /dev/null
+++ b/app/Templates/event_comment_create.php
@@ -0,0 +1,7 @@
+<p class="activity-title">
+ <?= e('%s commented the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
+</p>
+<p class="activity-description">
+ <em><?= Helper\escape($task_title) ?></em><br/>
+ <div class="markdown"><?= Helper\parse($comment) ?></div>
+</p> \ No newline at end of file
diff --git a/app/Templates/event_comment_update.php b/app/Templates/event_comment_update.php
new file mode 100644
index 00000000..a42e5dab
--- /dev/null
+++ b/app/Templates/event_comment_update.php
@@ -0,0 +1,7 @@
+<p class="activity-title">
+ <?= e('%s updated a comment on the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
+</p>
+<p class="activity-description">
+ <em><?= Helper\escape($task_title) ?></em><br/>
+ <div class="markdown"><?= Helper\parse($comment) ?></div>
+</p> \ No newline at end of file
diff --git a/app/Templates/event_subtask_create.php b/app/Templates/event_subtask_create.php
new file mode 100644
index 00000000..81268449
--- /dev/null
+++ b/app/Templates/event_subtask_create.php
@@ -0,0 +1,12 @@
+<p class="activity-title">
+ <?= e('%s created a subtask for the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
+</p>
+<p class="activity-description">
+ <em><?= Helper\escape($task_title) ?></em><br/>
+ <p><?= Helper\escape($subtask_title) ?> <strong>(<?= Helper\in_list($subtask_status, $subtask_status_list) ?>)</strong></p>
+ <?php if ($subtask_assignee): ?>
+ <p><?= t('Assigned to %s with estimate of %s/%sh', $subtask_assignee, $subtask_time_spent, $subtask_time_estimated) ?></p>
+ <?php else: ?>
+ <p><?= t('Not assigned, estimate of %sh', $subtask_time_estimated) ?></p>
+ <?php endif ?>
+</p> \ No newline at end of file
diff --git a/app/Templates/event_subtask_update.php b/app/Templates/event_subtask_update.php
new file mode 100644
index 00000000..9862f997
--- /dev/null
+++ b/app/Templates/event_subtask_update.php
@@ -0,0 +1,12 @@
+<p class="activity-title">
+ <?= e('%s updated a subtask for the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
+</p>
+<p class="activity-description">
+ <em><?= Helper\escape($task_title) ?></em><br/>
+ <p><?= Helper\escape($subtask_title) ?> <strong>(<?= Helper\in_list($subtask_status, $subtask_status_list) ?>)</strong></p>
+ <?php if ($subtask_assignee): ?>
+ <p><?= t('Assigned to %s with estimate of %s/%sh', $subtask_assignee, $subtask_time_spent, $subtask_time_estimated) ?></p>
+ <?php else: ?>
+ <p><?= t('Not assigned, estimate of %sh', $subtask_time_estimated) ?></p>
+ <?php endif ?>
+</p> \ No newline at end of file
diff --git a/app/Templates/event_task_close.php b/app/Templates/event_task_close.php
index d5952d74..9d92ea55 100644
--- a/app/Templates/event_task_close.php
+++ b/app/Templates/event_task_close.php
@@ -1,5 +1,5 @@
<p class="activity-title">
- <?= t('%s closed the task #%d', $author, $task_id) ?>
+ <?= e('%s closed the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
</p>
<p class="activity-description">
<em><?= Helper\escape($task_title) ?></em>
diff --git a/app/Templates/event_task_create.php b/app/Templates/event_task_create.php
index f0dcf2d7..7ceab4bb 100644
--- a/app/Templates/event_task_create.php
+++ b/app/Templates/event_task_create.php
@@ -1,5 +1,5 @@
<p class="activity-title">
- <?= t('%s created the task #%d', $author, $task_id) ?>
+ <?= e('%s created the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
</p>
<p class="activity-description">
<em><?= Helper\escape($task_title) ?></em>
diff --git a/app/Templates/event_task_move_column.php b/app/Templates/event_task_move_column.php
index 0ccad655..a674f80a 100644
--- a/app/Templates/event_task_move_column.php
+++ b/app/Templates/event_task_move_column.php
@@ -1,5 +1,5 @@
<p class="activity-title">
- <?= t('%s moved the task #%d to the column %s', $author, $task_id, $task_column_name) ?>
+ <?= e('%s moved the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a> to the column "%s"', Helper\escape($author), $task_id, $task_id, Helper\escape($task_column_name)) ?>
</p>
<p class="activity-description">
<em><?= Helper\escape($task_title) ?></em>
diff --git a/app/Templates/event_task_move_position.php b/app/Templates/event_task_move_position.php
index e7d6b244..0b7e9615 100644
--- a/app/Templates/event_task_move_position.php
+++ b/app/Templates/event_task_move_position.php
@@ -1,5 +1,5 @@
<p class="activity-title">
- <?= t('%s moved the task #%d to the position %d in the column %s', $author, $task_id, $task_position, $task_column_name) ?>
+ <?= e('%s moved the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a> to the position #%d in the column "%s"', Helper\escape($author), $task_id, $task_id, $task_position, Helper\escape($task_column_name)) ?>
</p>
<p class="activity-description">
<em><?= Helper\escape($task_title) ?></em>
diff --git a/app/Templates/event_task_open.php b/app/Templates/event_task_open.php
index b3bc595a..763b0dfc 100644
--- a/app/Templates/event_task_open.php
+++ b/app/Templates/event_task_open.php
@@ -1,6 +1,6 @@
<p class="activity-title">
- <?= t('%s open the task #%d', $author, $task_id) ?>
+ <?= e('%s open the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
</p>
<p class="activity-description">
- <em><?= Helper\escape($task_title ?></em>
+ <em><?= Helper\escape($task_title) ?></em>
</p> \ No newline at end of file
diff --git a/app/Templates/event_task_update.php b/app/Templates/event_task_update.php
index e2af6776..313e79cb 100644
--- a/app/Templates/event_task_update.php
+++ b/app/Templates/event_task_update.php
@@ -1,5 +1,5 @@
<p class="activity-title">
- <?= t('%s updated the task #%d', $author, $task_id) ?>
+ <?= e('%s updated the task <a href="?controller=task&amp;action=show&amp;task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
</p>
<p class="activity-description">
<em><?= Helper\escape($task_title) ?></em>
diff --git a/app/Templates/project_activity.php b/app/Templates/project_activity.php
index 7886cfa4..b79d97f9 100644
--- a/app/Templates/project_activity.php
+++ b/app/Templates/project_activity.php
@@ -17,6 +17,10 @@
<p class="activity-datetime">
<?php if ($event['event_type'] === 'task'): ?>
<i class="fa fa-newspaper-o"></i>
+ <?php elseif ($event['event_type'] === 'subtask'): ?>
+ <i class="fa fa-tasks"></i>
+ <?php elseif ($event['event_type'] === 'comment'): ?>
+ <i class="fa fa-comments-o"></i>
<?php endif ?>
&nbsp;<?= dt('%B %e, %Y at %k:%M %p', $event['date_creation']) ?>
</p>
diff --git a/app/translator.php b/app/translator.php
index 338821d3..ac4d72e2 100644
--- a/app/translator.php
+++ b/app/translator.php
@@ -9,6 +9,13 @@ function t()
return call_user_func_array(array($t, 'translate'), func_get_args());
}
+// translate with no html escaping
+function e()
+{
+ $t = new Translator;
+ return call_user_func_array(array($t, 'translateNoEscaping'), func_get_args());
+}
+
// Get a locale currency
function c($value)
{