Commit a242857a1d2d16883c2cec0fc1299d927bdc2b57
1 parent
6ee28339
Exists in
master
and in
66 other branches
Shared objects
Showing
3 changed files
with
91 additions
and
8 deletions
Show diff stats
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
... | ... | @@ -27,7 +27,9 @@ class IHMConfigClass |
27 | 27 | |
28 | 28 | private static $requestDir = "RES/"; |
29 | 29 | |
30 | - private static $sharedTTDir = "SHAREDTT/"; | |
30 | + private static $sharedDir = "shared_data/"; | |
31 | + | |
32 | + private static $sharedTreeFile = "SharedObjectTree.xml"; | |
31 | 33 | |
32 | 34 | private static $ttDir = "TT/"; |
33 | 35 | |
... | ... | @@ -122,9 +124,14 @@ class IHMConfigClass |
122 | 124 | return PARAMS_LOCALINFO_DIR; |
123 | 125 | } |
124 | 126 | |
125 | - public static function getSharedTTPath() | |
127 | + public static function getSharedPath() | |
128 | + { | |
129 | + return IHM_SRC_DIR.self::$sharedDir; | |
130 | + } | |
131 | + | |
132 | + public static function getSharedTreeFilePath() | |
126 | 133 | { |
127 | - return IHM_SRC_DIR.self::$dataDir.self::$sharedTTDir.self::$ttDir; | |
134 | + return self::getSharedPath().self::$sharedTreeFile; | |
128 | 135 | } |
129 | 136 | |
130 | 137 | public static function getUserTTPath() |
... | ... |
src/InputOutput/IHMImpl/Params/IHMInputOutputParamsAbstractClass.php
... | ... | @@ -74,12 +74,24 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface |
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - if (strpos($tt->id, "sharedtt_") === 0) | |
78 | - $ttPath = IHMConfigClass::getSharedTTPath(); | |
79 | - else | |
77 | + if (strpos($tt->id, "sharedtimeTable_") === 0) { | |
78 | + $result = IHMSharedObjectsClass::getPath("timeTable", $tt->id); | |
79 | + if (!$result['success']) | |
80 | + throw new Exception($result['message']); | |
81 | + $ttPath = $result['path']; | |
82 | + } | |
83 | + else if (strpos($tt->id, "sharedcatalog_") === 0) { | |
84 | + $result = IHMSharedObjectsClass::getPath("catalog", $tt->id); | |
85 | + if (!$result['success']) | |
86 | + throw new Exception($result['message']); | |
87 | + $ttPath = $result['path']; | |
88 | + } | |
89 | + else { | |
80 | 90 | $ttPath = IHMConfigClass::getUserTTPath(); |
81 | - $ttPath .= ($tt->id.".xml"); | |
82 | - if (strpos($tt->id, "cat_") === 0) | |
91 | + $ttPath .= ($tt->id.".xml"); | |
92 | + } | |
93 | + | |
94 | + if ((strpos($tt->id, "cat_") === 0) || (strpos($tt->id, "sharedcatalog_") === 0)) | |
83 | 95 | $timesNode->addCatalog($ttPath, $tt->{'timeTableName'}, $ttIntIndex); |
84 | 96 | else |
85 | 97 | $timesNode->addTimeTable($ttPath, $tt->{'timeTableName'}, $ttIntIndex); |
... | ... |
src/InputOutput/IHMImpl/Tools/IHMSharedObjectsClass.php
0 โ 100644
... | ... | @@ -0,0 +1,64 @@ |
1 | +<?php | |
2 | + | |
3 | +/** | |
4 | + * @class IHMSharedObjectsClass | |
5 | + * @brief Shared objects helper | |
6 | + * @details | |
7 | + */ | |
8 | +class IHMSharedObjectsClass { | |
9 | + /* | |
10 | + * @brief Constructor | |
11 | + */ | |
12 | + function __construct() | |
13 | + { | |
14 | + } | |
15 | + | |
16 | + public static function getPath($object_type, $object_id) { | |
17 | + $objectDir = ""; | |
18 | + switch ($object_type) { | |
19 | + case 'timeTable' : | |
20 | + $objectDir = "TT"; | |
21 | + break; | |
22 | + case 'catalog' : | |
23 | + $objectDir = "CAT"; | |
24 | + break; | |
25 | + default: | |
26 | + return array('success' => false, 'message' => 'Unknown shared object type'); | |
27 | + } | |
28 | + | |
29 | + $treeFilePath = IHMConfigClass::getSharedTreeFilePath(); | |
30 | + | |
31 | + if (!file_exists($treeFilePath)) | |
32 | + return array('success' => false, 'message' => 'Cannot retrieve shared objects file'); | |
33 | + | |
34 | + $dom = new DomDocument("1.0"); | |
35 | + if (!$dom->load($treeFilePath)) | |
36 | + return array('success' => false, 'message' => 'Cannot load shared objects file'); | |
37 | + | |
38 | + $objectRootNodeId = 'shared'.$object_type.'-treeRootNode'; | |
39 | + | |
40 | + $objectRootNode = $dom->getElementById($objectRootNodeId); | |
41 | + | |
42 | + if (!isset($objectRootNode)) | |
43 | + return array('success' => false, 'message' => 'Cannot retrieve shared objects root node'); | |
44 | + | |
45 | + $folderNodes = $objectRootNode->getElementsByTagName("folder"); | |
46 | + | |
47 | + foreach ($folderNodes as $folderNode) { | |
48 | + $objectNodes = $folderNode->getElementsByTagName($object_type); | |
49 | + | |
50 | + foreach ($objectNodes as $objectNode) { | |
51 | + if ($objectNode->getAttribute('xml:id') == $object_id) { | |
52 | + switch ($object_type) { | |
53 | + | |
54 | + } | |
55 | + return array('success' => true, 'path' => IHMConfigClass::getSharedPath().$objectDir."/".$folderNode->getAttribute('name').'/data/'.$object_id.".xml"); | |
56 | + } | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + return array('success' => false, 'message' => 'Cannot retrieve shared object with id '.$object_id); | |
61 | + } | |
62 | +} | |
63 | + | |
64 | +?> | |
0 | 65 | \ No newline at end of file |
... | ... |