Completed
Push — master ( d4d075...c3a49a )
by Benjamin
55:33 queued 55:33
created

FrontNodeController::displayNodeAdminBarAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Controller;
4
5
use Alpixel\Bundle\CMSBundle\Entity\Node;
6
use Alpixel\Bundle\SEOBundle\Annotation\MetaTag;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14
class FrontNodeController extends Controller
15
{
16
    /**
17
     * @Route("/page/{slug}", name="alpixel_cms")
18
     * @MetaTag("node", providerClass="Alpixel\Bundle\CMSBundle\Entity\Node", title="Page de contenu")
19
     * @ParamConverter("node", options={"mapping" : {"slug": "slug"}})
20
     * @Method("GET")
21
     */
22
    public function dispatchAction(Request $request, Node $node)
23
    {
24
        $object = $this->get('cms.helper')->getNodeElementEntityFromNode($node);
25
26
        if ($object !== null && $object->getNode()->getPublished()) {
27
            if (stripos($request->getLocale(), $object->getNode()->getLocale()) !== false) {
28
                $contentType = $this->get('cms.helper')->getContentTypeFromNodeElementClass($object);
29
                return $this->forward($contentType['controller'], [
30
                    '_route'        => $this->getRequest()->attributes->get('_route'),
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
31
                    '_route_params' => $this->getRequest()->attributes->get('_route_params'),
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
32
                    'object'        => $object,
33
                ]);
34
            }
35
        }
36
37
        throw $this->createNotFoundException();
38
    }
39
40
    public function displayNodeAdminBarAction(Node $node)
41
    {
42
        $canEdit = $this->get('request')->cookies->get('can_edit');
43
44
        if ($canEdit !== null && $canEdit === hash('sha256', 'can_edit'.$this->container->getParameter('secret'))) {
45
            return $this->render('CMSBundle:admin:blocks/admin_bar_page.html.twig', [
46
                'link' => $this->generateUrl('admin_alpixel_cms_node_editContent', ['id' => $node->getId()]),
47
            ]);
48
        }
49
50
        return new Response();
51
    }
52
53
    public function displayCustomAdminBarAction($link)
54
    {
55
        $canEdit = $this->get('request')->cookies->get('can_edit');
56
57
        if ($canEdit !== null && $canEdit === hash('sha256', 'can_edit'.$this->container->getParameter('secret'))) {
58
            return $this->render('CMSBundle:admin:blocks/admin_bar_page.html.twig', [
59
                'link' => $link,
60
            ]);
61
        }
62
63
        return new Response();
64
    }
65
}
66