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 formatted date time. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function created_at_iso() |
88
|
|
|
{ |
89
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Convert presented moment to an array. |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function toArray() |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
|
|
'summary' => $this->summary(), |
|
|
|
|
101
|
|
|
'created_at_iso' => $this->created_at_iso(), |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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@property
annotation 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.