Completed
Push — master ( a7fff6...5ea170 )
by Jeroen
18:57 queued 10s
created

DefaultController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 10
dl 0
loc 71
ccs 0
cts 38
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 14 2
A editIndexAction() 0 35 5
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Controller;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\AdminBundle\Entity\DashboardConfiguration;
7
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
8
use Kunstmaan\AdminBundle\Form\DashboardConfigurationType;
9
use Symfony\Component\Routing\Annotation\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
15
/**
16
 * The default controller is used to render the main screen the users see when they log in to the admin
17
 */
18
class DefaultController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
19
{
20
    /**
21
     * The index action will render the main screen the users see when they log in in to the admin
22
     *
23
     * @Route("/", name="KunstmaanAdminBundle_homepage")
24
     * @Template("@KunstmaanAdmin/Default/index.html.twig")
25
     *
26
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be RedirectResponse|array<s...DashboardConfiguration>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
27
     */
28
    public function indexAction()
29
    {
30
        if ($this->container->hasParameter('kunstmaan_admin.dashboard_route')) {
31
            return $this->redirect($this->generateUrl($this->getParameter('kunstmaan_admin.dashboard_route')));
32
        }
33
34
        /* @var DashboardConfiguration $dashboardConfiguration */
35
        $dashboardConfiguration = $this->getDoctrine()
36
            ->getManager()
37
            ->getRepository('KunstmaanAdminBundle:DashboardConfiguration')
38
            ->findOneBy(array());
39
40
        return array('dashboardConfiguration' => $dashboardConfiguration);
41
    }
42
43
    /**
44
     * The admin of the index page
45
     *
46
     * @Route("/adminindex", name="KunstmaanAdminBundle_homepage_admin")
47
     * @Template("@KunstmaanAdmin/Default/editIndex.html.twig")
48
     *
49
     * @param \Symfony\Component\HttpFoundation\Request $request
50
     *
51
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be RedirectResponse|array<s...DashboardConfiguration>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
     */
53
    public function editIndexAction(Request $request)
54
    {
55
        /* @var $em EntityManager */
56
        $em = $this->getDoctrine()->getManager();
57
58
        /* @var DashboardConfiguration $dashboardConfiguration */
59
        $dashboardConfiguration = $em
60
            ->getRepository('KunstmaanAdminBundle:DashboardConfiguration')
61
            ->findOneBy(array());
62
63
        if (is_null($dashboardConfiguration)) {
64
            $dashboardConfiguration = new DashboardConfiguration();
65
        }
66
        $form = $this->createForm(DashboardConfigurationType::class, $dashboardConfiguration);
67
68
        if ($request->isMethod('POST')) {
69
            $form->handleRequest($request);
70
            if ($form->isSubmitted() && $form->isValid()) {
71
                $em->persist($dashboardConfiguration);
72
                $em->flush($dashboardConfiguration);
73
74
                $this->addFlash(
75
                    FlashTypes::SUCCESS,
76
                    $this->get('translator')->trans('kuma_admin.edit.flash.success')
77
                );
78
79
                return new RedirectResponse($this->generateUrl('KunstmaanAdminBundle_homepage'));
80
            }
81
        }
82
83
        return array(
84
            'form' => $form->createView(),
85
            'dashboardConfiguration' => $dashboardConfiguration,
86
        );
87
    }
88
}
89