|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gitamin\Presenters; |
|
13
|
|
|
|
|
14
|
|
|
use Gitamin\Facades\Setting; |
|
15
|
|
|
use Gitamin\Models\Comment; |
|
16
|
|
|
use Gitamin\Models\Issue; |
|
17
|
|
|
use Gitamin\Models\Moment; |
|
18
|
|
|
use Gitamin\Presenters\Traits\TimestampsTrait; |
|
19
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
|
20
|
|
|
use Jenssegers\Date\Date; |
|
21
|
|
|
|
|
22
|
|
|
class MomentPresenter extends AbstractPresenter |
|
23
|
|
|
{ |
|
24
|
|
|
use TimestampsTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Renders the message from Markdown into HTML. |
|
28
|
|
|
* |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
public function formattedData() |
|
32
|
|
|
{ |
|
33
|
|
|
return Markdown::convertToHtml($this->wrappedObject->data); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function formattedTarget() |
|
37
|
|
|
{ |
|
38
|
|
|
if ($this->wrappedObject->target instanceof Comment) { |
|
39
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->message); |
|
|
|
|
|
|
40
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
|
41
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the moment action summary. |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function actionName() |
|
51
|
|
|
{ |
|
52
|
|
|
switch ($this->wrappedObject->action) { |
|
53
|
|
|
case Moment::CREATED: |
|
54
|
|
|
return 'created'; |
|
55
|
|
|
case Moment::CLOSED: |
|
56
|
|
|
return 'closed'; |
|
57
|
|
|
case Moment::COMMENTED: |
|
58
|
|
|
return 'commented on'; |
|
59
|
|
|
default: |
|
60
|
|
|
return 'Unknow'; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function icon() |
|
65
|
|
|
{ |
|
66
|
|
|
if ($this->wrappedObject->target instanceof Comment) { |
|
67
|
|
|
return 'fa fa-comments-o'; |
|
68
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
|
69
|
|
|
return 'fa fa-exclamation-circle'; |
|
70
|
|
|
} else { |
|
71
|
|
|
return 'fa fa-code-fork'; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Present formatted date time. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public function created_at_iso() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Convert presented moment to an array. |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
public function toArray() |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
|
|
'summary' => $this->summary(), |
|
|
|
|
|
|
94
|
|
|
'created_at_iso' => $this->created_at_iso(), |
|
95
|
|
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.