-
Notifications
You must be signed in to change notification settings - Fork 18
/
AlertifyController.php
69 lines (61 loc) · 2.29 KB
/
AlertifyController.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
<?php
namespace Troopers\AlertifyBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Alertify controller.
*/
class AlertifyController extends AbstractController
{
/**
* Confirm modal.
*
* @param Request $request An HTTP request.
* @Route("/confirm", name="alertify_confirm", options={"expose"=true})
*
* @return Response
*/
public function confirmAction(Request $request)
{
$confirmCallback = $request->get('confirm_callback');
if ($confirmCallback === '') {
$confirmCallback = null;
}
return $this->render('@TroopersAlertify/confirm.html.twig', [
'title' => $request->get('title'),
'body' => $request->get('body'),
'id' => $request->get('id').rand(1, 100).'-modal',
'cancel_button_class' => $request->get('cancel_button_class', 'btn-cancel'),
'confirm_button_class' => $request->get('confirm_button_class', 'btn-primary'),
'cancel_button_value' => $request->get('cancel_button_value'),
'confirm_button_value' => $request->get('confirm_button_value'),
'modal_class' => $request->get('modal_class'),
'type' => $request->get('type'),
'confirmCallback' => $confirmCallback,
]);
}
/**
* Ajax.
*
* @param Request $request An HTTP request.
* @Route("/ajax", name="alertify_ajax", options={"expose"=true})
*
* @return Response
*/
public function ajaxAction(Request $request)
{
$options = [];
if ($context = $request->request->get('context')) {
$options = $this->container->getParameter('troopers_alertify.contexts.'.$context);
}
foreach ($request->request->all() as $name => $option) {
$options[$name] = $option;
}
if ($request->get('main_type')) {
$this->get('session')->getFlashBag()->add($request->get('main_type'), $options);
}
return $this->render('@TroopersAlertify/ajax.html.twig');
}
}