summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controller/Task.php7
-rw-r--r--app/Model/ProjectActivity.php117
-rw-r--r--app/Template/app/dashboard.php2
-rw-r--r--app/Template/event/events.php (renamed from app/Template/project/events.php)0
-rw-r--r--app/Template/project/activity.php2
-rw-r--r--app/Template/task/activity.php5
-rw-r--r--app/Template/task/events.php25
7 files changed, 69 insertions, 89 deletions
diff --git a/app/Controller/Task.php b/app/Controller/Task.php
index 9bd6e711..3c5b5c39 100644
--- a/app/Controller/Task.php
+++ b/app/Controller/Task.php
@@ -92,14 +92,15 @@ class Task extends Base
public function activites()
{
$task = $this->getTask();
- $this->response->html($this->taskLayout('task/events', array(
+
+ $this->response->html($this->taskLayout('task/activity', array(
'title' => $task['title'],
'task' => $task,
'ajax' => $this->request->isAjax(),
- 'events' => $this->projectActivity->getTasks([$task['id']]),
+ 'events' => $this->projectActivity->getTask($task['id']),
)));
}
-
+
/**
* Display a form to create a new task
*
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 05081a47..27f1cfcd 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -50,52 +50,6 @@ 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
*
@@ -127,23 +81,68 @@ class ProjectActivity extends Base
return array();
}
- $query = $this->db->table(self::TABLE)
- ->columns(
- self::TABLE.'.*',
- User::TABLE.'.username AS author_username',
- User::TABLE.'.name AS author_name',
- User::TABLE.'.email'
- )
- ->in('project_id', $project_ids)
- ->join(User::TABLE, 'id', 'creator_id')
- ->desc(self::TABLE.'.id')
- ->limit($limit);
+ $query = $this
+ ->db
+ ->table(self::TABLE)
+ ->columns(
+ self::TABLE.'.*',
+ User::TABLE.'.username AS author_username',
+ User::TABLE.'.name AS author_name',
+ User::TABLE.'.email'
+ )
+ ->in('project_id', $project_ids)
+ ->join(User::TABLE, 'id', 'creator_id')
+ ->desc(self::TABLE.'.id')
+ ->limit($limit);
+
+ return $this->getEvents($query, $start, $end);
+ }
+
+ /**
+ * Get all events for the given task
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @param integer $limit Maximum events number
+ * @param integer $start Timestamp of earliest activity
+ * @param integer $end Timestamp of latest activity
+ * @return array
+ */
+ public function getTask($task_id, $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',
+ User::TABLE.'.email'
+ )
+ ->eq('task_id', $task_id)
+ ->join(User::TABLE, 'id', 'creator_id')
+ ->desc(self::TABLE.'.id')
+ ->limit($limit);
+
+ return $this->getEvents($query, $start, $end);
+ }
- if (!is_null($start)){
+ /**
+ * Common function to return events
+ *
+ * @access public
+ * @param \PicoDb\Table $query PicoDb Query
+ * @param integer $start Timestamp of earliest activity
+ * @param integer $end Timestamp of latest activity
+ * @return array
+ */
+ private function getEvents(\PicoDb\Table $query, $start, $end)
+ {
+ if (! is_null($start)){
$query->gte('date_creation', $start);
}
- if (!is_null($end)){
+ if (! is_null($end)){
$query->lte('date_creation', $end);
}
diff --git a/app/Template/app/dashboard.php b/app/Template/app/dashboard.php
index 5b83540c..a832345b 100644
--- a/app/Template/app/dashboard.php
+++ b/app/Template/app/dashboard.php
@@ -53,7 +53,7 @@
</div>
<div id="dashboard-activities">
<h2><?= t('Activity stream') ?></h2>
- <?= $this->render('project/events', array('events' => $events)) ?>
+ <?= $this->render('event/events', array('events' => $events)) ?>
</div>
</div>
</section>
diff --git a/app/Template/project/events.php b/app/Template/event/events.php
index 93bc6584..93bc6584 100644
--- a/app/Template/project/events.php
+++ b/app/Template/event/events.php
diff --git a/app/Template/project/activity.php b/app/Template/project/activity.php
index bc4eb19c..7da6be5c 100644
--- a/app/Template/project/activity.php
+++ b/app/Template/project/activity.php
@@ -23,6 +23,6 @@
</ul>
</div>
<section>
- <?= $this->render('project/events', array('events' => $events)) ?>
+ <?= $this->render('event/events', array('events' => $events)) ?>
</section>
</section> \ No newline at end of file
diff --git a/app/Template/task/activity.php b/app/Template/task/activity.php
new file mode 100644
index 00000000..cc4aad03
--- /dev/null
+++ b/app/Template/task/activity.php
@@ -0,0 +1,5 @@
+<div class="page-header">
+ <h2><?= t('Activity stream') ?></h2>
+</div>
+
+<?= $this->render('event/events', array('events' => $events)) ?> \ No newline at end of file
diff --git a/app/Template/task/events.php b/app/Template/task/events.php
deleted file mode 100644
index 188f46fe..00000000
--- a/app/Template/task/events.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<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 ?> \ No newline at end of file