Commit b1d505690c37bbf66e782468fa87b8f86f87f1e9
1 parent
996f73e5
Exists in
master
and in
111 other branches
formattage
Showing
1 changed file
with
83 additions
and
70 deletions
Show diff stats
php/classes/AmdaObjectMgr.php
... | ... | @@ -2,11 +2,10 @@ |
2 | 2 | /** |
3 | 3 | * @class AmdaObjectMgr |
4 | 4 | * @version $Id: AmdaObjectMgr.php 2891 2015-04-30 11:31:51Z elena $ |
5 | - * | |
6 | 5 | */ |
7 | 6 | |
8 | -class AmdaObjectMgr { | |
9 | - | |
7 | +class AmdaObjectMgr | |
8 | +{ | |
10 | 9 | protected $xmlName, $xp; |
11 | 10 | protected $attributes, $optionalAttributes; |
12 | 11 | protected $contentRootId, $objTagName; |
... | ... | @@ -19,7 +18,8 @@ class AmdaObjectMgr { |
19 | 18 | public $contentDom; |
20 | 19 | public $objectDom; |
21 | 20 | |
22 | - protected function __construct($xmlFile) { | |
21 | + protected function __construct($xmlFile) | |
22 | + { | |
23 | 23 | // content XML |
24 | 24 | $this->xmlName = USERWSDIR."/".$xmlFile; |
25 | 25 | $this->contentDom = new DomDocument("1.0"); |
... | ... | @@ -35,35 +35,41 @@ class AmdaObjectMgr { |
35 | 35 | $this->objectDom = new DomDocument("1.0"); |
36 | 36 | $this->objectDom->preserveWhiteSpace = false; |
37 | 37 | $this->objectDom->formatOutput = true; |
38 | - } | |
38 | + } | |
39 | 39 | |
40 | - private function getNewId() { | |
40 | + private function getNewId() | |
41 | + { | |
41 | 42 | // Get all ID attributes |
42 | 43 | $elements = $this->xp->query("//".$this->objTagName."/@xml:id"); |
43 | 44 | |
44 | 45 | // Now find New Valid ID |
45 | - if ($elements->length > 0) { | |
46 | - if($elements->length > 0) for ($i = 0; $i < $elements->length; $i++) { | |
46 | + if ($elements->length > 0) | |
47 | + { | |
48 | + if($elements->length > 0) for ($i = 0; $i < $elements->length; $i++) | |
49 | + { | |
47 | 50 | $id = explode('_',$elements->item($i)->nodeValue); |
48 | 51 | $idList[] = $id[1]; |
49 | 52 | } |
50 | 53 | |
51 | 54 | sort($idList); |
52 | 55 | |
53 | - for ($i = 0; $i < count($idList); $i++) { | |
54 | - if ($idList[$i] > $i) { | |
56 | + for ($i = 0; $i < count($idList); $i++) | |
57 | + { | |
58 | + if ($idList[$i] > $i) | |
59 | + { | |
55 | 60 | $newID = $i; |
56 | 61 | break; |
57 | 62 | } |
58 | 63 | $newID = $i+1; |
59 | 64 | } |
60 | 65 | } else |
61 | - $newID = 0; | |
66 | + $newID = 0; | |
67 | + | |
62 | 68 | return $newID; |
63 | 69 | } |
64 | 70 | |
65 | - protected function setId() { | |
66 | - | |
71 | + protected function setId() | |
72 | + { | |
67 | 73 | $id_ = $this->getNewId(); |
68 | 74 | if ($id_ === false) return false; |
69 | 75 | $this->id = $this->id_prefix.$id_; |
... | ... | @@ -71,16 +77,16 @@ class AmdaObjectMgr { |
71 | 77 | return $this->id; |
72 | 78 | } |
73 | 79 | |
74 | - protected function objectExistsByName($name){ | |
75 | - | |
80 | + protected function objectExistsByName($name) | |
81 | + { | |
76 | 82 | $this->obj = $this->xp->query("//".$this->objTagName."[@name='".$name."']"); |
77 | 83 | if ($this->obj->length != 0) return true; |
78 | 84 | |
79 | 85 | return false; |
80 | 86 | } |
81 | 87 | |
82 | - protected function getObjectIdByName($name) { | |
83 | - | |
88 | + protected function getObjectIdByName($name) | |
89 | + { | |
84 | 90 | $this->obj = $this->xp->query("//".$this->objTagName."[@name='".$name."']"); |
85 | 91 | if ($this->obj->length == 0) return false; |
86 | 92 | $id = $this->obj->item(0)->getAttribute('xml:id'); |
... | ... | @@ -97,8 +103,8 @@ class AmdaObjectMgr { |
97 | 103 | return false; |
98 | 104 | } |
99 | 105 | |
100 | - protected function objectExistsById($id){ | |
101 | - | |
106 | + protected function objectExistsById($id) | |
107 | + { | |
102 | 108 | $this->obj = $this->contentDom->getElementById($id); |
103 | 109 | if ($this->obj != null) return $this->obj; |
104 | 110 | |
... | ... | @@ -111,23 +117,28 @@ class AmdaObjectMgr { |
111 | 117 | /* |
112 | 118 | * Write Object into desc file |
113 | 119 | */ |
114 | - protected function createObjectDescription($obj){ | |
115 | - | |
120 | + protected function createObjectDescription($obj) | |
121 | + { | |
116 | 122 | $root = $this->objectDom->createElement($this->objTagName); |
117 | 123 | $root->setAttribute('xml:id',$this->id); |
118 | 124 | |
119 | - foreach($obj as $key => $value) { | |
120 | - if ($key != 'id' && $key != 'leaf' && $key != 'nodeType') { | |
121 | - $node = $this->objectDom->createElement($key,htmlspecialchars($value)); | |
122 | - $root -> appendChild($node); | |
123 | - } | |
125 | + foreach($obj as $key => $value) | |
126 | + { | |
127 | + if ($key != 'id' && $key != 'leaf' && $key != 'nodeType') | |
128 | + { | |
129 | + $node = $this->objectDom->createElement($key,htmlspecialchars($value)); | |
130 | + $root -> appendChild($node); | |
131 | + } | |
124 | 132 | } |
125 | 133 | // add Optional Attributes if they are undefined |
126 | - foreach ($this->optionalAttributes as $key => $value) | |
127 | - if ($root->getElementsByTagName($key)->length == 0) { | |
134 | + foreach ($this->optionalAttributes as $key => $value) | |
135 | + { | |
136 | + if ($root->getElementsByTagName($key)->length == 0) | |
137 | + { | |
128 | 138 | $node = $this->objectDom->createElement($key,htmlspecialchars($value)); |
129 | 139 | $root -> appendChild($node); |
130 | 140 | } |
141 | + } | |
131 | 142 | |
132 | 143 | $this->objectDom->appendChild($root); |
133 | 144 | $this->objectDom->save($this->descFileName); |
... | ... | @@ -136,16 +147,16 @@ class AmdaObjectMgr { |
136 | 147 | /* |
137 | 148 | * Just Save Content XML |
138 | 149 | */ |
139 | - protected function saveContent() { | |
140 | - | |
141 | - $this->contentDom->save($this->xmlName); | |
150 | + protected function saveContent() | |
151 | + { | |
152 | + $this->contentDom->save($this->xmlName); | |
142 | 153 | } |
143 | 154 | |
144 | 155 | /* |
145 | 156 | * Add Object to Content XML |
146 | 157 | */ |
147 | - protected function addToContent($obj, $folder) { | |
148 | - | |
158 | + protected function addToContent($obj, $folder) | |
159 | + { | |
149 | 160 | $folderToAdd = null; |
150 | 161 | |
151 | 162 | $objList = $this->contentDom->getElementById($this->contentRootId); |
... | ... | @@ -153,7 +164,8 @@ class AmdaObjectMgr { |
153 | 164 | $newObj->setAttribute('xml:id',$this->id); |
154 | 165 | // object to mapped array |
155 | 166 | $obj_arr = (array)$obj; |
156 | - foreach ($this->attributes as $key => $value) { | |
167 | + foreach ($this->attributes as $key => $value) | |
168 | + { | |
157 | 169 | $newObj->setAttribute($key, $obj_arr[$key]); |
158 | 170 | } |
159 | 171 | if ($folder != null) |
... | ... | @@ -170,8 +182,8 @@ class AmdaObjectMgr { |
170 | 182 | /* |
171 | 183 | * Delete Object From Content XML |
172 | 184 | */ |
173 | - protected function deleteFromContent($obj) { | |
174 | - | |
185 | + protected function deleteFromContent($obj) | |
186 | + { | |
175 | 187 | $objList = $obj -> parentNode; // $this->contentDom->getElementById($this->contentRootId); |
176 | 188 | $objList -> removeChild($obj); |
177 | 189 | $this->saveContent(); |
... | ... | @@ -180,8 +192,8 @@ class AmdaObjectMgr { |
180 | 192 | /* |
181 | 193 | * Create Folder |
182 | 194 | */ |
183 | - protected function createFolder($obj){ | |
184 | - | |
195 | + protected function createFolder($obj) | |
196 | + { | |
185 | 197 | if ($this -> folderExistsByName($obj->name)) |
186 | 198 | return array('error' => NAME_EXISTS); |
187 | 199 | $newFolder = $this->contentDom->createElement('folder'); |
... | ... | @@ -198,8 +210,8 @@ class AmdaObjectMgr { |
198 | 210 | /* |
199 | 211 | * Get Folder of the object |
200 | 212 | */ |
201 | - protected function getObjectFolder($id) { | |
202 | - | |
213 | + protected function getObjectFolder($id) | |
214 | + { | |
203 | 215 | if (!($obj = $this->objectExistsById($id))) |
204 | 216 | return "NO_SUCH_ID"; |
205 | 217 | if ($obj->parentNode->tagName == 'folder') |
... | ... | @@ -208,32 +220,35 @@ class AmdaObjectMgr { |
208 | 220 | return null; |
209 | 221 | } |
210 | 222 | |
211 | - protected function setAlias($chain) { | |
212 | - | |
223 | + protected function setAlias($chain) | |
224 | + { | |
213 | 225 | $aliasMgr = new AliasMgr(); |
214 | 226 | $listeAlias = $aliasMgr->getList(); |
215 | 227 | |
216 | - foreach($listeAlias as $alias) { | |
228 | + foreach($listeAlias as $alias) | |
229 | + { | |
217 | 230 | $chain = $aliasMgr->substrParamAlias($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); |
218 | 231 | } |
219 | 232 | return $chain; |
220 | 233 | } |
221 | 234 | |
222 | - protected function resetAlias($chain) { | |
223 | - | |
235 | + protected function resetAlias($chain) | |
236 | + { | |
224 | 237 | $aliasMgr = new AliasMgr(); |
225 | 238 | $listeAlias = $aliasMgr->getList(); |
226 | 239 | |
227 | - foreach($listeAlias as $alias) { | |
240 | + foreach($listeAlias as $alias) | |
241 | + { | |
228 | 242 | $chain = $aliasMgr->substrAliasParam($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); |
229 | 243 | } |
230 | 244 | return $chain; |
231 | 245 | } |
232 | 246 | |
233 | - protected function createDom() { | |
234 | - | |
247 | + protected function createDom() | |
248 | + { | |
235 | 249 | $rootElement = $this->contentDom->createElement('ws'); |
236 | - foreach ($this->types as $type) { | |
250 | + foreach ($this->types as $type) | |
251 | + { | |
237 | 252 | $contentId = $type.'-treeRootNode'; |
238 | 253 | $contentTag = $type.'List'; |
239 | 254 | $typeElement = $this->contentDom->createElement($contentTag); |
... | ... | @@ -244,33 +259,28 @@ class AmdaObjectMgr { |
244 | 259 | $this->contentDom->appendChild($rootElement); |
245 | 260 | $this->contentDom->save($this->xmlName); |
246 | 261 | } |
247 | - | |
248 | - | |
249 | -/***************************************************************** | |
250 | -* PUBLIC FUNCTIONS | |
251 | -*****************************************************************/ | |
252 | 262 | |
253 | 263 | /* |
254 | 264 | * Create Parameter[TT...]/Folder |
255 | 265 | * create object itself, add it to content DOM |
256 | 266 | */ |
257 | - function createObject($p, $folder){ | |
258 | - | |
267 | + function createObject($p, $folder) | |
268 | + { | |
259 | 269 | if ($p -> leaf) |
260 | 270 | return $this->createParameter($p, $folder); |
261 | 271 | // else return $this->createFolder($p); |
262 | 272 | //TODO check if this is possible? |
263 | 273 | else |
264 | 274 | return array('error' => 'createFolder should be called from RENAME'); |
265 | - | |
266 | 275 | } |
267 | 276 | |
268 | 277 | /* |
269 | 278 | * Rename Parameter[TT...]/Folder |
270 | 279 | */ |
271 | - function renameObject($p){ | |
272 | - | |
273 | - if (!($objToRename = $this -> objectExistsById($p->id))) { | |
280 | + function renameObject($p) | |
281 | + { | |
282 | + if (!($objToRename = $this -> objectExistsById($p->id))) | |
283 | + { | |
274 | 284 | // NO SUCH ID: leaf -> error; |
275 | 285 | if ($p->leaf) |
276 | 286 | return array('error' => NO_SUCH_ID); |
... | ... | @@ -279,7 +289,8 @@ class AmdaObjectMgr { |
279 | 289 | } |
280 | 290 | |
281 | 291 | // object was just DD in the tree : move tag in xml |
282 | - if ($p -> name == $p -> old_name) { | |
292 | + if ($p -> name == $p -> old_name) | |
293 | + { | |
283 | 294 | if (!($parentNode = $this->contentDom->getElementById($p -> parent))) |
284 | 295 | return array('error' => NO_SUCH_PARENT_ID); |
285 | 296 | $parentNode -> appendChild($objToRename); |
... | ... | @@ -294,7 +305,8 @@ class AmdaObjectMgr { |
294 | 305 | |
295 | 306 | $objToRename->setAttribute('name',$p->name); |
296 | 307 | |
297 | - if (!$p->leaf) { | |
308 | + if (!$p->leaf) | |
309 | + { | |
298 | 310 | $objToRename->removeAttribute('xml:id'); |
299 | 311 | $objToRename->setAttribute('xml:id', $p->name.'_'.$this->objTagName); |
300 | 312 | } |
... | ... | @@ -310,8 +322,8 @@ class AmdaObjectMgr { |
310 | 322 | * Delete Parameter[TT...]/Folder |
311 | 323 | * Delete object itself, delete from contentDOM, mark as undefined in depending objects |
312 | 324 | */ |
313 | - function deleteObject($p){ | |
314 | - | |
325 | + function deleteObject($p) | |
326 | + { | |
315 | 327 | if ($p->leaf) { |
316 | 328 | // if Parameter[TT...] - delete resources first |
317 | 329 | $isDeleted = $this->deleteParameter($p->id); |
... | ... | @@ -340,9 +352,10 @@ class AmdaObjectMgr { |
340 | 352 | /* |
341 | 353 | * Modify Parameter[TT...]/Folder |
342 | 354 | */ |
343 | - function modifyObject($p){ | |
344 | - | |
345 | - if ($this->renameOnly($p)) { | |
355 | + function modifyObject($p) | |
356 | + { | |
357 | + if ($this->renameOnly($p)) | |
358 | + { | |
346 | 359 | $p->leaf = 1; |
347 | 360 | return $this->renameObject($p); |
348 | 361 | } |
... | ... | @@ -354,14 +367,15 @@ class AmdaObjectMgr { |
354 | 367 | } |
355 | 368 | |
356 | 369 | |
357 | - function validNameObject($p){ | |
358 | - | |
370 | + function validNameObject($p) | |
371 | + { | |
359 | 372 | if (!isset($p->name) || ($p->name == "")) |
360 | 373 | return array('valid' => false, 'error' => 'Name is required'); |
361 | 374 | if ($p->leaf) |
362 | 375 | $alreadyExist = $this -> objectExistsByName($p->name, $this->objTagName); |
363 | 376 | else |
364 | 377 | $alreadyExist = $this -> folderExistsByName($p->name); |
378 | + | |
365 | 379 | if ($alreadyExist) |
366 | 380 | return array('valid' => false, 'error' => 'This name already exists in this subtree!'); |
367 | 381 | |
... | ... | @@ -369,6 +383,5 @@ class AmdaObjectMgr { |
369 | 383 | } |
370 | 384 | |
371 | 385 | function getObject($id){} |
372 | - | |
373 | 386 | } |
374 | 387 | ?> | ... | ... |