Add tags to task export
This commit is contained in:
@@ -30,11 +30,13 @@ class TaskExport extends Base
|
|||||||
public function export($project_id, $from, $to)
|
public function export($project_id, $from, $to)
|
||||||
{
|
{
|
||||||
$tasks = $this->getTasks($project_id, $from, $to);
|
$tasks = $this->getTasks($project_id, $from, $to);
|
||||||
|
$taskIds = array_column($tasks, 'id');
|
||||||
|
$tags = $this->taskTagModel->getTagsByTaskIds($taskIds);
|
||||||
$colors = $this->colorModel->getList();
|
$colors = $this->colorModel->getList();
|
||||||
$results = array($this->getColumns());
|
$results = array($this->getColumns());
|
||||||
|
|
||||||
foreach ($tasks as &$task) {
|
foreach ($tasks as &$task) {
|
||||||
$task = $this->format($task, $colors);
|
$task = $this->format($task, $colors, $tags);
|
||||||
$results[] = array_values($task);
|
$results[] = array_values($task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,14 +106,16 @@ class TaskExport extends Base
|
|||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param array $task
|
* @param array $task
|
||||||
* @param array $colors
|
* @param array $colors
|
||||||
|
* @param array $tags
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function format(array &$task, array $colors)
|
protected function format(array &$task, array $colors, array &$tags)
|
||||||
{
|
{
|
||||||
$task['is_active'] = $task['is_active'] == TaskModel::STATUS_OPEN ? e('Open') : e('Closed');
|
$task['is_active'] = $task['is_active'] == TaskModel::STATUS_OPEN ? e('Open') : e('Closed');
|
||||||
$task['color_id'] = $colors[$task['color_id']];
|
$task['color_id'] = $colors[$task['color_id']];
|
||||||
$task['score'] = $task['score'] ?: 0;
|
$task['score'] = $task['score'] ?: 0;
|
||||||
|
$task['tags'] = '';
|
||||||
|
|
||||||
$task = $this->dateParser->format(
|
$task = $this->dateParser->format(
|
||||||
$task,
|
$task,
|
||||||
@@ -119,6 +123,11 @@ class TaskExport extends Base
|
|||||||
$this->dateParser->getUserDateTimeFormat()
|
$this->dateParser->getUserDateTimeFormat()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($tags[$task['id']])) {
|
||||||
|
$taskTags = array_column($tags[$task['id']], 'name');
|
||||||
|
$task['tags'] = implode(', ', $taskTags);
|
||||||
|
}
|
||||||
|
|
||||||
return $task;
|
return $task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +163,7 @@ class TaskExport extends Base
|
|||||||
e('Time estimated'),
|
e('Time estimated'),
|
||||||
e('Time spent'),
|
e('Time spent'),
|
||||||
e('Priority'),
|
e('Priority'),
|
||||||
|
e('Tags'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,13 @@ class TaskExportTest extends Base
|
|||||||
'swimlane_id' => 2,
|
'swimlane_id' => 2,
|
||||||
'title' => 'Task 2',
|
'title' => 'Task 2',
|
||||||
'date_due' => time(),
|
'date_due' => time(),
|
||||||
|
'tags' => array('tag 1', 'tag 2'),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$report = $taskExport->export(1, date('Y-m-d'), date('Y-m-d'));
|
$report = $taskExport->export(1, date('Y-m-d'), date('Y-m-d'));
|
||||||
|
|
||||||
$this->assertCount(3, $report);
|
$this->assertCount(3, $report);
|
||||||
$this->assertCount(23, $report[0]);
|
$this->assertCount(24, $report[0]);
|
||||||
$this->assertEquals('Task Id', $report[0][0]);
|
$this->assertEquals('Task Id', $report[0][0]);
|
||||||
|
|
||||||
$this->assertEquals(1, $report[1][0]);
|
$this->assertEquals(1, $report[1][0]);
|
||||||
@@ -77,5 +78,7 @@ class TaskExportTest extends Base
|
|||||||
|
|
||||||
$this->assertEquals(2.5, $report[1][20]);
|
$this->assertEquals(2.5, $report[1][20]);
|
||||||
$this->assertEquals(0, $report[2][20]);
|
$this->assertEquals(0, $report[2][20]);
|
||||||
|
|
||||||
|
$this->assertEquals('tag 1, tag 2', $report[2][23]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user