glpi / src / Vigilo / VigiloLocation.php @ ad6689da
History | View | Annotate | Download (2.67 KB)
1 | a5c9df40 | Thibault Louet | <?php
|
---|---|---|---|
2 | |||
3 | class VigiloLocation extends VigiloXml |
||
4 | { |
||
5 | protected $childrenLocation; |
||
6 | protected $childrenEntity; |
||
7 | protected $childrenManufacturer; |
||
8 | |||
9 | public function __construct() |
||
10 | { |
||
11 | ad6689da | Francois POIROTTE | $this->childrenLocation = array(); |
12 | $this->childrenEntity = array(); |
||
13 | $this->childrenManufacturer = array(); |
||
14 | a5c9df40 | Thibault Louet | $this->selectLocations();
|
15 | $this->selectEntities();
|
||
16 | $this->selectManufacturers();
|
||
17 | } |
||
18 | |||
19 | protected function selectManufacturers() |
||
20 | { |
||
21 | ad6689da | Francois POIROTTE | $manufacturers = new Manufacturer(); |
22 | $manufacturers = $manufacturers->find(); |
||
23 | a5c9df40 | Thibault Louet | foreach ($manufacturers as $manufacturer) { |
24 | $this->childrenManufacturer[] = new VigiloGroups($manufacturer["name"]); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | protected function selectEntities() |
||
29 | { |
||
30 | ad6689da | Francois POIROTTE | $entities = new Entity(); |
31 | $entities = $entities->find("", "completename"); |
||
32 | $ancestors = array(); |
||
33 | a5c9df40 | Thibault Louet | foreach ($entities as $entity) { |
34 | ad6689da | Francois POIROTTE | $currentLevel = $entity["level"]; |
35 | if ($currentLevel == 1 && isset($ancestors[1])) { |
||
36 | $this->childrenEntity[] = $ancestors[1]; |
||
37 | a5c9df40 | Thibault Louet | } |
38 | $tempEntity = new VigiloGroups($entity["name"]); |
||
39 | ad6689da | Francois POIROTTE | $ancestors[$currentLevel] = $tempEntity; |
40 | a5c9df40 | Thibault Louet | if ($currentLevel != 1) { |
41 | ad6689da | Francois POIROTTE | $ancestors[$currentLevel - 1]->addSubGroup($tempEntity); |
42 | a5c9df40 | Thibault Louet | } |
43 | } |
||
44 | ad6689da | Francois POIROTTE | $this->childrenEntity[] = $ancestors[1]; |
45 | a5c9df40 | Thibault Louet | } |
46 | |||
47 | protected function selectLocations() |
||
48 | { |
||
49 | ad6689da | Francois POIROTTE | $locations = new Location(); |
50 | $locations = $locations->find("", "completename"); |
||
51 | $ancestors = array(); |
||
52 | a5c9df40 | Thibault Louet | foreach ($locations as $location) { |
53 | ad6689da | Francois POIROTTE | $currentLevel = $location["level"]; |
54 | if ($currentLevel == 1 && isset($ancestors[1])) { |
||
55 | $this->childrenLocation[] = $ancestors[1]; |
||
56 | a5c9df40 | Thibault Louet | } |
57 | $tempLocation = new VigiloGroups($location["name"]); |
||
58 | ad6689da | Francois POIROTTE | $ancestors[$currentLevel] = $tempLocation; |
59 | a5c9df40 | Thibault Louet | if ($currentLevel != 1) { |
60 | ad6689da | Francois POIROTTE | $ancestors[$currentLevel - 1]->addSubGroup($tempLocation); |
61 | a5c9df40 | Thibault Louet | } |
62 | } |
||
63 | ad6689da | Francois POIROTTE | $this->childrenLocation[] = $ancestors[1]; |
64 | a5c9df40 | Thibault Louet | } |
65 | |||
66 | public function __toString() |
||
67 | { |
||
68 | ad6689da | Francois POIROTTE | $outXML = new DOMDocument(); |
69 | $outXML->preserveWhiteSpace = false; |
||
70 | $outXML->formatOutput = true; |
||
71 | a5c9df40 | Thibault Louet | $outXML->loadXML(
|
72 | self::sprintf( |
||
73 | '<groups>
|
||
74 | <group name="Locations"> %s </group>
|
||
75 | <group name="Entities"> %s </group>
|
||
76 | <group name="Manufacturers"> %s </group>
|
||
77 | </groups>',
|
||
78 | $this->childrenLocation,
|
||
79 | $this->childrenEntity,
|
||
80 | $this->childrenManufacturer
|
||
81 | ) |
||
82 | ); |
||
83 | return $outXML->saveXML(); |
||
84 | } |
||
85 | } |