Passed
Push — master ( 31adf1...6657ff )
by Anthony
02:17
created

ModuleService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Service;
4
5
use PiouPiou\RibsAdminBundle\Entity\Module;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
8
class ModuleService
9
{
10
	private $em;
11
	private $globals;
12
	
13
	/**
14
	 * AccessRights constructor.
15
	 * @param ContainerInterface $em
16
	 * @param Globals $globals
17
	 */
18
	public function __construct(ContainerInterface $em, Globals $globals)
19
	{
20
		$this->em = $em;
21
		$this->globals = $globals;
22
	}
23
	
24
	/**
25
	 * @return array
26
	 * method that return all infos needed in access right management page
27
	 */
28
	public function getAllInfosModules()
29
	{
30
		$modules = $this->em->get("doctrine")->getRepository(Module::class)->findBy([
31
			"active" => true,
32
			"displayed" => true
33
		]);
34
		$modules_data = [];
35
		
36
		foreach ($modules as $module) {
37
			$modules_data[] = [
38
				"name" => $module->getTitle(),
39
				"rights" => (array)json_decode(file_get_contents($this->globals->getBaseBundlePath($module->getPackageName()) . "/Resources/json/ribsadmin_rights.json"))
40
			];
41
		}
42
		
43
		return $modules_data;
44
	}
45
	
46
	/**
47
	 * @return object
48
	 * function that return all modules rights
49
	 */
50
	public function getModuleRights()
51
	{
52
		$modules = $this->em->get("doctrine")->getRepository(Module::class)->findBy([
53
			"active" => true,
54
			"displayed" => true
55
		]);
56
		$rights = [];
57
		
58
		foreach ($modules as $module) {
59
			$rights[] = json_decode(file_get_contents($this->globals->getBaseBundlePath($module->getPackageName()) . "/Resources/json/ribsadmin_rights.json"));
60
		}
61
		
62
		return (object)$rights;
63
	}
64
}