add activity stream to task #693

This commit is contained in:
BlueTeck 2015-03-29 12:48:24 +02:00
parent 5536f6c6ce
commit 58b0159e87
4 changed files with 90 additions and 0 deletions

View File

@ -84,6 +84,22 @@ class Task extends Base
)));
}
/**
* Display task activities
*
* @access public
*/
public function activites()
{
$task = $this->getTask();
$this->response->html($this->taskLayout('task/events', array(
'title' => $task['title'],
'task' => $task,
'ajax' => $this->request->isAjax(),
'events' => $this->projectActivity->getTasks([$task['id']]),
)));
}
/**
* Display a form to create a new task
*

View File

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

View File

@ -0,0 +1,25 @@
<div class="page-header">
<h2><?= t('Activity stream') ?></h2>
</div>
<?php if (empty($events)): ?>
<p class="alert"><?= t('No activity.') ?></p>
<?php else: ?>
<?php foreach ($events as $event): ?>
<div class="activity-event">
<p class="activity-datetime">
<?php if ($this->contains($event['event_name'], 'subtask')): ?>
<i class="fa fa-tasks"></i>
<?php elseif ($this->contains($event['event_name'], 'task')): ?>
<i class="fa fa-newspaper-o"></i>
<?php elseif ($this->contains($event['event_name'], 'comment')): ?>
<i class="fa fa-comments-o"></i>
<?php endif ?>
&nbsp;<?= dt('%B %e, %Y at %k:%M %p', $event['date_creation']) ?>
</p>
<div class="activity-content"><?= $event['event_content'] ?></div>
</div>
<?php endforeach ?>
<?php endif ?>

View File

@ -4,6 +4,9 @@
<li>
<?= $this->a(t('Summary'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
</li>
<li>
<?= $this->a(t('Activity stream'), 'task', 'activites', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
</li>
<li>
<?= $this->a(t('Transitions'), 'task', 'transitions', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
</li>