Completed
Push — master ( cd3b2e...50c111 )
by Craig
07:10
created

SortController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A resortAction() 0 23 3
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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
16
use Symfony\Component\HttpFoundation\Request;
17
use Zikula\Core\Controller\AbstractController;
18
use Zikula\Core\Response\Ajax\AjaxResponse;
19
20
/**
21
 * Sort controller class handling resort functionality.
22
 *
23
 * @Route("/ajax")
24
 */
25
class SortController extends AbstractController
26
{
27
    /**
28
     * Resort routes.
29
     *
30
     * @param Request $request Current request instance
31
     *
32
     * @return boolean|AjaxResponse The response
33
     */
34
    public function resortAction(Request $request)
35
    {
36
        if (!$this->hasPermission('ZikulaRoutesModule::Ajax', '::', ACCESS_EDIT)) {
37
            return true;
38
        }
39
40
        $sort = $request->request->get('sort', []);
41
42
        $entityManager = $this->get('doctrine.orm.default_entity_manager');
43
44
        foreach ($sort as $position => $id) {
45
            $id = substr($id, 4);
46
            $object = $entityManager->find('ZikulaRoutesModule:RouteEntity', $id);
47
            $object->setSort($position);
48
            $entityManager->persist($object);
49
        }
50
51
        $entityManager->flush();
52
53
        $this->get('zikula.cache_clearer')->clear('symfony.routing');
54
55
        return new AjaxResponse([]);
56
    }
57
}
58