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\Presenters\Traits\TimestampsTrait; |
16
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
17
|
|
|
use Jenssegers\Date\Date; |
18
|
|
|
|
19
|
|
|
class IssuePresenter extends AbstractPresenter |
20
|
|
|
{ |
21
|
|
|
use TimestampsTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Renders the message from Markdown into HTML. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function formattedMessage() |
29
|
|
|
{ |
30
|
|
|
return Markdown::convertToHtml($this->wrappedObject->description); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Present diff for humans date time. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function created_at_diff() |
39
|
|
|
{ |
40
|
|
|
return (new Date($this->wrappedObject->created_at)) |
41
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
42
|
|
|
->diffForHumans(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Present formatted date time. |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function created_at_formatted() |
51
|
|
|
{ |
52
|
|
|
return ucfirst((new Date($this->wrappedObject->created_at)) |
53
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
54
|
|
|
->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s'))); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Formats the created_at time ready to be used by bootstrap-datetimepicker. |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function created_at_datetimepicker() |
63
|
|
|
{ |
64
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Present formatted date time. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function created_at_iso() |
73
|
|
|
{ |
74
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns a formatted timestamp for use within the timeline. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function timestamp_formatted() |
83
|
|
|
{ |
84
|
|
|
return $this->created_at_formatted; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Return the iso timestamp for use within the timeline. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function timestamp_iso() |
93
|
|
|
{ |
94
|
|
|
return $this->created_at_iso; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function test() |
98
|
|
|
{ |
99
|
|
|
|
100
|
|
|
return "test"; |
101
|
|
|
} |
102
|
|
|
/** |
103
|
|
|
* Present the status with an icon. |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function icon() |
108
|
|
|
{ |
109
|
|
|
switch ($this->wrappedObject->state) { |
110
|
|
|
case 0: // Scheduled |
111
|
|
|
return 'fa fa-calendar'; |
112
|
|
|
case 1: // Investigating |
113
|
|
|
return 'fa fa-flag oranges'; |
114
|
|
|
case 2: // Identified |
115
|
|
|
return 'fa fa-warning yellows'; |
116
|
|
|
case 3: // Watching |
117
|
|
|
return 'fa fa-eye blues'; |
118
|
|
|
case 4: // Fixed |
119
|
|
|
return 'fa fa-wrench greens'; |
120
|
|
|
default: // Something actually broke, this shouldn't happen. |
121
|
|
|
return ''; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Convert the presenter instance to an array. |
127
|
|
|
* |
128
|
|
|
* @return string[] |
129
|
|
|
*/ |
130
|
|
|
public function toArray() |
131
|
|
|
{ |
132
|
|
|
return array_merge($this->wrappedObject->toArray(), [ |
133
|
|
|
'created_at' => $this->created_at(), |
134
|
|
|
'updated_at' => $this->updated_at(), |
135
|
|
|
]); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
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.