summaryrefslogtreecommitdiff
path: root/app/Formatter
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-06-24 10:05:45 -0400
committerFrederic Guillot <fred@kanboard.net>2016-06-24 10:05:45 -0400
commit700b4e8f0265e4eabd7a7c0eb6a06088d50554fe (patch)
treee38c011894e6f53b59557ad9a86fed8ad6bf6049 /app/Formatter
parent9e278a9370e3b651a4a545c0c0c0c256088ed187 (diff)
Associate tags to tasks in BoardFormatter
Diffstat (limited to 'app/Formatter')
-rw-r--r--app/Formatter/BoardColumnFormatter.php15
-rw-r--r--app/Formatter/BoardFormatter.php5
-rw-r--r--app/Formatter/BoardSwimlaneFormatter.php15
-rw-r--r--app/Formatter/BoardTaskFormatter.php22
4 files changed, 53 insertions, 4 deletions
diff --git a/app/Formatter/BoardColumnFormatter.php b/app/Formatter/BoardColumnFormatter.php
index 3d8f6e67..d49a577a 100644
--- a/app/Formatter/BoardColumnFormatter.php
+++ b/app/Formatter/BoardColumnFormatter.php
@@ -15,6 +15,7 @@ class BoardColumnFormatter extends BaseFormatter implements FormatterInterface
protected $swimlaneId = 0;
protected $columns = array();
protected $tasks = array();
+ protected $tags = array();
/**
* Set swimlaneId
@@ -56,6 +57,19 @@ class BoardColumnFormatter extends BaseFormatter implements FormatterInterface
}
/**
+ * Set tags
+ *
+ * @access public
+ * @param array $tags
+ * @return $this
+ */
+ public function withTags(array $tags)
+ {
+ $this->tags = $tags;
+ return $this;
+ }
+
+ /**
* Apply formatter
*
* @access public
@@ -66,6 +80,7 @@ class BoardColumnFormatter extends BaseFormatter implements FormatterInterface
foreach ($this->columns as &$column) {
$column['tasks'] = BoardTaskFormatter::getInstance($this->container)
->withTasks($this->tasks)
+ ->withTags($this->tags)
->withSwimlaneId($this->swimlaneId)
->withColumnId($column['id'])
->format();
diff --git a/app/Formatter/BoardFormatter.php b/app/Formatter/BoardFormatter.php
index 562a97bc..350dde6c 100644
--- a/app/Formatter/BoardFormatter.php
+++ b/app/Formatter/BoardFormatter.php
@@ -44,12 +44,14 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface
{
$swimlanes = $this->swimlaneModel->getSwimlanes($this->projectId);
$columns = $this->columnModel->getAll($this->projectId);
-
$tasks = $this->query
->eq(TaskModel::TABLE.'.project_id', $this->projectId)
->asc(TaskModel::TABLE.'.position')
->findAll();
+ $task_ids = array_column($tasks, 'id');
+ $tags = $this->taskTagModel->getTagsByTasks($task_ids);
+
if (empty($swimlanes) || empty($columns)) {
return array();
}
@@ -58,6 +60,7 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface
->withSwimlanes($swimlanes)
->withColumns($columns)
->withTasks($tasks)
+ ->withTags($tags)
->format();
}
}
diff --git a/app/Formatter/BoardSwimlaneFormatter.php b/app/Formatter/BoardSwimlaneFormatter.php
index 91b4bfd7..c2abb444 100644
--- a/app/Formatter/BoardSwimlaneFormatter.php
+++ b/app/Formatter/BoardSwimlaneFormatter.php
@@ -15,6 +15,7 @@ class BoardSwimlaneFormatter extends BaseFormatter implements FormatterInterface
protected $swimlanes = array();
protected $columns = array();
protected $tasks = array();
+ protected $tags = array();
/**
* Set swimlanes
@@ -56,6 +57,19 @@ class BoardSwimlaneFormatter extends BaseFormatter implements FormatterInterface
}
/**
+ * Set tags
+ *
+ * @access public
+ * @param array $tags
+ * @return $this
+ */
+ public function withTags(array $tags)
+ {
+ $this->tags = $tags;
+ return $this;
+ }
+
+ /**
* Apply formatter
*
* @access public
@@ -71,6 +85,7 @@ class BoardSwimlaneFormatter extends BaseFormatter implements FormatterInterface
->withSwimlaneId($swimlane['id'])
->withColumns($this->columns)
->withTasks($this->tasks)
+ ->withTags($this->tags)
->format();
$swimlane['nb_swimlanes'] = $nb_swimlanes;
diff --git a/app/Formatter/BoardTaskFormatter.php b/app/Formatter/BoardTaskFormatter.php
index d9500710..3bf171b1 100644
--- a/app/Formatter/BoardTaskFormatter.php
+++ b/app/Formatter/BoardTaskFormatter.php
@@ -13,10 +13,24 @@ use Kanboard\Core\Filter\FormatterInterface;
class BoardTaskFormatter extends BaseFormatter implements FormatterInterface
{
protected $tasks = array();
+ protected $tags = array();
protected $columnId = 0;
protected $swimlaneId = 0;
/**
+ * Set tags
+ *
+ * @access public
+ * @param array $tags
+ * @return $this
+ */
+ public function withTags(array $tags)
+ {
+ $this->tags = $tags;
+ return $this;
+ }
+
+ /**
* Set tasks
*
* @access public
@@ -63,17 +77,19 @@ class BoardTaskFormatter extends BaseFormatter implements FormatterInterface
*/
public function format()
{
- return array_values(array_filter($this->tasks, array($this, 'filterTasks')));
+ $tasks = array_values(array_filter($this->tasks, array($this, 'filterTasks')));
+ array_merge_relation($tasks, $this->tags, 'tags', 'id');
+ return $tasks;
}
/**
* Keep only tasks of the given column and swimlane
*
- * @access public
+ * @access protected
* @param array $task
* @return bool
*/
- public function filterTasks(array $task)
+ protected function filterTasks(array $task)
{
return $task['column_id'] == $this->columnId && $task['swimlane_id'] == $this->swimlaneId;
}