/
StandardListView.php
155 lines (129 loc) · 3.92 KB
/
StandardListView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace Concrete\Core\Notification\View;
use Concrete\Controller\Element\Notification\ListDetails;
use Concrete\Controller\Element\Notification\Menu;
use Concrete\Core\Entity\Notification\Notification;
use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\Url\Url;
use Concrete\Core\User\UserInfo;
use HtmlObject\Element;
use HtmlObject\Link;
abstract class StandardListView implements StandardListViewInterface
{
protected $notification;
public function getNotificationObject()
{
return $this->notification;
}
public function renderIcon()
{
$element = new Element('i');
$element->addClass($this->getIconClass());
return $element;
}
public function renderDetails()
{
$details = new ListDetails($this);
return $details->render();
}
public function renderMenu()
{
$menu = new Menu($this);
return $menu->render();
}
public function __construct(Notification $notification)
{
$this->notification = $notification;
}
public function getShortDescription()
{
return '';
}
/**
* @return UserInfo
*/
public function getInitiatorUserObject()
{
return null;
}
public function getInitiatorComment()
{
return null;
}
public function getMenu()
{
return false;
}
public function getFormAction()
{
return false;
}
protected function getRequestedByElement()
{
return new Element('span', t('Requested By '));
}
public function renderInitiatorCommentDescription()
{
$comment = $this->getInitiatorComment();
if ($comment) {
$commentElement = new Element(
'div',
$comment,
array('class' => 'ccm-block-desktop-waiting-for-me-author-comment')
);
return $commentElement;
}
}
protected function getLinkToUser(UserInfo $user)
{
$app = Facade::getFacadeApplication();
return $app->make('url/manager')->resolve([$user]);
}
public function getDateString()
{
$app = Facade::getFacadeApplication();
$date = $this->notification->getNotificationDate();
$service = $app->make('date');
$user = $this->getInitiatorUserObject();
$timezone = null;
if ($user) {
$timezone = $user->getUserTimezone();
}
if (!$timezone) {
$timezone = $this->notification->getNotificationDateTimeZone();
}
return $service->formatDateTime($date, false, false, $timezone);
}
public function renderInitiatorActionDescription()
{
$wrapper = new Element('div');
$title = new Element(
'span', tc('notificationTitle', '%s. ', $this->getTitle()),
array('class' => 'ccm-block-desktop-waiting-for-me-title')
);
$user = $this->getInitiatorUserObject();
$element = $this->getRequestedByElement();
if (is_object($user)) {
$inner = new Element('span', null, array('class' => 'ccm-block-desktop-waiting-for-me-author'));
$link = new Link($this->getLinkToUser($user), $user->getUserDisplayName());
$element->appendChild($inner);
$inner->appendChild($link);
$dateElement = new Element(
'span',
tc('date', ' on %s', $this->getDateString()),
array('class' => 'ccm-block-desktop-waiting-for-me-date')
);
$element->appendChild($dateElement);
} else {
// No requested by element
$element = new Element(
'span',
$this->getDateString(),
array('class' => 'ccm-block-desktop-waiting-for-me-date')
);
}
$wrapper->appendChild($title);
$wrapper->appendChild($element);
return $wrapper;
}
}