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\Models\Comment; |
15
|
|
|
use Gitamin\Models\Issue; |
16
|
|
|
use Gitamin\Models\Moment; |
17
|
|
|
use Gitamin\Models\Owner; |
18
|
|
|
use Gitamin\Models\Project; |
19
|
|
|
use Gitamin\Presenters\Traits\TimestampsTrait; |
20
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
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
|
|
|
} elseif ($this->wrappedObject->target instanceof Project) { |
43
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the moment action summary. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
protected function actionName() |
53
|
|
|
{ |
54
|
|
|
switch ($this->wrappedObject->action) { |
55
|
|
|
case Moment::CREATED: |
56
|
|
|
return trans('gitamin.moments.created'); |
57
|
|
|
case Moment::UPDATED: |
58
|
|
|
return trans('gitamin.moments.updated'); |
59
|
|
|
case Moment::CLOSED: |
60
|
|
|
return trans('gitamin.moments.closed'); |
61
|
|
|
case Moment::COMMENTED: |
62
|
|
|
return trans('gitamin.moments.commented'); |
63
|
|
|
default: |
64
|
|
|
return 'Unknow'; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function icon() |
69
|
|
|
{ |
70
|
|
|
if ($this->wrappedObject->target instanceof Project) { |
71
|
|
|
return 'fa fa-cubes'; |
72
|
|
|
} elseif ($this->wrappedObject->target instanceof Comment) { |
73
|
|
|
return 'fa fa-comments-o'; |
74
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
75
|
|
|
return 'fa fa-exclamation-circle'; |
76
|
|
|
} elseif ($this->wrappedObject->target instanceof Owner) { |
77
|
|
|
return 'fa fa-user'; |
78
|
|
|
} else { |
79
|
|
|
return 'fa fa-code-fork'; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Convert presented moment to an array. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function toArray() |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
'summary' => $this->summary(), |
|
|
|
|
92
|
|
|
'created_at_iso' => $this->created_at_iso(), |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.