glpi / src / plugins / vigilo / inc / groups.class.php @ e1c378c0
History | View | Annotate | Download (2.79 KB)
1 | 166be9d2 | Francois POIROTTE | <?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 | e1c378c0 | Francois POIROTTE | 'Technicians' => new VigiloGroups('Technicians'), |
14 | 166be9d2 | Francois POIROTTE | ); |
15 | |||
16 | $this->getManufacturers();
|
||
17 | $this->getEntities();
|
||
18 | $this->getLocations();
|
||
19 | e1c378c0 | Francois POIROTTE | $this->getTechnicians();
|
20 | 166be9d2 | Francois POIROTTE | } |
21 | |||
22 | public function getName() |
||
23 | { |
||
24 | return "glpi"; |
||
25 | } |
||
26 | |||
27 | protected function getManufacturers() |
||
28 | { |
||
29 | $manufacturers = new Manufacturer(); |
||
30 | $manufacturers = $manufacturers->find(); |
||
31 | foreach ($manufacturers as $manufacturer) { |
||
32 | $this->groups['Manufacturers'][] = $manufacturer["name"]; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | protected function getEntities() |
||
37 | { |
||
38 | $items = new Entity(); |
||
39 | $items = $items->find("", "completename"); |
||
40 | foreach ($items as $item) { |
||
41 | $parts = explode(' > ', $item['completename']); |
||
42 | $name = array_pop($parts); |
||
43 | |||
44 | $pos =& $this->groups['Entities']; |
||
45 | foreach ($parts as $part) { |
||
46 | $pos =& $pos[$part]; |
||
47 | } |
||
48 | $pos[] = $name; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | protected function getLocations() |
||
53 | { |
||
54 | $items = new Location(); |
||
55 | $items = $items->find("", "completename"); |
||
56 | foreach ($items as $item) { |
||
57 | $parts = explode(' > ', $item['completename']); |
||
58 | $name = array_pop($parts); |
||
59 | |||
60 | $pos =& $this->groups['Locations']; |
||
61 | foreach ($parts as $part) { |
||
62 | $pos =& $pos[$part]; |
||
63 | } |
||
64 | $pos[] = $name; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | e1c378c0 | Francois POIROTTE | protected function getTechnicians() |
69 | { |
||
70 | global $DB; |
||
71 | |||
72 | // Ce serait plus propre d'utiliser la surcouche de GLPI
|
||
73 | // pour récupérer l'information, mais cela serait aussi
|
||
74 | // beaucoup plus coûteux (plus d'appels à la BDD, etc.).
|
||
75 | |||
76 | $query = <<<SQL |
||
77 | SELECT DISTINCT u.name
|
||
78 | FROM glpi_users u
|
||
79 | JOIN (
|
||
80 | SELECT users_id_tech
|
||
81 | FROM glpi_computers
|
||
82 | UNION ALL
|
||
83 | SELECT users_id_tech
|
||
84 | FROM glpi_networkequipments
|
||
85 | UNION ALL
|
||
86 | SELECT users_id_tech
|
||
87 | FROM glpi_printers
|
||
88 | ) as a1 on a1.users_id_tech = u.id;
|
||
89 | SQL;
|
||
90 | foreach ($DB->request($query) as $row) { |
||
91 | $this->groups['Technicians'][] = $row['name']; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | 166be9d2 | Francois POIROTTE | public function __toString() |
96 | { |
||
97 | $out = "<groups>\n"; |
||
98 | foreach ($this->groups as $group) { |
||
99 | $out .= $group; |
||
100 | } |
||
101 | $out .= "</groups>\n"; |
||
102 | |||
103 | $outXML = new DOMDocument(); |
||
104 | $outXML->preserveWhiteSpace = false; |
||
105 | $outXML->formatOutput = true; |
||
106 | $outXML->loadXML($out); |
||
107 | return $outXML->saveXML(); |
||
108 | } |
||
109 | } |