1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// ------------------------------------------------------------------------- |
4
|
|
|
// OVIDENTIA http://www.ovidentia.org |
5
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
6
|
|
|
// it under the terms of the GNU General Public License as published by |
7
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
8
|
|
|
// any later version. |
9
|
|
|
// |
10
|
|
|
// This program is distributed in the hope that it will be useful, but |
11
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
// See the GNU General Public License for more details. |
14
|
|
|
// |
15
|
|
|
// You should have received a copy of the GNU General Public License |
16
|
|
|
// along with this program; if not, write to the Free Software |
17
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18
|
|
|
// USA. |
19
|
|
|
// ------------------------------------------------------------------------- |
20
|
|
|
/** |
21
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
22
|
|
|
* @copyright Copyright (c) 2022 by SI4YOU ({@link https://www.siforyou.com}) |
23
|
|
|
*/ |
24
|
|
|
namespace Capwelton\LibApp\Ctrl; |
25
|
|
|
|
26
|
|
|
use Capwelton\Widgets\Widgets\Item\WidgetLink; |
|
|
|
|
27
|
|
|
use Capwelton\Widgets\Widgets\Layout\WidgetFlexLayout; |
|
|
|
|
28
|
|
|
use Capwelton\LibApp\Set\AppNotification; |
29
|
|
|
require_once APP_CTRL_PATH . '/record.ctrl.php'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* This controller manages actions that can be performed on notifications |
33
|
|
|
* |
34
|
|
|
* @method Func_App App() |
35
|
|
|
* @method app_NotificationSet getRecordSet() |
36
|
|
|
* @method self proxy() |
37
|
|
|
*/ |
38
|
|
|
class AppCtrlNotification extends AppCtrlRecord |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
public function popup($itemId = null) |
42
|
|
|
{ |
43
|
|
|
$App = $this->App(); |
44
|
|
|
$page = $App->Ui()->Page($itemId); |
45
|
|
|
$page->setTitle($App->translate('Notifications')); |
46
|
|
|
$page->setSizePolicy('testNotification'); |
47
|
|
|
|
48
|
|
|
$W = bab_Widgets(); |
49
|
|
|
|
50
|
|
|
$notificationSet = $App->NotificationSet(); |
51
|
|
|
$notifications = $notificationSet->select($notificationSet->user->is($App->getCurrentUser()) |
52
|
|
|
->_AND_($notificationSet->seen->is(false))) |
53
|
|
|
->orderDesc($notificationSet->createdOn); |
54
|
|
|
|
55
|
|
|
$page->addItem($notifBox = $W->VBoxLayout()); |
56
|
|
|
$page->setReloadAction($this->proxy() |
57
|
|
|
->popup($notifBox->getId())); |
58
|
|
|
$page->addClass(AppNotification::NOTIFICATION_PORTLET_CLASS); |
59
|
|
|
|
60
|
|
|
foreach ($notifications as $notification){ |
61
|
|
|
$notifBox->addItem($W->Link($notification->title, $this->proxy() |
|
|
|
|
62
|
|
|
->display($notification->id)) |
63
|
|
|
->setOpenMode(WidgetLink::OPEN_DIALOG)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $page; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function display($id) |
70
|
|
|
{ |
71
|
|
|
$set = $this->getRecordSet(); |
72
|
|
|
$record = $set->get($id); |
73
|
|
|
if(! $record){ |
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$App = $this->App(); |
78
|
|
|
$Ui = $App->Ui(); |
79
|
|
|
$page = $Ui->Page(); |
80
|
|
|
$page->setTitle($record->title); |
81
|
|
|
|
82
|
|
|
$record->markAsSeen(); |
83
|
|
|
$W = bab_Widgets(); |
84
|
|
|
$box = $W->VBoxItems(); |
85
|
|
|
|
86
|
|
|
$box->addItem($W->Label($record->description)); |
87
|
|
|
|
88
|
|
|
$box->addItem($W->Label(date('d/m/Y H:i', strtotime($record->createdOn)))); |
89
|
|
|
|
90
|
|
|
$page->addItem($box); |
91
|
|
|
|
92
|
|
|
return $page; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function _createDummy() |
96
|
|
|
{ |
97
|
|
|
$App = $this->App(); |
98
|
|
|
$notifSet = $App->NotificationSet(); |
99
|
|
|
$dummy = $notifSet->newRecord(); |
100
|
|
|
|
101
|
|
|
$dummy->title = 'Dummy title'; |
102
|
|
|
$dummy->description = 'Lorem ipsum dolor sit amet, consectetur adisciping elit'; |
103
|
|
|
$dummy->user = bab_getUserId(); |
104
|
|
|
$dummy->save(); |
105
|
|
|
|
106
|
|
|
$dummy->createSSENotification(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function portletView($itemId = null) |
110
|
|
|
{ |
111
|
|
|
$App = $this->App(); |
112
|
|
|
$W = bab_Widgets(); |
113
|
|
|
$notifSet = $App->NotificationSet(); |
114
|
|
|
|
115
|
|
|
$box = $W->FlowItems()->setIconFormat(24, 'center'); |
116
|
|
|
if(isset($itemId)){ |
117
|
|
|
$box->setId($itemId); |
118
|
|
|
} |
119
|
|
|
$notifs = $notifSet->selectUserNotifications(); |
120
|
|
|
$nbNotif = $notifs->count(); |
121
|
|
|
$notifIcon = 'icon '; |
122
|
|
|
$notifClass = 'label label-default'; |
123
|
|
|
$sizePolicy = 'notificationBtn'; |
124
|
|
|
|
125
|
|
|
$box->addItem($btnWidget = $W->FlexItems()) |
|
|
|
|
126
|
|
|
->setIcon(16, 'left'); |
|
|
|
|
127
|
|
|
if($nbNotif > 0){ |
128
|
|
|
$btnWidget->addItem($W->Label($nbNotif) |
129
|
|
|
->addClass('notificationNumber')); |
130
|
|
|
$btnWidget->addClass('notificationDisplayButton'); |
131
|
|
|
$notifIcon .= 'webapp-bell-ringing-o'; |
132
|
|
|
$sizePolicy .= ' hasNotification'; |
133
|
|
|
|
134
|
|
|
$notificationBox = $W->FlexItems($W->Html('') |
135
|
|
|
->addClass('notificationListArrow'), $W->Html('') |
136
|
|
|
->addClass('notificationListArrowInside')) |
137
|
|
|
->setSizePolicy('notificationsList') |
138
|
|
|
->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL); |
139
|
|
|
|
140
|
|
|
$notificationBox->addItems($W->FlexItems($W->Title($App->translate('Notifications'), 3), $W->Link('', $this->proxy() |
141
|
|
|
->personalConfiguration()) |
142
|
|
|
->setOpenMode(WidgetLink::OPEN_DIALOG) |
143
|
|
|
->addClass('icon webapp-gear') |
144
|
|
|
->setTitle($App->translate('Notifications configuration'))) |
145
|
|
|
->addClass('notificationBoxTitle') |
146
|
|
|
->setJustifyContent(WidgetFlexLayout::FLEX_JUSTIFY_CONTENT_SPACE_BETWEEN), $notificationBoxElements = $W->FlexItems() |
147
|
|
|
->addClass('notificationBoxElements') |
148
|
|
|
->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL)); |
149
|
|
|
|
150
|
|
|
foreach ($notifs as $notif){ |
151
|
|
|
$notificationBoxElements->addItem($W->Link($el = $W->FlexItems($W->Label($notif->title) |
152
|
|
|
->addClass('notificationElementTitle'), $W->Label(date('d/m/Y H:i', strtotime($notif->createdOn))) |
153
|
|
|
->addClass('notificationElementDate')) |
154
|
|
|
->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL), $this->proxy() |
|
|
|
|
155
|
|
|
->display($notif->id)) |
156
|
|
|
->addClass('notificationBoxElement') |
157
|
|
|
->setOpenMode(WidgetLink::OPEN_DIALOG)); |
158
|
|
|
if(! empty($notif->description)){ |
159
|
|
|
$desc = $notif->description; |
160
|
|
|
if(strlen($desc) > 40){ |
161
|
|
|
$desc = trim(substr($desc, 0, 40)) . '...'; |
162
|
|
|
} |
163
|
|
|
$el->addItem($W->Label($desc) |
164
|
|
|
->addClass('notificationElementDescription'), 1); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$notificationBoxElements->addItem($W->Label($App->translate('Show more')) |
169
|
|
|
->addClass('notificationElementShowMore')); |
170
|
|
|
|
171
|
|
|
$box->addItem($notificationBox); |
172
|
|
|
} |
173
|
|
|
else{ |
174
|
|
|
$notifIcon .= 'webapp-bell-o'; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$btnWidget->addClass($notifIcon)->addClass($notifClass); |
178
|
|
|
$btnWidget->setSizePolicy($sizePolicy); |
179
|
|
|
|
180
|
|
|
$box->setReloadAction($this->proxy() |
|
|
|
|
181
|
|
|
->portletView($box->getId())); |
182
|
|
|
|
183
|
|
|
$box->addClass(AppNotification::NOTIFICATION_PORTLET_CLASS); |
184
|
|
|
$box->addClass('notificationsBox'); |
185
|
|
|
|
186
|
|
|
return $box; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function personalConfiguration() |
190
|
|
|
{ |
191
|
|
|
$App = $this->App(); |
192
|
|
|
$Ui = $App->Ui(); |
193
|
|
|
|
194
|
|
|
$page = $Ui->Page(); |
195
|
|
|
$page->setTitle($App->translate('Notifications configuration')); |
196
|
|
|
|
197
|
|
|
$markAllAsSeenEditor = $Ui->BasicEditor(); |
198
|
|
|
$markAllAsSeenEditor->isAjax = true; |
199
|
|
|
$markAllAsSeenEditor->setSaveAction($this->proxy() |
200
|
|
|
->markAllAsSeen(), $App->translate('Mark all notification as seen')); |
201
|
|
|
|
202
|
|
|
$page->addItem($markAllAsSeenEditor); |
203
|
|
|
|
204
|
|
|
return $page; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function markAllAsSeen() |
208
|
|
|
{ |
209
|
|
|
$this->requireSaveMethod(); |
210
|
|
|
|
211
|
|
|
$App = $this->App(); |
212
|
|
|
|
213
|
|
|
$notifSet = $App->NotificationSet(); |
214
|
|
|
$notifs = $notifSet->selectUserNotifications(); |
215
|
|
|
foreach ($notifs as $notif){ |
216
|
|
|
$notif->markAsSeen(); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return true; |
220
|
|
|
} |
221
|
|
|
}
|
222
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths