diff options
author | BlueTeck <tili2@gmx.de> | 2015-03-29 12:48:24 +0200 |
---|---|---|
committer | BlueTeck <tili2@gmx.de> | 2015-03-29 12:48:24 +0200 |
commit | 58b0159e87f778819b6045ae5a099fa06b4f1a72 (patch) | |
tree | b0f1811c2ed869710baed246177f9f0a89548411 /app/Model | |
parent | 5536f6c6ce591ba05a169d2e33b6fb240378d8a4 (diff) |
add activity stream to task #693
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/ProjectActivity.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php index c5fbbd38..46d71fc7 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivity.php @@ -50,6 +50,52 @@ class ProjectActivity extends Base return $this->db->table(self::TABLE)->insert($values); } + /** + * Get all events for the given task + * + * @access public + * @param integer[] $task_ids Task ids + * @param integer $limit Maximum events number + * @param integer $start Timestamp of earliest activity + * @param integer $end Timestamp of latest activity + * @return array + */ + public function getTasks(array $task_ids, $limit = 50, $start = null, $end = null) + { + $query = $this->db->table(self::TABLE) + ->columns( + self::TABLE.'.*', + User::TABLE.'.username AS author_username', + User::TABLE.'.name AS author_name' + ) + ->in('task_id', $task_ids) + ->join(User::TABLE, 'id', 'creator_id') + ->desc(self::TABLE.'.id') + ->limit($limit); + + if(!is_null($start)){ + $query->gte('date_creation', $start); + } + + if(!is_null($end)){ + $query->lte('date_creation', $end); + } + + $events = $query->findAll(); + + foreach ($events as &$event) { + + $event += $this->decode($event['data']); + unset($event['data']); + + $event['author'] = $event['author_name'] ?: $event['author_username']; + $event['event_title'] = $this->getTitle($event); + $event['event_content'] = $this->getContent($event); + } + + return $events; + } + /** * Get all events for the given project * |