Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / Vigilo / VigiloLocation.php @ 7225125e

History | View | Annotate | Download (2.67 KB)

1
<?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
        $manufacturers = new Manufacturer();
22
        $manufacturers = $manufacturers->find();
23
        foreach ($manufacturers as $manufacturer) {
24
            $this->childrenManufacturer[] = new VigiloGroups($manufacturer["name"]);
25
        }
26
    }
27

    
28
    protected function selectEntities()
29
    {
30
        $entities   = new Entity();
31
        $entities   = $entities->find("", "completename");
32
        $ancestors  = array();
33
        foreach ($entities as $entity) {
34
            $currentLevel = $entity["level"];
35
            if ($currentLevel == 1 && isset($ancestors[1])) {
36
                $this->childrenEntity[] = $ancestors[1];
37
            }
38
            $tempEntity = new VigiloGroups($entity["name"]);
39
            $ancestors[$currentLevel] = $tempEntity;
40
            if ($currentLevel != 1) {
41
                $ancestors[$currentLevel - 1]->addSubGroup($tempEntity);
42
            }
43
        }
44
        $this->childrenEntity[] = $ancestors[1];
45
    }
46

    
47
    protected function selectLocations()
48
    {
49
        $locations = new Location();
50
        $locations = $locations->find("", "completename");
51
        $ancestors = array();
52
        foreach ($locations as $location) {
53
            $currentLevel = $location["level"];
54
            if ($currentLevel == 1 && isset($ancestors[1])) {
55
                $this->childrenLocation[] = $ancestors[1];
56
            }
57
            $tempLocation = new VigiloGroups($location["name"]);
58
            $ancestors[$currentLevel] = $tempLocation;
59
            if ($currentLevel != 1) {
60
                $ancestors[$currentLevel - 1]->addSubGroup($tempLocation);
61
            }
62
        }
63
        $this->childrenLocation[] = $ancestors[1];
64
    }
65
  
66
    public function __toString()
67
    {
68
        $outXML = new DOMDocument();
69
        $outXML->preserveWhiteSpace = false;
70
        $outXML->formatOutput       = true;
71
        $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
}