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