PageController::orderAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * This file is part of Webcook common bundle.
5
 *
6
 * See LICENSE file in the root of the bundle. Webcook
7
 */
8
9
namespace Webcook\Cms\CoreBundle\Controller;
10
11
use Webcook\Cms\CoreBundle\Base\BaseRestController;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
14
use Webcook\Cms\CoreBundle\Entity\Page;
15
use Webcook\Cms\CoreBundle\Entity\PageSection;
16
use Webcook\Cms\CoreBundle\Form\Type\PageType;
17
use Webcook\Cms\CoreBundle\Form\Type\PageSectionType;
18
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
19
use Webcook\Cms\SecurityBundle\Authorization\Voter\WebcookCmsVoter;
20
use FOS\RestBundle\Controller\Annotations\Get;
21
use FOS\RestBundle\Controller\Annotations\Post;
22
use FOS\RestBundle\Controller\Annotations\Put;
23
use FOS\RestBundle\Controller\Annotations\Delete;
24
use Doctrine\DBAL\LockMode;
25
26
/**
27
 * Page controller.
28
 */
29
class PageController extends BaseRestController
30
{
31
    /**
32
     * Update page section order.
33
     *
34
     * @param int $id Id of the desired Page.
35
     *
36
     */
37
    public function orderAction($id)
38
    {
39
        $order = $this->getPutParameters('order');
40
        $pageSection = $this->getEntityManager()->getRepository('Webcook\Cms\CoreBundle\Entity\PageSection')->find($id);
41
42
        if (!is_null($pageSection)) {
43
            if (!is_numeric($order)) {
44
                throw new BadRequestHttpException('Order is not numeric.');
45
            }
46
47
            $pageSection->setOrder($order);
48
            $this->getEntityManager()->flush();
49
        } else {
50
            throw new NotFoundHttpException('Page section does not exist.');
51
        }
52
53
        return $pageSection;
54
    }
55
}
56