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