IHMTTCatLoaderClass.php
6.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* @class IHMTTCatLoaderClass
* @brief Loader for IHM TimeTables and Catalogs properties
* @details
*/
class IHMTTCatLoaderClass
{
protected $ttCatList = null;
private static $userTTCatFile = 'Tt.xml';
private static $mgrUserTTListNode = 'timetabList';
private static $mgrUserTTEltNode = 'timetab';
private static $mgrUserCatListNode = 'catalogList';
private static $mgrUserCatEltNode = 'catalog';
private static $mgrUserTTCatEltIdAtt = 'xml:id';
private static $mgrUserTTCatEltNameAtt = 'name';
private static $mgrUserTTCatEltNbIntAtt = 'intervals';
private static $mgrUserTTCatFolderNode = 'folder';
private static $mgrUserTTCatFolderIdAtt = 'xml:id';
private static $mgrUserTTCatFolderNameAtt = 'name';
private static $mgrSharedTTListNode = 'timeTableList';
private static $mgrSharedTTEltNode = 'timeTable';
private static $mgrSharedCatListNode = 'catalogList';
private static $mgrSharedCatEltNode = 'catalog';
private static $mgrSharedTTCatEltIdAtt = 'xml:id';
private static $mgrSharedTTCatEltNameAtt = 'name';
private static $mgrSharedTTCatEltNbIntAtt = 'nbIntervals';
private static $mgrSharedTTCatFolderNode = 'folder';
private static $mgrSharedTTCatFolderIdAtt = 'xml:id';
private static $mgrSharedTTCatFolderNameAtt = 'name';
/*
* @brief Constructor
*/
function __construct()
{
}
/*
* @brief Get info about a TT or a catalog from id
*/
public function getTTCatInfoFromId($id)
{
if (!isset($this->ttCatList)) {
$this->ttCatList = $this->loadTTCatManagerFiles();
}
if (!array_key_exists($id, $this->ttCatList)) {
return array("success" => false, "message" => "Cannot retrieve TT or catalog");
}
return array("success" => true, "info" => $this->ttCatList[$id]);
}
/*
* @brief Get parameters from id (empty for a TT)
*/
public function getCatalogParameters($id)
{
$info = $this->getTTCatInfoFromId($id);
if (!$info["success"]) {
return $info;
}
if (!$info["info"]["isCatalog"]) {
return array("success" => TRUE, "parameters" => array());
}
$dom = new DomDocument("1.0");
if (!$dom->load($info["info"]["path"])) {
return array("success" => FALSE, "message" => "Cannot open catalog ".$id);
}
$parametersNodes = $dom->getElementsByTagName("parameters");
if ($parametersNodes->length == 0) {
return array("success" => FALSE, "message" => "Cannot retrieve parameters node in catalog ".$id);
}
$parametersNode = $parametersNodes->item(0);
$parameterNodes = $parametersNode->getElementsByTagName("parameter");
$parameters = array();
foreach ($parameterNodes as $parameterNode) {
$parameters[] = array(
"id" => $parameterNode->getAttribute("id"),
"name" => $parameterNode->getAttribute("name"),
"size" => $parameterNode->getAttribute("size"),
"type" => $parameterNode->getAttribute("type"),
"unit" => $parameterNode->getAttribute("unit"),
"description" => $parameterNode->getAttribute("description"),
"ucd" => $parameterNode->getAttribute("ucd"),
"utype" => $parameterNode->getAttribute("utype"),
);
}
return array("success" => TRUE, "parameters" => $parameters);
}
/*
* @brief Load all TT and catalogs from manager files
*/
private function loadTTCatManagerFiles()
{
if (isset($this->ttCatList)) {
return $this->ttCatList;
}
return $this->loadUserTTCatManagerFile() + $this->loadSharedTTCatManagerFile();
}
/*
* @brief Load user TT and cat manager file
*/
private function loadUserTTCatManagerFile()
{
//load xml file
$dom = new DomDocument("1.0");
if (!$dom->load(IHMConfigClass::getUserWSPath() . '/' . self::$userTTCatFile))
return array();
$ttCat = array();
//get TT
$listNodes = $dom->getElementsByTagName(self::$mgrUserTTListNode);
if ($listNodes->length > 0) {
$this->getEltRecursively($listNodes->item(0), FALSE, FALSE, array(), $ttCat);
}
//get catalogs
$listNodes = $dom->getElementsByTagName(self::$mgrUserCatListNode);
if ($listNodes->length > 0) {
$this->getEltRecursively($listNodes->item(0), FALSE, TRUE, array(), $ttCat);
}
return $ttCat;
}
/*
* @brief Load shared objects manager file
*/
private function loadSharedTTCatManagerFile()
{
//load xml file
$dom = new DomDocument("1.0");
if (!$dom->load(IHMConfigClass::getSharedTreeFilePath()))
return array();
$ttCat = array();
//get TT
$listNodes = $dom->getElementsByTagName(self::$mgrSharedTTListNode);
if ($listNodes->length > 0) {
$this->getEltRecursively($listNodes->item(0), TRUE, FALSE, array(), $ttCat);
}
//get catalogs
$listNodes = $dom->getElementsByTagName(self::$mgrSharedCatListNode);
if ($listNodes->length > 0) {
$this->getEltRecursively($listNodes->item(0), TRUE, TRUE, array(), $ttCat);
}
return $ttCat;
}
private function getEltRecursively($baseNode, $isShared, $isCatalog, $folders, &$elts) {
if ($isShared) {
$basePath = IHMConfigClass::getSharedPath();
if ($isCatalog) {
$eltNode = self::$mgrSharedCatEltNode;
$basePath .= "/CAT";
}
else {
$eltNode = self::$mgrSharedTTEltNode;
$basePath .= "/TT";
}
$eltIdAtt = self::$mgrSharedTTCatEltIdAtt;
$eltNameAtt = self::$mgrSharedTTCatEltNameAtt;
$eltNbIntAtt = self::$mgrSharedTTCatEltNbIntAtt;
$folderNode = self::$mgrSharedTTCatFolderNode;
$folderIdAtt = self::$mgrSharedTTCatFolderIdAtt;
$folderNameAtt = self::$mgrSharedTTCatFolderNameAtt;
if (!empty($folders)) {
$basePath .= "/".$folders[0]["name"]."/data";
}
}
else {
$basePath = IHMConfigClass::getUserTTPath();
if ($isCatalog) {
$eltNode = self::$mgrUserCatEltNode;
}
else {
$eltNode = self::$mgrUserTTEltNode;
}
$eltIdAtt = self::$mgrUserTTCatEltIdAtt;
$eltNameAtt = self::$mgrUserTTCatEltNameAtt;
$eltNbIntAtt = self::$mgrUserTTCatEltNbIntAtt;
$folderNode = self::$mgrUserTTCatFolderNode;
$folderIdAtt = self::$mgrUserTTCatFolderIdAtt;
$folderNameAtt = self::$mgrUserTTCatFolderNameAtt;
}
$eltNodes = $baseNode->getElementsByTagName($eltNode);
foreach ($eltNodes as $node) {
$elts[$node->getAttribute($eltIdAtt)] = array(
"id" => $node->getAttribute($eltIdAtt),
"name" => $node->getAttribute($eltNameAtt),
"nbIntervals" => $node->getAttribute($eltNbIntAtt),
"folders" => $folders,
"path" => $basePath . "/" . $node->getAttribute($eltIdAtt). ".xml",
"isShared" => $isShared,
"isCatalog" => $isCatalog,
);
}
$folderNodes = $baseNode->getElementsByTagName($folderNode);
foreach ($folderNodes as $node) {
$crt_folders = $folders;
$crt_folders[] = array(
"id" => $node->getAttribute($folderIdAtt),
"name" => $node->getAttribute($folderNameAtt),
);
$this->getEltRecursively($node, $isShared, $isCatalog, $crt_folders, $elts);
}
}
}