|
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\Models\Project; |
|
19
|
|
|
use Gitamin\Presenters\Traits\TimestampsTrait; |
|
20
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
|
21
|
|
|
use Jenssegers\Date\Date; |
|
22
|
|
|
|
|
23
|
|
|
class MomentPresenter extends AbstractPresenter |
|
24
|
|
|
{ |
|
25
|
|
|
use TimestampsTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Renders the message from Markdown into HTML. |
|
29
|
|
|
* |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
public function formattedData() |
|
33
|
|
|
{ |
|
34
|
|
|
return Markdown::convertToHtml($this->wrappedObject->data); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function formattedTarget() |
|
38
|
|
|
{ |
|
39
|
|
|
if ($this->wrappedObject->target instanceof Comment) { |
|
40
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->message); |
|
|
|
|
|
|
41
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
|
42
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
|
|
43
|
|
|
} elseif ($this->wrappedObject->target instanceof Project) { |
|
44
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the moment action summary. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function actionName() |
|
54
|
|
|
{ |
|
55
|
|
|
switch ($this->wrappedObject->action) { |
|
56
|
|
|
case Moment::CREATED: |
|
57
|
|
|
return trans('gitamin.moments.created'); |
|
58
|
|
|
case Moment::UPDATED: |
|
59
|
|
|
return trans('gitamin.moments.updated'); |
|
60
|
|
|
case Moment::CLOSED: |
|
61
|
|
|
return trans('gitamin.moments.closed'); |
|
62
|
|
|
case Moment::COMMENTED: |
|
63
|
|
|
return trans('gitamin.moments.commented'); |
|
64
|
|
|
default: |
|
65
|
|
|
return 'Unknow'; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function icon() |
|
70
|
|
|
{ |
|
71
|
|
|
if ($this->wrappedObject->target instanceof Project) { |
|
72
|
|
|
return 'fa fa-cubes'; |
|
73
|
|
|
} elseif ($this->wrappedObject->target instanceof Comment) { |
|
74
|
|
|
return 'fa fa-comments-o'; |
|
75
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
|
76
|
|
|
return 'fa fa-exclamation-circle'; |
|
77
|
|
|
} else { |
|
78
|
|
|
return 'fa fa-code-fork'; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Present diff for humans date time. |
|
84
|
|
|
* |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public function created_at_diff() |
|
88
|
|
|
{ |
|
89
|
|
|
return (new Date($this->wrappedObject->created_at)) |
|
90
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
|
91
|
|
|
->diffForHumans(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Present formatted date time. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function created_at_formatted() |
|
100
|
|
|
{ |
|
101
|
|
|
return ucfirst((new Date($this->wrappedObject->created_at)) |
|
102
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
|
103
|
|
|
->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s'))); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Present formatted date time. |
|
108
|
|
|
* |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
public function created_at_iso() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Convert presented moment to an array. |
|
118
|
|
|
* |
|
119
|
|
|
* @return array |
|
120
|
|
|
*/ |
|
121
|
|
|
public function toArray() |
|
122
|
|
|
{ |
|
123
|
|
|
return [ |
|
124
|
|
|
'summary' => $this->summary(), |
|
|
|
|
|
|
125
|
|
|
'created_at_iso' => $this->created_at_iso(), |
|
126
|
|
|
]; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
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.