Completed
Push — master ( 5247c6...b8f763 )
by Craig
10:35 queued 03:41
created

AjaxController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.1 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Controller;
14
15
use Zikula\RoutesModule\Controller\Base\AbstractAjaxController;
16
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
17
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
18
use Symfony\Component\HttpFoundation\Request;
19
use Zikula\Core\Response\Ajax\AjaxResponse;
20
21
/**
22
 * Ajax controller class providing navigation and interaction functionality.
23
 *
24
 * @Route("/ajax")
25
 */
26
class AjaxController extends AbstractAjaxController
27
{
28
    /**
29
     * This is the default function handling the main area called without defining arguments.
30
     *
31
     * @Route("/ajax",
32
     *        methods = {"GET"}
33
     * )
34
     *
35
     * @param Request $request Current request instance
36
     *
37
     * @return mixed Output
38
     *
39
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
40
     */
41
    public function indexAction(Request $request)
42
    {
43
        return parent::indexAction($request);
44
    }
45
46
    /**
47
     * Resort routes.
48
     *
49
     * @param Request $request Current request instance
50
     *
51
     * @return boolean|AjaxResponse The response
52
     */
53
    public function sortAction(Request $request)
54
    {
55
        if (!$this->hasPermission($this->name . '::Ajax', '::', ACCESS_EDIT)) {
56
            return true;
57
        }
58
59
        $objectType = $request->request->getAlnum('ot', 'route');
60
        $sort = $request->request->get('sort', []);
61
62
        $entityManager = $this->get('doctrine.orm.entity_manager');
63
64
        foreach ($sort as $position => $id) {
65
            $id = substr($id, 4);
66
            $object = $entityManager->find($this->name . ':' . ucfirst($objectType) . 'Entity', $id);
67
            $object->setSort($position);
68
            $entityManager->persist($object);
69
        }
70
71
        $entityManager->flush();
72
73
        $this->get('zikula.cache_clearer')->clear('symfony.routing');
74
75
        return new AjaxResponse([]);
76
    }
77
}
78