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\Project; |
18
|
|
|
use Gitamin\Presenters\Traits\TimestampsTrait; |
19
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
20
|
|
|
|
21
|
|
|
class MomentPresenter extends AbstractPresenter |
22
|
|
|
{ |
23
|
|
|
use TimestampsTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Renders the message from Markdown into HTML. |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function formattedData() |
31
|
|
|
{ |
32
|
|
|
return Markdown::convertToHtml($this->wrappedObject->data); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function formattedTarget() |
36
|
|
|
{ |
37
|
|
|
if ($this->wrappedObject->target instanceof Comment) { |
38
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->message); |
|
|
|
|
39
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
40
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
41
|
|
|
} elseif ($this->wrappedObject->target instanceof Project) { |
42
|
|
|
return Markdown::convertToHtml($this->wrappedObject->target->description); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the moment action summary. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
protected function actionName() |
52
|
|
|
{ |
53
|
|
|
switch ($this->wrappedObject->action) { |
54
|
|
|
case Moment::CREATED: |
55
|
|
|
return trans('gitamin.moments.created'); |
56
|
|
|
case Moment::UPDATED: |
57
|
|
|
return trans('gitamin.moments.updated'); |
58
|
|
|
case Moment::CLOSED: |
59
|
|
|
return trans('gitamin.moments.closed'); |
60
|
|
|
case Moment::COMMENTED: |
61
|
|
|
return trans('gitamin.moments.commented'); |
62
|
|
|
default: |
63
|
|
|
return 'Unknow'; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function icon() |
68
|
|
|
{ |
69
|
|
|
if ($this->wrappedObject->target instanceof Project) { |
70
|
|
|
return 'fa fa-cubes'; |
71
|
|
|
} elseif ($this->wrappedObject->target instanceof Comment) { |
72
|
|
|
return 'fa fa-comments-o'; |
73
|
|
|
} elseif ($this->wrappedObject->target instanceof Issue) { |
74
|
|
|
return 'fa fa-exclamation-circle'; |
75
|
|
|
} else { |
76
|
|
|
return 'fa fa-code-fork'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Convert presented moment to an array. |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
public function toArray() |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
'summary' => $this->summary(), |
|
|
|
|
89
|
|
|
'created_at_iso' => $this->created_at_iso(), |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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.