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

AdminBundle/Controller/DefaultController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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