Code

Updated new Config Management
[gosa.git] / gosa-core / plugins / 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 getItemByPath($path)
72     {
73         if(isset($this->data['linear'][$path])){
74             return($this->data['linear'][$path]);
75         }
76         return(NULL);
77     }
79     function getItemsByType($type)
80     {
81         $res = array();
82         foreach($this->data['linear'] as $path => $item){
83             if($item['type'] == $type) $res[] = $item;
84         }
85         return($res);
86     }
87 }
89 ?>