1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | * @copyright 2016 Mautic Contributors. All rights reserved |
||||
5 | * @author Mautic |
||||
6 | * |
||||
7 | * @link http://mautic.org |
||||
8 | * |
||||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||||
10 | */ |
||||
11 | |||||
12 | namespace Mautic\NotificationBundle\Controller; |
||||
13 | |||||
14 | use Mautic\CoreBundle\Controller\AbstractFormController; |
||||
15 | use Mautic\CoreBundle\Form\Type\DateRangeType; |
||||
16 | use Mautic\CoreBundle\Helper\InputHelper; |
||||
17 | use Mautic\LeadBundle\Controller\EntityContactsTrait; |
||||
18 | use Mautic\NotificationBundle\Entity\Notification; |
||||
19 | use Symfony\Component\HttpFoundation\JsonResponse; |
||||
20 | use Symfony\Component\HttpFoundation\Response; |
||||
21 | |||||
22 | class NotificationController extends AbstractFormController |
||||
23 | { |
||||
24 | use EntityContactsTrait; |
||||
25 | |||||
26 | /** |
||||
27 | * @param int $page |
||||
28 | * |
||||
29 | * @return JsonResponse|\Symfony\Component\HttpFoundation\Response |
||||
30 | */ |
||||
31 | public function indexAction($page = 1) |
||||
32 | { |
||||
33 | /** @var \Mautic\NotificationBundle\Model\NotificationModel $model */ |
||||
34 | $model = $this->getModel('notification'); |
||||
35 | |||||
36 | //set some permissions |
||||
37 | $permissions = $this->get('mautic.security')->isGranted( |
||||
38 | [ |
||||
39 | 'notification:notifications:viewown', |
||||
40 | 'notification:notifications:viewother', |
||||
41 | 'notification:notifications:create', |
||||
42 | 'notification:notifications:editown', |
||||
43 | 'notification:notifications:editother', |
||||
44 | 'notification:notifications:deleteown', |
||||
45 | 'notification:notifications:deleteother', |
||||
46 | 'notification:notifications:publishown', |
||||
47 | 'notification:notifications:publishother', |
||||
48 | ], |
||||
49 | 'RETURN_ARRAY' |
||||
50 | ); |
||||
51 | |||||
52 | if (!$permissions['notification:notifications:viewown'] && !$permissions['notification:notifications:viewother']) { |
||||
53 | return $this->accessDenied(); |
||||
54 | } |
||||
55 | |||||
56 | if ('POST' == $this->request->getMethod()) { |
||||
57 | $this->setListFilters(); |
||||
58 | } |
||||
59 | |||||
60 | $session = $this->get('session'); |
||||
61 | |||||
62 | //set limits |
||||
63 | $limit = $session->get('mautic.notification.limit', $this->coreParametersHelper->get('default_pagelimit')); |
||||
64 | $start = (1 === $page) ? 0 : (($page - 1) * $limit); |
||||
65 | if ($start < 0) { |
||||
66 | $start = 0; |
||||
67 | } |
||||
68 | |||||
69 | $search = $this->request->get('search', $session->get('mautic.notification.filter', '')); |
||||
70 | $session->set('mautic.notification.filter', $search); |
||||
71 | |||||
72 | $filter = [ |
||||
73 | 'string' => $search, |
||||
74 | 'where' => [ |
||||
75 | [ |
||||
76 | 'expr' => 'eq', |
||||
77 | 'col' => 'mobile', |
||||
78 | 'val' => 0, |
||||
79 | ], |
||||
80 | ], |
||||
81 | ]; |
||||
82 | |||||
83 | if (!$permissions['notification:notifications:viewother']) { |
||||
84 | $filter['force'][] = |
||||
85 | ['column' => 'e.createdBy', 'expr' => 'eq', 'value' => $this->user->getId()]; |
||||
86 | } |
||||
87 | |||||
88 | $orderBy = $session->get('mautic.notification.orderby', 'e.name'); |
||||
89 | $orderByDir = $session->get('mautic.notification.orderbydir', 'DESC'); |
||||
90 | |||||
91 | $notifications = $model->getEntities( |
||||
92 | [ |
||||
93 | 'start' => $start, |
||||
94 | 'limit' => $limit, |
||||
95 | 'filter' => $filter, |
||||
96 | 'orderBy' => $orderBy, |
||||
97 | 'orderByDir' => $orderByDir, |
||||
98 | ] |
||||
99 | ); |
||||
100 | |||||
101 | $count = count($notifications); |
||||
102 | if ($count && $count < ($start + 1)) { |
||||
103 | //the number of entities are now less then the current page so redirect to the last page |
||||
104 | if (1 === $count) { |
||||
105 | $lastPage = 1; |
||||
106 | } else { |
||||
107 | $lastPage = (floor($count / $limit)) ?: 1; |
||||
108 | } |
||||
109 | |||||
110 | $session->set('mautic.notification.page', $lastPage); |
||||
111 | $returnUrl = $this->generateUrl('mautic_notification_index', ['page' => $lastPage]); |
||||
112 | |||||
113 | return $this->postActionRedirect( |
||||
114 | [ |
||||
115 | 'returnUrl' => $returnUrl, |
||||
116 | 'viewParameters' => ['page' => $lastPage], |
||||
117 | 'contentTemplate' => 'MauticNotificationBundle:Notification:index', |
||||
118 | 'passthroughVars' => [ |
||||
119 | 'activeLink' => '#mautic_notification_index', |
||||
120 | 'mauticContent' => 'notification', |
||||
121 | ], |
||||
122 | ] |
||||
123 | ); |
||||
124 | } |
||||
125 | $session->set('mautic.notification.page', $page); |
||||
126 | |||||
127 | return $this->delegateView( |
||||
128 | [ |
||||
129 | 'viewParameters' => [ |
||||
130 | 'searchValue' => $search, |
||||
131 | 'items' => $notifications, |
||||
132 | 'totalItems' => $count, |
||||
133 | 'page' => $page, |
||||
134 | 'limit' => $limit, |
||||
135 | 'tmpl' => $this->request->get('tmpl', 'index'), |
||||
136 | 'permissions' => $permissions, |
||||
137 | 'model' => $model, |
||||
138 | 'security' => $this->get('mautic.security'), |
||||
139 | ], |
||||
140 | 'contentTemplate' => 'MauticNotificationBundle:Notification:list.html.php', |
||||
141 | 'passthroughVars' => [ |
||||
142 | 'activeLink' => '#mautic_notification_index', |
||||
143 | 'mauticContent' => 'notification', |
||||
144 | 'route' => $this->generateUrl('mautic_notification_index', ['page' => $page]), |
||||
145 | ], |
||||
146 | ] |
||||
147 | ); |
||||
148 | } |
||||
149 | |||||
150 | /** |
||||
151 | * Loads a specific form into the detailed panel. |
||||
152 | * |
||||
153 | * @param $objectId |
||||
154 | * |
||||
155 | * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response |
||||
156 | */ |
||||
157 | public function viewAction($objectId) |
||||
158 | { |
||||
159 | /** @var \Mautic\NotificationBundle\Model\NotificationModel $model */ |
||||
160 | $model = $this->getModel('notification'); |
||||
161 | $security = $this->get('mautic.security'); |
||||
162 | |||||
163 | /** @var \Mautic\NotificationBundle\Entity\Notification $notification */ |
||||
164 | $notification = $model->getEntity($objectId); |
||||
165 | //set the page we came from |
||||
166 | $page = $this->get('session')->get('mautic.notification.page', 1); |
||||
167 | |||||
168 | if (null === $notification) { |
||||
169 | //set the return URL |
||||
170 | $returnUrl = $this->generateUrl('mautic_notification_index', ['page' => $page]); |
||||
171 | |||||
172 | return $this->postActionRedirect( |
||||
173 | [ |
||||
174 | 'returnUrl' => $returnUrl, |
||||
175 | 'viewParameters' => ['page' => $page], |
||||
176 | 'contentTemplate' => 'MauticNotificationBundle:Notification:index', |
||||
177 | 'passthroughVars' => [ |
||||
178 | 'activeLink' => '#mautic_notification_index', |
||||
179 | 'mauticContent' => 'notification', |
||||
180 | ], |
||||
181 | 'flashes' => [ |
||||
182 | [ |
||||
183 | 'type' => 'error', |
||||
184 | 'msg' => 'mautic.notification.error.notfound', |
||||
185 | 'msgVars' => ['%id%' => $objectId], |
||||
186 | ], |
||||
187 | ], |
||||
188 | ] |
||||
189 | ); |
||||
190 | } elseif (!$this->get('mautic.security')->hasEntityAccess( |
||||
191 | 'notification:notifications:viewown', |
||||
192 | 'notification:notifications:viewother', |
||||
193 | $notification->getCreatedBy() |
||||
194 | ) |
||||
195 | ) { |
||||
196 | return $this->accessDenied(); |
||||
197 | } |
||||
198 | |||||
199 | // Audit Log |
||||
200 | $logs = $this->getModel('core.auditlog')->getLogForObject('notification', $notification->getId(), $notification->getDateAdded()); |
||||
201 | |||||
202 | // Init the date range filter form |
||||
203 | $dateRangeValues = $this->request->get('daterange', []); |
||||
204 | $action = $this->generateUrl('mautic_notification_action', ['objectAction' => 'view', 'objectId' => $objectId]); |
||||
205 | $dateRangeForm = $this->get('form.factory')->create(DateRangeType::class, $dateRangeValues, ['action' => $action]); |
||||
206 | $entityViews = $model->getHitsLineChartData( |
||||
207 | null, |
||||
208 | new \DateTime($dateRangeForm->get('date_from')->getData()), |
||||
209 | new \DateTime($dateRangeForm->get('date_to')->getData()), |
||||
210 | null, |
||||
211 | ['notification_id' => $notification->getId()] |
||||
212 | ); |
||||
213 | |||||
214 | // Get click through stats |
||||
215 | $trackableLinks = $model->getNotificationClickStats($notification->getId()); |
||||
216 | |||||
217 | return $this->delegateView([ |
||||
218 | 'returnUrl' => $this->generateUrl('mautic_notification_action', ['objectAction' => 'view', 'objectId' => $notification->getId()]), |
||||
219 | 'viewParameters' => [ |
||||
220 | 'notification' => $notification, |
||||
221 | 'trackables' => $trackableLinks, |
||||
222 | 'logs' => $logs, |
||||
223 | 'permissions' => $security->isGranted([ |
||||
224 | 'notification:notifications:viewown', |
||||
225 | 'notification:notifications:viewother', |
||||
226 | 'notification:notifications:create', |
||||
227 | 'notification:notifications:editown', |
||||
228 | 'notification:notifications:editother', |
||||
229 | 'notification:notifications:deleteown', |
||||
230 | 'notification:notifications:deleteother', |
||||
231 | 'notification:notifications:publishown', |
||||
232 | 'notification:notifications:publishother', |
||||
233 | ], 'RETURN_ARRAY'), |
||||
234 | 'security' => $security, |
||||
235 | 'entityViews' => $entityViews, |
||||
236 | 'contacts' => $this->forward( |
||||
237 | 'MauticNotificationBundle:Notification:contacts', |
||||
238 | [ |
||||
239 | 'objectId' => $notification->getId(), |
||||
240 | 'page' => $this->get('session')->get('mautic.notification.contact.page', 1), |
||||
241 | 'ignoreAjax' => true, |
||||
242 | ] |
||||
243 | )->getContent(), |
||||
244 | 'dateRangeForm' => $dateRangeForm->createView(), |
||||
245 | ], |
||||
246 | 'contentTemplate' => 'MauticNotificationBundle:Notification:details.html.php', |
||||
247 | 'passthroughVars' => [ |
||||
248 | 'activeLink' => '#mautic_notification_index', |
||||
249 | 'mauticContent' => 'notification', |
||||
250 | ], |
||||
251 | ]); |
||||
252 | } |
||||
253 | |||||
254 | /** |
||||
255 | * Generates new form and processes post data. |
||||
256 | * |
||||
257 | * @param Notification $entity |
||||
258 | * |
||||
259 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
||||
260 | */ |
||||
261 | public function newAction($entity = null) |
||||
262 | { |
||||
263 | /** @var \Mautic\NotificationBundle\Model\NotificationModel $model */ |
||||
264 | $model = $this->getModel('notification'); |
||||
265 | |||||
266 | if (!$entity instanceof Notification) { |
||||
267 | /** @var \Mautic\NotificationBundle\Entity\Notification $entity */ |
||||
268 | $entity = $model->getEntity(); |
||||
269 | } |
||||
270 | |||||
271 | $method = $this->request->getMethod(); |
||||
272 | $session = $this->get('session'); |
||||
273 | |||||
274 | if (!$this->get('mautic.security')->isGranted('notification:notifications:create')) { |
||||
275 | return $this->accessDenied(); |
||||
276 | } |
||||
277 | |||||
278 | //set the page we came from |
||||
279 | $page = $session->get('mautic.notification.page', 1); |
||||
280 | $action = $this->generateUrl('mautic_notification_action', ['objectAction' => 'new']); |
||||
281 | $notification = $this->request->request->get('notification', []); |
||||
282 | $updateSelect = ('POST' == $method) |
||||
283 | ? ($notification['updateSelect'] ?? false) |
||||
284 | : $this->request->get('updateSelect', false); |
||||
285 | |||||
286 | if ($updateSelect) { |
||||
287 | $entity->setNotificationType('template'); |
||||
288 | } |
||||
289 | |||||
290 | //create the form |
||||
291 | $form = $model->createForm($entity, $this->get('form.factory'), $action, ['update_select' => $updateSelect]); |
||||
292 | |||||
293 | ///Check for a submitted form and process it |
||||
294 | if ('POST' === $method) { |
||||
295 | $valid = false; |
||||
296 | if (!$cancelled = $this->isFormCancelled($form)) { |
||||
297 | if ($valid = $this->isFormValid($form)) { |
||||
298 | //form is valid so process the data |
||||
299 | $model->saveEntity($entity); |
||||
300 | |||||
301 | $this->addFlash( |
||||
0 ignored issues
–
show
|
|||||
302 | 'mautic.core.notice.created', |
||||
303 | [ |
||||
304 | '%name%' => $entity->getName(), |
||||
305 | '%menu_link%' => 'mautic_notification_index', |
||||
306 | '%url%' => $this->generateUrl( |
||||
307 | 'mautic_notification_action', |
||||
308 | [ |
||||
309 | 'objectAction' => 'edit', |
||||
310 | 'objectId' => $entity->getId(), |
||||
311 | ] |
||||
312 | ), |
||||
313 | ] |
||||
314 | ); |
||||
315 | |||||
316 | if ($form->get('buttons')->get('save')->isClicked()) { |
||||
317 | $viewParameters = [ |
||||
318 | 'objectAction' => 'view', |
||||
319 | 'objectId' => $entity->getId(), |
||||
320 | ]; |
||||
321 | $returnUrl = $this->generateUrl('mautic_notification_action', $viewParameters); |
||||
322 | $template = 'MauticNotificationBundle:Notification:view'; |
||||
323 | } else { |
||||
324 | //return edit view so that all the session stuff is loaded |
||||
325 | return $this->editAction($entity->getId(), true); |
||||
326 | } |
||||
327 | } |
||||
328 | } else { |
||||
329 | $viewParameters = ['page' => $page]; |
||||
330 | $returnUrl = $this->generateUrl('mautic_notification_index', $viewParameters); |
||||
331 | $template = 'MauticNotificationBundle:Notification:index'; |
||||
332 | //clear any modified content |
||||
333 | $session->remove('mautic.notification.'.$entity->getId().'.content'); |
||||
334 | } |
||||
335 | |||||
336 | $passthrough = [ |
||||
337 | 'activeLink' => 'mautic_notification_index', |
||||
338 | 'mauticContent' => 'notification', |
||||
339 | ]; |
||||
340 | |||||
341 | // Check to see if this is a popup |
||||
342 | if (isset($form['updateSelect'])) { |
||||
343 | $template = false; |
||||
344 | $passthrough = array_merge( |
||||
345 | $passthrough, |
||||
346 | [ |
||||
347 | 'updateSelect' => $form['updateSelect']->getData(), |
||||
348 | 'id' => $entity->getId(), |
||||
349 | 'name' => $entity->getName(), |
||||
350 | 'group' => $entity->getLanguage(), |
||||
351 | ] |
||||
352 | ); |
||||
353 | } |
||||
354 | |||||
355 | if ($cancelled || ($valid && $form->get('buttons')->get('save')->isClicked())) { |
||||
356 | return $this->postActionRedirect( |
||||
357 | [ |
||||
358 | 'returnUrl' => $returnUrl, |
||||
359 | 'viewParameters' => $viewParameters, |
||||
360 | 'contentTemplate' => $template, |
||||
361 | 'passthroughVars' => $passthrough, |
||||
362 | ] |
||||
363 | ); |
||||
364 | } |
||||
365 | } |
||||
366 | |||||
367 | return $this->delegateView( |
||||
368 | [ |
||||
369 | 'viewParameters' => [ |
||||
370 | 'form' => $this->setFormTheme($form, 'MauticNotificationBundle:Notification:form.html.php', 'MauticNotificationBundle:FormTheme\Notification'), |
||||
371 | 'notification' => $entity, |
||||
372 | ], |
||||
373 | 'contentTemplate' => 'MauticNotificationBundle:Notification:form.html.php', |
||||
374 | 'passthroughVars' => [ |
||||
375 | 'activeLink' => '#mautic_notification_index', |
||||
376 | 'mauticContent' => 'notification', |
||||
377 | 'updateSelect' => InputHelper::clean($this->request->query->get('updateSelect')), |
||||
378 | 'route' => $this->generateUrl( |
||||
379 | 'mautic_notification_action', |
||||
380 | [ |
||||
381 | 'objectAction' => 'new', |
||||
382 | ] |
||||
383 | ), |
||||
384 | ], |
||||
385 | ] |
||||
386 | ); |
||||
387 | } |
||||
388 | |||||
389 | /** |
||||
390 | * @param $objectId |
||||
391 | * @param bool $ignorePost |
||||
392 | * @param bool $forceTypeSelection |
||||
393 | * |
||||
394 | * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response |
||||
395 | */ |
||||
396 | public function editAction($objectId, $ignorePost = false, $forceTypeSelection = false) |
||||
397 | { |
||||
398 | /** @var \Mautic\NotificationBundle\Model\NotificationModel $model */ |
||||
399 | $model = $this->getModel('notification'); |
||||
400 | $method = $this->request->getMethod(); |
||||
401 | $entity = $model->getEntity($objectId); |
||||
402 | $session = $this->get('session'); |
||||
403 | $page = $session->get('mautic.notification.page', 1); |
||||
404 | |||||
405 | //set the return URL |
||||
406 | $returnUrl = $this->generateUrl('mautic_notification_index', ['page' => $page]); |
||||
407 | |||||
408 | $postActionVars = [ |
||||
409 | 'returnUrl' => $returnUrl, |
||||
410 | 'viewParameters' => ['page' => $page], |
||||
411 | 'contentTemplate' => 'MauticNotificationBundle:Notification:index', |
||||
412 | 'passthroughVars' => [ |
||||
413 | 'activeLink' => 'mautic_notification_index', |
||||
414 | 'mauticContent' => 'notification', |
||||
415 | ], |
||||
416 | ]; |
||||
417 | |||||
418 | //not found |
||||
419 | if (null === $entity) { |
||||
420 | return $this->postActionRedirect( |
||||
421 | array_merge( |
||||
422 | $postActionVars, |
||||
423 | [ |
||||
424 | 'flashes' => [ |
||||
425 | [ |
||||
426 | 'type' => 'error', |
||||
427 | 'msg' => 'mautic.notification.error.notfound', |
||||
428 | 'msgVars' => ['%id%' => $objectId], |
||||
429 | ], |
||||
430 | ], |
||||
431 | ] |
||||
432 | ) |
||||
433 | ); |
||||
434 | } elseif (!$this->get('mautic.security')->hasEntityAccess( |
||||
435 | 'notification:notifications:viewown', |
||||
436 | 'notification:notifications:viewother', |
||||
437 | $entity->getCreatedBy() |
||||
438 | ) |
||||
439 | ) { |
||||
440 | return $this->accessDenied(); |
||||
441 | } elseif ($model->isLocked($entity)) { |
||||
442 | //deny access if the entity is locked |
||||
443 | return $this->isLocked($postActionVars, $entity, 'notification'); |
||||
444 | } |
||||
445 | |||||
446 | //Create the form |
||||
447 | $action = $this->generateUrl('mautic_notification_action', ['objectAction' => 'edit', 'objectId' => $objectId]); |
||||
448 | $notification = $this->request->request->get('notification', []); |
||||
449 | $updateSelect = 'POST' === $method |
||||
450 | ? ($notification['updateSelect'] ?? false) |
||||
451 | : $this->request->get('updateSelect', false); |
||||
452 | |||||
453 | $form = $model->createForm($entity, $this->get('form.factory'), $action, ['update_select' => $updateSelect]); |
||||
454 | |||||
455 | ///Check for a submitted form and process it |
||||
456 | if (!$ignorePost && 'POST' === $method) { |
||||
457 | $valid = false; |
||||
458 | |||||
459 | if (!$cancelled = $this->isFormCancelled($form)) { |
||||
460 | if ($valid = $this->isFormValid($form)) { |
||||
461 | //form is valid so process the data |
||||
462 | $model->saveEntity($entity, $form->get('buttons')->get('save')->isClicked()); |
||||
463 | |||||
464 | $this->addFlash( |
||||
0 ignored issues
–
show
The function
Mautic\CoreBundle\Contro...nController::addFlash() has been deprecated: Will be removed in Mautic 3.0. Use CommonController::flashBag->addFlash() instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
465 | 'mautic.core.notice.updated', |
||||
466 | [ |
||||
467 | '%name%' => $entity->getName(), |
||||
468 | '%menu_link%' => 'mautic_notification_index', |
||||
469 | '%url%' => $this->generateUrl( |
||||
470 | 'mautic_notification_action', |
||||
471 | [ |
||||
472 | 'objectAction' => 'edit', |
||||
473 | 'objectId' => $entity->getId(), |
||||
474 | ] |
||||
475 | ), |
||||
476 | ], |
||||
477 | 'warning' |
||||
478 | ); |
||||
479 | } |
||||
480 | } else { |
||||
481 | //clear any modified content |
||||
482 | $session->remove('mautic.notification.'.$objectId.'.content'); |
||||
483 | //unlock the entity |
||||
484 | $model->unlockEntity($entity); |
||||
485 | } |
||||
486 | |||||
487 | $template = 'MauticNotificationBundle:Notification:view'; |
||||
488 | $passthrough = [ |
||||
489 | 'activeLink' => 'mautic_notification_index', |
||||
490 | 'mauticContent' => 'notification', |
||||
491 | ]; |
||||
492 | |||||
493 | // Check to see if this is a popup |
||||
494 | if (isset($form['updateSelect'])) { |
||||
495 | $template = false; |
||||
496 | $passthrough = array_merge( |
||||
497 | $passthrough, |
||||
498 | [ |
||||
499 | 'updateSelect' => $form['updateSelect']->getData(), |
||||
500 | 'id' => $entity->getId(), |
||||
501 | 'name' => $entity->getName(), |
||||
502 | 'group' => $entity->getLanguage(), |
||||
503 | ] |
||||
504 | ); |
||||
505 | } |
||||
506 | |||||
507 | if ($cancelled || ($valid && $form->get('buttons')->get('save')->isClicked())) { |
||||
508 | $viewParameters = [ |
||||
509 | 'objectAction' => 'view', |
||||
510 | 'objectId' => $entity->getId(), |
||||
511 | ]; |
||||
512 | |||||
513 | return $this->postActionRedirect( |
||||
514 | array_merge( |
||||
515 | $postActionVars, |
||||
516 | [ |
||||
517 | 'returnUrl' => $this->generateUrl('mautic_notification_action', $viewParameters), |
||||
518 | 'viewParameters' => $viewParameters, |
||||
519 | 'contentTemplate' => $template, |
||||
520 | 'passthroughVars' => $passthrough, |
||||
521 | ] |
||||
522 | ) |
||||
523 | ); |
||||
524 | } |
||||
525 | } else { |
||||
526 | //lock the entity |
||||
527 | $model->lockEntity($entity); |
||||
528 | } |
||||
529 | |||||
530 | return $this->delegateView( |
||||
531 | [ |
||||
532 | 'viewParameters' => [ |
||||
533 | 'form' => $this->setFormTheme($form, 'MauticNotificationBundle:Notification:form.html.php', 'MauticNotificationBundle:FormTheme\Notification'), |
||||
534 | 'notification' => $entity, |
||||
535 | 'forceTypeSelection' => $forceTypeSelection, |
||||
536 | ], |
||||
537 | 'contentTemplate' => 'MauticNotificationBundle:Notification:form.html.php', |
||||
538 | 'passthroughVars' => [ |
||||
539 | 'activeLink' => '#mautic_notification_index', |
||||
540 | 'mauticContent' => 'notification', |
||||
541 | 'updateSelect' => InputHelper::clean($this->request->query->get('updateSelect')), |
||||
542 | 'route' => $this->generateUrl( |
||||
543 | 'mautic_notification_action', |
||||
544 | [ |
||||
545 | 'objectAction' => 'edit', |
||||
546 | 'objectId' => $entity->getId(), |
||||
547 | ] |
||||
548 | ), |
||||
549 | ], |
||||
550 | ] |
||||
551 | ); |
||||
552 | } |
||||
553 | |||||
554 | /** |
||||
555 | * Clone an entity. |
||||
556 | * |
||||
557 | * @param $objectId |
||||
558 | * |
||||
559 | * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response |
||||
560 | */ |
||||
561 | public function cloneAction($objectId) |
||||
562 | { |
||||
563 | $model = $this->getModel('notification'); |
||||
564 | $entity = $model->getEntity($objectId); |
||||
565 | |||||
566 | if (null != $entity) { |
||||
567 | if (!$this->get('mautic.security')->isGranted('notification:notifications:create') |
||||
568 | || !$this->get('mautic.security')->hasEntityAccess( |
||||
569 | 'notification:notifications:viewown', |
||||
570 | 'notification:notifications:viewother', |
||||
571 | $entity->getCreatedBy() |
||||
572 | ) |
||||
573 | ) { |
||||
574 | return $this->accessDenied(); |
||||
575 | } |
||||
576 | |||||
577 | $entity = clone $entity; |
||||
578 | $session = $this->get('session'); |
||||
579 | $contentName = 'mautic.notification.'.$entity->getId().'.content'; |
||||
580 | |||||
581 | $session->set($contentName, $entity->getContent()); |
||||
582 | } |
||||
583 | |||||
584 | return $this->newAction($entity); |
||||
585 | } |
||||
586 | |||||
587 | /** |
||||
588 | * Deletes the entity. |
||||
589 | * |
||||
590 | * @param $objectId |
||||
591 | * |
||||
592 | * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
||||
593 | */ |
||||
594 | public function deleteAction($objectId) |
||||
595 | { |
||||
596 | $page = $this->get('session')->get('mautic.notification.page', 1); |
||||
597 | $returnUrl = $this->generateUrl('mautic_notification_index', ['page' => $page]); |
||||
598 | $flashes = []; |
||||
599 | |||||
600 | $postActionVars = [ |
||||
601 | 'returnUrl' => $returnUrl, |
||||
602 | 'viewParameters' => ['page' => $page], |
||||
603 | 'contentTemplate' => 'MauticNotificationBundle:Notification:index', |
||||
604 | 'passthroughVars' => [ |
||||
605 | 'activeLink' => 'mautic_notification_index', |
||||
606 | 'mauticContent' => 'notification', |
||||
607 | ], |
||||
608 | ]; |
||||
609 | |||||
610 | if ('POST' == $this->request->getMethod()) { |
||||
611 | $model = $this->getModel('notification'); |
||||
612 | $entity = $model->getEntity($objectId); |
||||
613 | |||||
614 | if (null === $entity) { |
||||
615 | $flashes[] = [ |
||||
616 | 'type' => 'error', |
||||
617 | 'msg' => 'mautic.notification.error.notfound', |
||||
618 | 'msgVars' => ['%id%' => $objectId], |
||||
619 | ]; |
||||
620 | } elseif (!$this->get('mautic.security')->hasEntityAccess( |
||||
621 | 'notification:notifications:deleteown', |
||||
622 | 'notification:notifications:deleteother', |
||||
623 | $entity->getCreatedBy() |
||||
624 | ) |
||||
625 | ) { |
||||
626 | return $this->accessDenied(); |
||||
627 | } elseif ($model->isLocked($entity)) { |
||||
628 | return $this->isLocked($postActionVars, $entity, 'notification'); |
||||
629 | } |
||||
630 | |||||
631 | $model->deleteEntity($entity); |
||||
632 | |||||
633 | $flashes[] = [ |
||||
634 | 'type' => 'notice', |
||||
635 | 'msg' => 'mautic.core.notice.deleted', |
||||
636 | 'msgVars' => [ |
||||
637 | '%name%' => $entity->getName(), |
||||
638 | '%id%' => $objectId, |
||||
639 | ], |
||||
640 | ]; |
||||
641 | } //else don't do anything |
||||
642 | |||||
643 | return $this->postActionRedirect( |
||||
644 | array_merge( |
||||
645 | $postActionVars, |
||||
646 | [ |
||||
647 | 'flashes' => $flashes, |
||||
648 | ] |
||||
649 | ) |
||||
650 | ); |
||||
651 | } |
||||
652 | |||||
653 | /** |
||||
654 | * Deletes a group of entities. |
||||
655 | * |
||||
656 | * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
||||
657 | */ |
||||
658 | public function batchDeleteAction() |
||||
659 | { |
||||
660 | $page = $this->get('session')->get('mautic.notification.page', 1); |
||||
661 | $returnUrl = $this->generateUrl('mautic_notification_index', ['page' => $page]); |
||||
662 | $flashes = []; |
||||
663 | |||||
664 | $postActionVars = [ |
||||
665 | 'returnUrl' => $returnUrl, |
||||
666 | 'viewParameters' => ['page' => $page], |
||||
667 | 'contentTemplate' => 'MauticNotificationBundle:Notification:index', |
||||
668 | 'passthroughVars' => [ |
||||
669 | 'activeLink' => '#mautic_notification_index', |
||||
670 | 'mauticContent' => 'notification', |
||||
671 | ], |
||||
672 | ]; |
||||
673 | |||||
674 | if ('POST' == $this->request->getMethod()) { |
||||
675 | $model = $this->getModel('notification'); |
||||
676 | $ids = json_decode($this->request->query->get('ids', '{}')); |
||||
677 | |||||
678 | $deleteIds = []; |
||||
679 | |||||
680 | // Loop over the IDs to perform access checks pre-delete |
||||
681 | foreach ($ids as $objectId) { |
||||
682 | $entity = $model->getEntity($objectId); |
||||
683 | |||||
684 | if (null === $entity) { |
||||
685 | $flashes[] = [ |
||||
686 | 'type' => 'error', |
||||
687 | 'msg' => 'mautic.notification.error.notfound', |
||||
688 | 'msgVars' => ['%id%' => $objectId], |
||||
689 | ]; |
||||
690 | } elseif (!$this->get('mautic.security')->hasEntityAccess( |
||||
691 | 'notification:notifications:viewown', |
||||
692 | 'notification:notifications:viewother', |
||||
693 | $entity->getCreatedBy() |
||||
694 | ) |
||||
695 | ) { |
||||
696 | $flashes[] = $this->accessDenied(true); |
||||
697 | } elseif ($model->isLocked($entity)) { |
||||
698 | $flashes[] = $this->isLocked($postActionVars, $entity, 'notification', true); |
||||
699 | } else { |
||||
700 | $deleteIds[] = $objectId; |
||||
701 | } |
||||
702 | } |
||||
703 | |||||
704 | // Delete everything we are able to |
||||
705 | if (!empty($deleteIds)) { |
||||
706 | $entities = $model->deleteEntities($deleteIds); |
||||
707 | |||||
708 | $flashes[] = [ |
||||
709 | 'type' => 'notice', |
||||
710 | 'msg' => 'mautic.notification.notice.batch_deleted', |
||||
711 | 'msgVars' => [ |
||||
712 | '%count%' => count($entities), |
||||
713 | ], |
||||
714 | ]; |
||||
715 | } |
||||
716 | } //else don't do anything |
||||
717 | |||||
718 | return $this->postActionRedirect( |
||||
719 | array_merge( |
||||
720 | $postActionVars, |
||||
721 | [ |
||||
722 | 'flashes' => $flashes, |
||||
723 | ] |
||||
724 | ) |
||||
725 | ); |
||||
726 | } |
||||
727 | |||||
728 | /** |
||||
729 | * @param $objectId |
||||
730 | * |
||||
731 | * @return JsonResponse|Response |
||||
732 | */ |
||||
733 | public function previewAction($objectId) |
||||
734 | { |
||||
735 | /** @var \Mautic\NotificationBundle\Model\NotificationModel $model */ |
||||
736 | $model = $this->getModel('notification'); |
||||
737 | $notification = $model->getEntity($objectId); |
||||
738 | |||||
739 | if (null != $notification |
||||
740 | && $this->get('mautic.security')->hasEntityAccess( |
||||
741 | 'notification:notifications:editown', |
||||
742 | 'notification:notifications:editother' |
||||
743 | ) |
||||
744 | ) { |
||||
745 | } |
||||
746 | |||||
747 | return $this->delegateView( |
||||
748 | [ |
||||
749 | 'viewParameters' => [ |
||||
750 | 'notification' => $notification, |
||||
751 | ], |
||||
752 | 'contentTemplate' => 'MauticNotificationBundle:Notification:preview.html.php', |
||||
753 | ] |
||||
754 | ); |
||||
755 | } |
||||
756 | |||||
757 | /** |
||||
758 | * @param $objectId |
||||
759 | * @param int $page |
||||
760 | * |
||||
761 | * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response |
||||
762 | */ |
||||
763 | public function contactsAction($objectId, $page = 1) |
||||
764 | { |
||||
765 | return $this->generateContactsGrid( |
||||
766 | $objectId, |
||||
767 | $page, |
||||
768 | 'notification:notifications:view', |
||||
769 | 'notification', |
||||
770 | 'push_notification_stats', |
||||
771 | 'notification', |
||||
772 | 'notification_id' |
||||
773 | ); |
||||
774 | } |
||||
775 | } |
||||
776 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.