ModuleService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
eloc 20
c 5
b 0
f 2
dl 0
loc 54
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAllInfosModules() 0 15 2
A getModuleRights() 0 13 2
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
     * method that return all infos needed in access right management page
26
	 * @return array
27
	 */
28
	public function getAllInfosModules()
29
	{
30
		$modules = $this->em->get("doctrine")->getRepository(Module::class)->findBy([
31
			"active" => true
32
		]);
33
		$modules_data = [];
34
		
35
		foreach ($modules as $module) {
36
			$modules_data[] = [
37
				"name" => $module->getTitle(),
38
				"rights" => (array)json_decode(file_get_contents($this->globals->getBaseBundlePath($module->getPackageName(), $module->getDevMode()) . "/Resources/json/ribsadmin_rights.json"))
39
			];
40
		}
41
		
42
		return $modules_data;
43
	}
44
	
45
	/**
46
     * function that return all modules rights
47
	 * @return object
48
	 */
49
	public function getModuleRights()
50
	{
51
		$modules = $this->em->get("doctrine")->getRepository(Module::class)->findBy([
52
			"active" => true,
53
			"displayed" => true
54
		]);
55
		$rights = [];
56
		
57
		foreach ($modules as $module) {
58
			$rights[] = json_decode(file_get_contents($this->globals->getBaseBundlePath($module->getPackageName(), $module->getDevMode()) . "/Resources/json/ribsadmin_rights.json"));
59
		}
60
		
61
		return (object)$rights;
62
	}
63
}
64