glpi / src / plugins / vigilo / inc / groups.class.php @ 166be9d2
History | View | Annotate | Download (2.02 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
class PluginVigiloGroups |
4 |
{ |
5 |
protected $groups; |
6 |
|
7 |
public function __construct() |
8 |
{ |
9 |
$this->groups = array( |
10 |
'Entities' => new VigiloGroups('Entities'), |
11 |
'Manufacturers' => new VigiloGroups('Manufacturers'), |
12 |
'Locations' => new VigiloGroups('Locations'), |
13 |
); |
14 |
|
15 |
$this->getManufacturers();
|
16 |
$this->getEntities();
|
17 |
$this->getLocations();
|
18 |
} |
19 |
|
20 |
public function getName() |
21 |
{ |
22 |
return "glpi"; |
23 |
} |
24 |
|
25 |
protected function getManufacturers() |
26 |
{ |
27 |
$manufacturers = new Manufacturer(); |
28 |
$manufacturers = $manufacturers->find(); |
29 |
foreach ($manufacturers as $manufacturer) { |
30 |
$this->groups['Manufacturers'][] = $manufacturer["name"]; |
31 |
} |
32 |
} |
33 |
|
34 |
protected function getEntities() |
35 |
{ |
36 |
$items = new Entity(); |
37 |
$items = $items->find("", "completename"); |
38 |
foreach ($items as $item) { |
39 |
$parts = explode(' > ', $item['completename']); |
40 |
$name = array_pop($parts); |
41 |
|
42 |
$pos =& $this->groups['Entities']; |
43 |
foreach ($parts as $part) { |
44 |
$pos =& $pos[$part]; |
45 |
} |
46 |
$pos[] = $name; |
47 |
} |
48 |
} |
49 |
|
50 |
protected function getLocations() |
51 |
{ |
52 |
$items = new Location(); |
53 |
$items = $items->find("", "completename"); |
54 |
foreach ($items as $item) { |
55 |
$parts = explode(' > ', $item['completename']); |
56 |
$name = array_pop($parts); |
57 |
|
58 |
$pos =& $this->groups['Locations']; |
59 |
foreach ($parts as $part) { |
60 |
$pos =& $pos[$part]; |
61 |
} |
62 |
$pos[] = $name; |
63 |
} |
64 |
} |
65 |
|
66 |
public function __toString() |
67 |
{ |
68 |
$out = "<groups>\n"; |
69 |
foreach ($this->groups as $group) { |
70 |
$out .= $group; |
71 |
} |
72 |
$out .= "</groups>\n"; |
73 |
|
74 |
$outXML = new DOMDocument(); |
75 |
$outXML->preserveWhiteSpace = false; |
76 |
$outXML->formatOutput = true; |
77 |
$outXML->loadXML($out); |
78 |
return $outXML->saveXML(); |
79 |
} |
80 |
} |