forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdown.php
More file actions
88 lines (70 loc) · 1.93 KB
/
Markdown.php
File metadata and controls
88 lines (70 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace kriskbx\gtt\Output;
use Illuminate\Support\Collection;
use kriskbx\gtt\Issue;
use kriskbx\gtt\Time;
class Markdown extends AbstractOutput
{
/**
* @var string
*/
protected $contents = '';
/**
* Render.
*
* @param Collection $issues
* @param array $params
*
* @return void
*/
public function render(Collection $issues, array $params)
{
$params = array_merge($params, [
'columns' => $this->columns,
'delimiter' => " | ",
'timesDelimiter' => "<br><br>",
'break' => "<br>",
'beforeHighlight' => "**",
'afterHighlight' => "**",
'beforeHeadline' => "***",
'afterHeadline' => "***"
]);
$this->tableHeaders();
$issues->each(function (Issue $issue) use ($params) {
$this->addToTotal($issue);
$this->contents .= "\n| " . $issue->toString($params) . " |";
});
$this->total();
$this->write($this->contents, $this->file);
$this->cleanUp();
}
/**
* Clean up.
*/
protected function cleanUp()
{
$this->contents = '';
}
/**
* Set total times.
*/
protected function total()
{
$subString = "* **Total:** " . Time::humanReadable($this->totalTime) . "\n";
collect($this->totalTimeByUser)->each(function ($time, $user) use (&$subString) {
$subString .= "* **{$user}:** " . Time::humanReadable($time) . "\n";
});
$this->contents = $subString . "\n\n" . $this->contents;
}
/**
* Set table headers.
*/
protected function tableHeaders()
{
$this->contents .= "| " . implode(" | ", $this->columns) . " |\n";
collect($this->columns)->each(function () {
$this->contents .= "| --- ";
});
$this->contents .= "|";
}
}