CatalogCacheMgr.php
2.68 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
<?php
/**
* @class CatalogCacheMgr
*/
class CatalogCacheMgr extends TimeTableCacheMgr
{
const DEFAULT_PARAM_ID_PREFIX = 'cat_param_id_';
function __construct() {
$this->objectMgr = new CatalogMgr();
}
protected function getCacheFileName() {
return "cacheCat";
}
protected function resetCache($options = array()) {
$this->cache = new CatalogCacheObject();
if (!empty($options['nparams'])) {
for ($i = 0; $i < (int)$options['nparams']; $i++) {
$this->cache->addParameter(CatalogCacheMgr::DEFAULT_PARAM_ID_PREFIX.(string)($i+1), 'column_'.(string)($i+1), 1, 0);
}
}
else if (!empty($options['parameters'])) {
$index = 0;
foreach ($options['parameters'] as $parameter) {
if (array_key_exists('id',$parameter) && !empty($parameter['id'])) {
$id = $parameter['id'];
}
else if (array_key_exists('ID',$parameter) && !empty($parameter['ID'])) {
$id = $parameter['ID'];
}
else {
$id = 'cat_param_id_'.$index;
}
$this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']));
++$index;
}
}
return array('parameters' => $this->cache->getParametersInfo());
}
protected function loadAdditionalDescription($options) {
$params_desc = $this->objectMgr->getCatalogParamDescription($options);
if (!$params_desc['success']) {
return array();
}
return array('parameters' => $params_desc['parameters']);
}
public function initFromUploadedFile($name, $format)
{
$result = parent::initFromUploadedFile($name, $format);
if (!$result['success']) {
return $result;
}
$info = $this->objectMgr->getUploadedObject($name, $format,TRUE);
foreach ($info['parameters'] as $parameter) {
$this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']));
}
return $result+ array('parameters' => $info['parameters']);
}
public function initFromTimeTable($id, $nbParams)
{
$params = $this->resetCache(array('nparams' => $nbParams));
$ttMgr= new TimeTableMgr();
$intervals_res = $ttMgr->loadIntervalsFromObject($id);
if (!$intervals_res['success'])
return $intervals_res;
foreach ($intervals_res['intervals'] as $interval)
{
//Add interval
$this->cache->addInterval($interval);
}
unset($intervals_res);
//Update cache
$this->cache->updateIndexes();
//Save cache file
return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(), 'parameters' => $this->cache->getParametersInfo());
}
}
?>