IHMSharedObjectsClass.php
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @class IHMSharedObjectsClass
* @brief Shared objects helper
* @details
*/
class IHMSharedObjectsClass {
/*
* @brief Constructor
*/
function __construct()
{
}
public static function getPath($object_type, $object_id) {
$objectDir = "";
switch ($object_type) {
case 'timeTable' :
$objectDir = "TT";
break;
case 'catalog' :
$objectDir = "CAT";
break;
default:
return array('success' => false, 'message' => 'Unknown shared object type');
}
$treeFilePath = IHMConfigClass::getSharedTreeFilePath();
if (!file_exists($treeFilePath))
return array('success' => false, 'message' => 'Cannot retrieve shared objects file');
$dom = new DomDocument("1.0");
if (!$dom->load($treeFilePath))
return array('success' => false, 'message' => 'Cannot load shared objects file');
$objectRootNodeId = 'shared'.$object_type.'-treeRootNode';
$objectRootNode = $dom->getElementById($objectRootNodeId);
if (!isset($objectRootNode))
return array('success' => false, 'message' => 'Cannot retrieve shared objects root node');
$folderNodes = $objectRootNode->getElementsByTagName("folder");
foreach ($folderNodes as $folderNode) {
$objectNodes = $folderNode->getElementsByTagName($object_type);
foreach ($objectNodes as $objectNode) {
if ($objectNode->getAttribute('xml:id') == $object_id) {
switch ($object_type) {
}
return array('success' => true, 'path' => IHMConfigClass::getSharedPath().$objectDir."/".$folderNode->getAttribute('name').'/data/'.$object_id.".xml");
}
}
}
return array('success' => false, 'message' => 'Cannot retrieve shared object with id '.$object_id);
}
}
?>