summaryrefslogtreecommitdiff
path: root/app/Model/BaseHistory.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-10 16:21:47 +0200
committerFrédéric Guillot <fred@kanboard.net>2014-09-10 16:21:47 +0200
commit28ff8dad91c9e3c25f6a3b5398ae15f2a1ef95cd (patch)
tree0cecc5cbb6e7e6795dd032cc6a5703cd88b8770e /app/Model/BaseHistory.php
parent9bde377bbe85617dde280af985e033cf7de61803 (diff)
Add subtasks and comments history
Diffstat (limited to 'app/Model/BaseHistory.php')
-rw-r--r--app/Model/BaseHistory.php70
1 files changed, 70 insertions, 0 deletions
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);
+ }
+}