Add subtasks and comments history

This commit is contained in:
Frédéric Guillot 2014-09-10 16:21:47 +02:00
parent 9bde377bbe
commit 28ff8dad91
29 changed files with 822 additions and 136 deletions

View File

@ -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();
}
}
/**

View File

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

View File

@ -26,44 +26,13 @@ class Translator
*/
private static $locales = array();
/**
* Flag to enable HTML escaping
*
* @static
* @access private
* @var boolean
*/
private static $enable_escaping = true;
/**
* Disable HTML escaping for translations
*
* @static
* @access public
*/
public static function disableEscaping()
{
self::$enable_escaping = false;
}
/**
* Enable HTML escaping for translations
*
* @static
* @access public
*/
public static function enableEscaping()
{
self::$enable_escaping = true;
}
/**
* Get a translation
*
* $translator->translate('I have %d kids', 5);
*
* @access public
* @param $identifier
* @param string $identifier Default string
* @return string
*/
public function translate($identifier)
@ -73,10 +42,8 @@ class Translator
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);
}
foreach ($args as &$arg) {
$arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
}
return call_user_func_array(
@ -85,6 +52,28 @@ class Translator
);
}
/**
* Get a translation with no HTML escaping
*
* $translator->translateNoEscaping('I have %d kids', 5);
*
* @access public
* @param string $identifier Default string
* @return string
*/
public function translateNoEscaping($identifier)
{
$args = func_get_args();
array_shift($args);
array_unshift($args, $this->get($identifier, $identifier));
return call_user_func_array(
'sprintf',
$args
);
}
/**
* Get a formatted number
*

View File

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

View File

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

View File

@ -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)
{

70
app/Model/BaseHistory.php Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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']) : '';

View File

@ -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
@ -28,6 +28,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
*
@ -58,40 +70,6 @@ class TaskHistory extends Base
return $result;
}
/**
* 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
*
@ -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,
@ -154,19 +133,6 @@ class TaskHistory extends Base
return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
}
/**
* 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
*

View File

@ -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)
{

View File

@ -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)
{

View File

@ -11,16 +11,51 @@ 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
);
");
}
function version_24($pdo)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)
{

View File

@ -43,7 +43,10 @@ require_once __DIR__.'/../../app/Model/Action.php';
require_once __DIR__.'/../../app/Model/Category.php';
require_once __DIR__.'/../../app/Model/SubTask.php';
require_once __DIR__.'/../../app/Model/File.php';
require_once __DIR__.'/../../app/Model/BaseHistory.php';
require_once __DIR__.'/../../app/Model/TaskHistory.php';
require_once __DIR__.'/../../app/Model/SubtaskHistory.php';
require_once __DIR__.'/../../app/Model/CommentHistory.php';
require_once __DIR__.'/../../app/Action/Base.php';
require_once __DIR__.'/../../app/Action/TaskClose.php';