Code

Removed accidentally checked in file:contrib/resolution
[gosa.git] / gosa-plugins / gosa-ng / admin / newConfigManagement / class_ConfigManagementDataModel.inc
1 <?php
3 class ConfigManagementDataModel
4 {
5     private $data = array();
6     private $typeToPath = array();
7     private $idToPath = array();
9     function __construct()
10     {
11         $this->data = array();
12         $this->data['linear'] = array();
13         $this->data['recursive'] = array();
14         $this->addItem('root', '','root', array());
15     }
17     function getDataModel()
18     {
19         return($this->data);
20     }
22     
25     function addItem($type, $path, $name, $values = array(), $status = "")
26     {
27         if($path == ""){
28             $parentItem = &$this->data['recursive'];
29             $parentId = NULL;
30             $parentDn = "";
31         }elseif(isset($this->data['linear'][$path])){
32             $parentItem = &$this->data['linear'][$path]['children'];
33             $parentId = $this->data['linear'][$path]['id'];
34             $parentDn = $this->data['linear'][$path]['dn'];
35         }else{
36             echo "No parent";
37             return(FALSE);
38         }
40         $this->currentID ++;
41         $entryPath = "{$path}/{$name}";
42         $entryDn  = rtrim("cn={$name},{$parentDn}",',');
43         $entryId =  $this->currentID;
44         
45         $entry['path'] = $entryPath;
46         $entry['dn'] = $entryDn;
47         $entry['id'] = $entryId;
48         $entry['parentId'] = $parentId;
49         $entry['name'] = $name;
50         $entry['path'] = $entryPath;
51         $entry['parentPath'] = $path;
52         $entry['type'] = $type;
53         $entry['status'] = $status;
54         $entry['values'] = $values;
55         $entry['children'] = array();
57         $parentItem[$entryPath] = &$entry;
58         $this->data['linear'][$entryPath] = &$parentItem[$entryPath];
60         $this->idToPath[$entryId] = $entryPath;
61         $this->typeToPath[$type][$name] = $entryPath;
62     
63         return($entryId);
64     }
66     function pathToDn($path)
67     {
68         
69     }
71     function itemExistsByPath($path)
72     {
73         return(isset($this->data['linear'][$path]));
74     }
75     
76     function getItemByPath($path)
77     {
78         if(isset($this->data['linear'][$path])){
79             return($this->data['linear'][$path]);
80         }
81         return(NULL);
82     }
84     function setItemStatus($path, $status)
85     {
86         if(!$this->itemExistsByPath($path)){
87             trigger_error("Invalid item path '{$path}'!");
88         }else{
89             $this->data['linear'][$path]['status'] = $status;
90         }
91     }
93     function getItemsByType($types)
94     {
95         $res = array();
96         foreach($this->data['linear'] as $path => $item){
97             if(in_array($item['type'],$types)) $res[] = $item;
98         }
99         return($res);
100     }
103     function getItemById($id)
104     {
105         $path = NULL;
106         if(isset($this->idToPath[$id])){
107             $path = $this->idToPath[$id];
108         }else{
109             return(NULL);
110         }
111         if(isset($this->data['linear'][$path])){
112             return($this->data['linear'][$path]);
113         }
114         return(NULL);
115     }
118 ?>