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

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