Completed
Pull Request — dev (#27)
by
unknown
14:14
created

AdminController::indexAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\Admin;
6
use AppBundle\Form\AdminType;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
12
/**
13
 * Class DefaultController
14
 * @Route("/admin", name="admin")
15
 * @package AppBundle\Controller
16
 */
17
class AdminController extends Controller
18
{
19
    /**
20
     * @Route("/", name="admin_info")
21
     * @Template("@App/Admin/index.html.twig")
22
     *
23
     * @param Request $request
24
     * @return array
25
     */
26
    public function indexAction(Request $request)
27
    {
28
        $em = $this->getDoctrine()->getManager();
29
        $admin = $em->getRepository(Admin::class)->findOneBy(['id' => $this->getUser()->getId()]);
30
        $editForm = $this->createForm(AdminType::class, $admin);
31
        $editForm->handleRequest($request);
32
        if ($editForm->isSubmitted()) {
33
            if ($editForm->isValid()) {
34
                $em->persist($admin);
35
                $em->flush();
36
            }
37
        }
38
        return [
39
            "admin" => $admin,
40
            "editForm" => $editForm->createView(),
41
        ];
42
    }
43
}
44