Passed
Push — master ( 099ac9...4174e1 )
by Anthony
01:48
created

AccessRightsController::handleEditForm()   A

Complexity

Conditions 1
Paths 0

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 0
nop 3
1
<?php
2
3
namespace Ribs\RibsAdminBundle\Controller;
4
5
use Ribs\RibsAdminBundle\Entity\AccessRight;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\Form\Form;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
class AccessRightsController extends Controller
13
{
14
	//---------------------------------------------- VIEWS METHODS ---------------------------------------------------------//
15
	/**
16
	 * @Route("/access-rights-management/", name="ribsadmin_access_rights")
17
	 * @return Response
18
	 */
19
	public function listAction(): Response
20
	{
21
		$em = $this->getDoctrine()->getManager();
22
		$acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll();
23
24
		return $this->render("@RibsAdmin/access-rights/list-all-list.html.twig", [
25
			"access_right" => $acces_right
26
		]);
27
	}
28
	
29
	/**
30
	 * @Route("/access-rights-management/create/", name="ribsadmin_access_rights_create")
31
	 * @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit")
32
	 * @param Request $request
33
	 * @param string|null $guid
34
	 * @return Response
35
	 */
36
	public function editAction(Request $request, string $guid = null): Response
37
	{
38
		$em = $this->getDoctrine()->getManager();
39
		$list_rights_user = [];
40
41
		if ($guid === null) {
42
			$access_right = new AccessRight();
43
		} else {
44
			$access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]);
45
			$list_rights_user = explode(",", $access_right->getAccessRights());
46
		}
47
48
		$form = $this->createForm("Ribs\RibsAdminBundle\Form\AccessRight", $access_right);
49
		$form->handleRequest($request);
50
		
51
		if ($form->isValid() && $form->isSubmitted()) {
52
			return $this->handleEditForm($request, $form, $access_right);
53
		}
54
		
55
		return $this->render("@RibsAdmin/access-rights/edit-list.html.twig", [
56
			"access_right" => $access_right,
57
            "form" => $form->createView(),
58
			"list_rights_user" => $list_rights_user,
59
			"ribs_admin_rights" => json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json"))
60
		]);
61
	}
62
	//---------------------------------------------- END VIEWS METHODS ---------------------------------------------------------//
63
	
64
	/**
65
	 * @param Request $request
66
	 * @param Form $form
67
	 * @param AccessRight $access_right
68
	 * in dev
69
	 */
70
	private function handleEditForm(Request $request, Form $form, AccessRight $access_right) {
71
		dump($request);
0 ignored issues
show
Bug introduced by
The function dump was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
		/** @scrutinizer ignore-call */ 
72
  dump($request);
Loading history...
72
		dump($form);
73
		dump($access_right);
74
		die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
75
	}
76
}