Commit 342b20ca3f447aab0b0670ca1dd45d7de9aa2c5d
1 parent
0fea5567
Exists in
master
and in
100 other branches
Fix inheritence between TimeTableCacheMgr and CatalogCacheMgr
Showing
11 changed files
with
175 additions
and
298 deletions
Show diff stats
js/app/models/TimeTable.js
1 | 1 | /** |
2 | 2 | * Project : AMDA-NG |
3 | - * Name : timeTable.js | |
3 | + * Name : timeTable.js | |
4 | 4 | * Description : TimeTable Business Object Definition |
5 | 5 | * @class amdaModel.TimeTable |
6 | - * @extends amdaModel.AmdaObject | |
7 | - * | |
6 | + * @extends amdaModel.AmdaObject | |
7 | + * | |
8 | 8 | * @author cdarmon |
9 | 9 | * @version $Id: TimeTable.js 1907 2013-11-25 15:59:42Z myriam $ |
10 | 10 | ****************************************************************************** |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | |
17 | 17 | |
18 | 18 | Ext.define('amdaModel.Interval', { |
19 | - extend: 'amdaModel.AmdaObject', | |
19 | + extend: 'amdaModel.AmdaObject', | |
20 | 20 | fields: [ |
21 | 21 | { |
22 | 22 | name: 'id', |
... | ... | @@ -80,19 +80,19 @@ Ext.define('amdaModel.Interval', { |
80 | 80 | { name: 'isNew', type : 'boolean', defaultValue: false}, |
81 | 81 | { name: 'isModified', type : 'boolean', defaultValue: false} |
82 | 82 | ], |
83 | - | |
83 | + | |
84 | 84 | getJsonValues : function () { |
85 | 85 | var values = new Object(); |
86 | 86 | values.start = this.get('start'); |
87 | 87 | values.stop = this.get('stop'); |
88 | 88 | return values; |
89 | 89 | }, |
90 | - | |
90 | + | |
91 | 91 | proxy: { |
92 | 92 | type: 'direct', |
93 | 93 | api : |
94 | 94 | { |
95 | - read : AmdaAction.readTTCacheIntervals | |
95 | + read : AmdaAction.readCacheIntervals | |
96 | 96 | }, |
97 | 97 | extraParams : {'typeTT' : ''}, |
98 | 98 | reader: |
... | ... | @@ -102,8 +102,8 @@ Ext.define('amdaModel.Interval', { |
102 | 102 | totalProperty : 'totalCount' |
103 | 103 | } |
104 | 104 | } |
105 | - | |
106 | - /* | |
105 | + | |
106 | + /* | |
107 | 107 | validations: [ |
108 | 108 | {type: 'presence', field: 'age'}, |
109 | 109 | {type: 'length', field: 'name', min: 2}, |
... | ... | @@ -112,49 +112,49 @@ Ext.define('amdaModel.Interval', { |
112 | 112 | {type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/} |
113 | 113 | ], |
114 | 114 | */ |
115 | - | |
115 | + | |
116 | 116 | }); |
117 | 117 | |
118 | 118 | |
119 | 119 | Ext.define('amdaModel.TimeTable', { |
120 | - | |
120 | + | |
121 | 121 | extend: 'amdaModel.AmdaObject', |
122 | - | |
122 | + | |
123 | 123 | fields : [ |
124 | 124 | {name: 'fromPlugin', type: 'boolean', defaultValue: false}, |
125 | 125 | {name: 'created', type: 'date'}, |
126 | 126 | {name: 'description', type: 'string'}, |
127 | - {name: 'history', type: 'string'}, | |
127 | + {name: 'history', type: 'string'}, | |
128 | 128 | {name: 'nbIntervals', type: 'int'}, |
129 | 129 | {name: 'objName', type: 'string', defaultValue: ""}, |
130 | 130 | {name: 'objFormat', type: 'string', defaultValue: ""}, |
131 | 131 | {name: 'folderId', type: 'string', defaultValue: ""}, |
132 | 132 | {name: 'cacheToken', type: 'string', defaultValue: ""}, |
133 | 133 | {name: 'relatedCatalogId', type: 'string', defaultValue: ""} |
134 | - ], | |
135 | - | |
134 | + ], | |
135 | + | |
136 | 136 | /*commit: function(){ |
137 | 137 | this.callParent(arguments); |
138 | - | |
138 | + | |
139 | 139 | // fix the modifications for its intervals |
140 | - Ext.Array.each(this.get('intervals'), function(item, index, all) { | |
141 | -//TODO check if JSON object should be processed | |
142 | - if (item.$className) { | |
140 | + Ext.Array.each(this.get('intervals'), function(item, index, all) { | |
141 | +//TODO check if JSON object should be processed | |
142 | + if (item.$className) { | |
143 | 143 | item.commit(); |
144 | - } | |
144 | + } | |
145 | 145 | }); |
146 | - | |
146 | + | |
147 | 147 | },*/ |
148 | - | |
148 | + | |
149 | 149 | // hasMany: {model: 'amdaModel.Interval', name: 'intervals'}, |
150 | - | |
150 | + | |
151 | 151 | /** |
152 | 152 | * get TimeTable values to sent to Server |
153 | 153 | * @return object |
154 | 154 | */ |
155 | 155 | //TODO utf8_encode() and Ext.urlEncode() ??? |
156 | 156 | getJsonValues : function (hasId) { |
157 | - var values = new Object(); | |
157 | + var values = new Object(); | |
158 | 158 | if (hasId) { |
159 | 159 | values.id = this.get('id'); |
160 | 160 | } |
... | ... | @@ -171,13 +171,10 @@ Ext.define('amdaModel.TimeTable', { |
171 | 171 | values.folderId = this.get('folderId'); |
172 | 172 | values.nbIntervals = this.get('nbIntervals'); |
173 | 173 | values.cacheToken = this.get('cacheToken'); |
174 | - | |
174 | + | |
175 | 175 | values.leaf = true; |
176 | 176 | values.nodeType = amdaModel.TimeTableNode.nodeType; |
177 | 177 | return values; |
178 | 178 | } |
179 | 179 | |
180 | 180 | }); |
181 | - | |
182 | - | |
183 | - | ... | ... |
js/app/views/CatalogUI.js
... | ... | @@ -98,7 +98,7 @@ Ext.define('amdaUI.CatalogUI', { |
98 | 98 | var row = this.TTGrid.getStore().getTotalCount(); |
99 | 99 | var me = this; |
100 | 100 | this.TTGrid.getSelectionModel().deselectAll(); |
101 | - AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) { | |
101 | + AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) { | |
102 | 102 | this.status = result.status; |
103 | 103 | if (!this.TTGrid.getStore().loading) { |
104 | 104 | this.TTGrid.getStore().reload({ |
... | ... | @@ -395,7 +395,7 @@ Ext.define('amdaUI.CatalogUI', { |
395 | 395 | remoteSort: true, |
396 | 396 | proxy: { |
397 | 397 | type: 'direct', |
398 | - api : { read : AmdaAction.readTTCacheIntervals }, | |
398 | + api : { read : AmdaAction.readCacheIntervals }, | |
399 | 399 | // remplir automatiquement tt, sharedtt , catalog, shared catalog |
400 | 400 | extraParams : {'typeTT' : 'catalog'}, |
401 | 401 | reader: |
... | ... | @@ -466,7 +466,7 @@ Ext.define('amdaUI.CatalogUI', { |
466 | 466 | } |
467 | 467 | else { |
468 | 468 | //From existing TT file |
469 | - AmdaAction.initObjectCacheFromTT(this.object.get('id'), typeTT, this.onAfterInit, this); | |
469 | + AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, this.onAfterInit, this); | |
470 | 470 | } |
471 | 471 | } |
472 | 472 | //Statistical plugin |
... | ... | @@ -588,16 +588,17 @@ Ext.define('amdaUI.CatalogUI', { |
588 | 588 | // Only update the record if the new value is different than the |
589 | 589 | // startValue. When the view refreshes its el will gain focus |
590 | 590 | if (!record.isEqual(value, startValue)) { |
591 | - var obj = {}; | |
592 | - | |
593 | - obj['cacheId'] = record.get('cacheId'); | |
594 | - obj['isCatalog'] = true; | |
595 | - obj[activeColumn.dataIndex] = value; | |
591 | + var obj = { | |
592 | + 'cacheId' : record.get('cacheId'), | |
593 | + 'isCatalog' : true, | |
594 | + 'data' : {} | |
595 | + }; | |
596 | + obj['data']['activeColumn.dataIndex'] = value; | |
596 | 597 | |
597 | 598 | //Interval is modified on the server side |
598 | 599 | me.editing = true; |
599 | 600 | |
600 | - AmdaAction.modifyTTCacheInterval(obj, function (result, e) { | |
601 | + AmdaAction.modifyCacheInterval(obj, function (result, e) { | |
601 | 602 | var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); |
602 | 603 | if (module) |
603 | 604 | module.getUiContent().status = result.status; |
... | ... | @@ -647,7 +648,7 @@ Ext.define('amdaUI.CatalogUI', { |
647 | 648 | this.TTGrid.getSelectionModel().deselectAll(); |
648 | 649 | |
649 | 650 | var me = this; |
650 | - AmdaAction.addTTCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) { | |
651 | + AmdaAction.addCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) { | |
651 | 652 | this.status = result.status; |
652 | 653 | if (!this.TTGrid.getStore().loading) { |
653 | 654 | this.TTGrid.getStore().reload({ | ... | ... |
js/app/views/TimeTableUI.js
... | ... | @@ -139,7 +139,7 @@ Ext.define('amdaUI.TimeTableUI', { |
139 | 139 | else |
140 | 140 | { |
141 | 141 | //From existing TT file |
142 | - AmdaAction.initObjectCacheFromTT(this.object.get('id'), typeTT, onAfterInit); | |
142 | + AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, onAfterInit); | |
143 | 143 | } |
144 | 144 | } |
145 | 145 | }, |
... | ... | @@ -249,7 +249,7 @@ Ext.define('amdaUI.TimeTableUI', { |
249 | 249 | var row = this.TTGrid.getStore().getTotalCount(); |
250 | 250 | var me = this; |
251 | 251 | this.TTGrid.getSelectionModel().deselectAll(); |
252 | - AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) { | |
252 | + AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) { | |
253 | 253 | this.status = result.status; |
254 | 254 | if (!this.TTGrid.getStore().loading) { |
255 | 255 | this.TTGrid.getStore().reload({ |
... | ... | @@ -405,28 +405,18 @@ Ext.define('amdaUI.TimeTableUI', { |
405 | 405 | // Only update the record if the new value is different than the |
406 | 406 | // startValue. When the view refreshes its el will gain focus |
407 | 407 | if (!record.isEqual(value, startValue)) { |
408 | - var obj = null; | |
409 | - if (activeColumn.dataIndex == 'start') | |
410 | - obj = { | |
411 | - 'cacheId' : record.get('cacheId'), | |
412 | - 'start' : value | |
413 | - }; | |
414 | - else if (activeColumn.dataIndex == 'stop') | |
415 | - obj = { | |
416 | - 'cacheId' : record.get('cacheId'), | |
417 | - 'stop' : value | |
418 | - }; | |
419 | - else | |
420 | - { | |
421 | - me.editing = false; | |
422 | - return; | |
423 | - } | |
408 | + var obj = { | |
409 | + 'cacheId' : record.get('cacheId'), | |
410 | + 'isCatalog' : false, | |
411 | + 'data' : {} | |
412 | + }; | |
413 | + obj['data'][activeColumn.dataIndex] = value; | |
424 | 414 | |
425 | 415 | //context.grid.getSelectionModel().deselectAll(); |
426 | 416 | //Interval is modified on the server side |
427 | 417 | me.editing = true; |
428 | 418 | |
429 | - AmdaAction.modifyTTCacheInterval(obj, function (result, e) { | |
419 | + AmdaAction.modifyCacheInterval(obj, function (result, e) { | |
430 | 420 | |
431 | 421 | var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id); |
432 | 422 | if (ttModule) |
... | ... | @@ -585,7 +575,7 @@ Ext.define('amdaUI.TimeTableUI', { |
585 | 575 | this.TTGrid.getSelectionModel().deselectAll(); |
586 | 576 | |
587 | 577 | var me = this; |
588 | - AmdaAction.addTTCacheInterval({'index' : row}, function (result, e) { | |
578 | + AmdaAction.addCacheInterval({'index' : row}, function (result, e) { | |
589 | 579 | this.status = result.status; |
590 | 580 | if (!this.TTGrid.getStore().loading) { |
591 | 581 | this.TTGrid.getStore().reload({ | ... | ... |
php/TTCacheDump.php
1 | 1 | <?php |
2 | -define ("USERTTDIR", "/home/benjamin/AMDA-GIT/AMDA/AMDA_IHM/data/testKernel/TT/"); | |
2 | +/*define ("USERWSDIR", "/home/amda_admin/AMDA-GIT/AMDA_IHM/data/testKernel/WS/"); | |
3 | +define ("USERTTDIR", "/home/amda_admin/AMDA-GIT/AMDA_IHM/data/testKernel/TT/"); | |
3 | 4 | |
4 | 5 | require_once("classes/AmdaObjectMgr.php"); |
5 | 6 | require_once("classes/TimeTableMgr.php"); |
7 | +require_once("classes/CatalogMgr.php"); | |
6 | 8 | require_once("classes/TimeTableCacheMgr.php"); |
9 | +require_once("classes/TimeTableCacheObject.php"); | |
10 | +require_once("classes/IntervalCacheObject.php"); | |
11 | +require_once("classes/CatalogCacheMgr.php"); | |
12 | +*/ | |
7 | 13 | |
8 | -$cacheMgr = new TimeTableCacheMgr(); | |
14 | +require_once("config.php"); | |
15 | + | |
16 | +define ("USERWSDIR", "/home/amda_admin/AMDA-GIT/AMDA_IHM/data/testKernel/WS/"); | |
17 | +define ("USERTTDIR", "/home/amda_admin/AMDA-GIT/AMDA_IHM/data/testKernel/TT/"); | |
18 | + | |
19 | +$cacheMgr = new CatalogCacheMgr(); | |
9 | 20 | |
10 | 21 | $cacheMgr->dump(); |
11 | 22 | ... | ... |
php/classes/AmdaAction.php
... | ... | @@ -1079,7 +1079,7 @@ class AmdaAction |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
1082 | - public function initObjectCacheFromTT($id, $type) | |
1082 | + public function initObjectCacheFromObject($id, $type) | |
1083 | 1083 | { |
1084 | 1084 | if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); |
1085 | 1085 | else $cacheMgr = new TimeTableCacheMgr(); |
... | ... | @@ -1121,7 +1121,7 @@ class AmdaAction |
1121 | 1121 | return $cacheMgr->initFromUploadedFile($name, $format); |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - public function readTTCacheIntervals($o) | |
1124 | + public function readCacheIntervals($o) | |
1125 | 1125 | { |
1126 | 1126 | if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) $cacheMgr = new CatalogCacheMgr(); |
1127 | 1127 | else $cacheMgr = new TimeTableCacheMgr(); |
... | ... | @@ -1151,7 +1151,7 @@ class AmdaAction |
1151 | 1151 | return $cacheMgr->saveInObject($o->ttId,$o->action,$o->cacheToken); |
1152 | 1152 | } |
1153 | 1153 | |
1154 | - public function addTTCacheInterval($o) | |
1154 | + public function addCacheInterval($o) | |
1155 | 1155 | { |
1156 | 1156 | if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr(); |
1157 | 1157 | else $cacheMgr = new TimeTableCacheMgr(); |
... | ... | @@ -1167,16 +1167,15 @@ class AmdaAction |
1167 | 1167 | return $cacheMgr->removeIntervalFromId($id); |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - public function modifyTTCacheInterval($o) | |
1170 | + public function modifyCacheInterval($o) | |
1171 | 1171 | { |
1172 | 1172 | if ($o->isCatalog) |
1173 | 1173 | { |
1174 | 1174 | $cacheMgr = new CatalogCacheMgr(); |
1175 | - return $cacheMgr->modifyIntervalFromId($o); | |
1176 | 1175 | } |
1177 | 1176 | else $cacheMgr = new TimeTableCacheMgr(); |
1178 | 1177 | |
1179 | - return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop); | |
1178 | + return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->data); | |
1180 | 1179 | } |
1181 | 1180 | |
1182 | 1181 | public function operationTTCacheIntervals($extendTime, $shiftTime) | ... | ... |
php/classes/CatalogCacheIntervalObject.php
... | ... | @@ -98,7 +98,12 @@ class CatalogCacheIntervalObject extends TimeTableCacheIntervalObject |
98 | 98 | |
99 | 99 | public function dump() |
100 | 100 | { |
101 | - echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; | |
101 | + parent::dump(); | |
102 | + echo " parameters = "; | |
103 | + foreach ($this->params as $param) { | |
104 | + echo $param.", "; | |
105 | + } | |
106 | + echo PHP_EOL; | |
102 | 107 | } |
103 | 108 | } |
104 | 109 | ... | ... |
php/classes/CatalogCacheMgr.php
... | ... | @@ -6,11 +6,8 @@ |
6 | 6 | |
7 | 7 | class CatalogCacheMgr extends TimeTableCacheMgr |
8 | 8 | { |
9 | - protected $objectMgr = null; | |
10 | - protected $cache = null; | |
11 | 9 | |
12 | 10 | function __construct() { |
13 | - | |
14 | 11 | $this->objectMgr = new CatalogMgr(); |
15 | 12 | } |
16 | 13 | |
... | ... | @@ -22,208 +19,93 @@ class CatalogCacheMgr extends TimeTableCacheMgr |
22 | 19 | $this->cache = new CatalogCacheObject(); |
23 | 20 | } |
24 | 21 | |
22 | + public function initObjectCache($options = array()) { | |
23 | + $result = parent::initObjectCache($options); | |
24 | + if (!$result['success']) { | |
25 | + return $result; | |
26 | + } | |
25 | 27 | |
26 | - public function initFromTmpObject($folderId, $name) { | |
27 | - | |
28 | - //Create new cache | |
29 | - $this->resetCache(); | |
30 | - | |
31 | - //Load intervals from TmpObject file (Statistics Module) | |
32 | - $intervals_res = $this->objectMgr->getTmpObject($folderId, $name); | |
28 | + //init parameters | |
29 | + $nparams = isset($options['nparams']) ? $options['nparams'] : 1; | |
30 | + $this->cache->setParamsNumber((int)$nparams); | |
33 | 31 | |
34 | - if (!isset($intervals_res)) | |
35 | - return array('success' => false, 'message' => 'Cannot get Tmp Object'); | |
32 | + $paramHeaders = array(); | |
36 | 33 | |
37 | - if (array_key_exists('intervals', $intervals_res)) | |
38 | - { | |
39 | - foreach ($intervals_res['intervals'] as $interval) | |
40 | - { | |
41 | - //Add interval | |
42 | - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); | |
34 | + for ($i = 0; $i < (int)$nparams; $i++) { | |
35 | + $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); | |
36 | + $paramHeaders[$i]['name'] = 'column_'.(string)($i+1); | |
37 | + $paramHeaders[$i]['size'] = 1; | |
38 | + $paramHeaders[$i]['type'] = 'Float'; | |
43 | 39 | |
44 | - } | |
45 | 40 | } |
46 | - | |
47 | - $this->cache->setIsModified(true); | |
48 | - | |
49 | - $paramHeaders = $intervals_res['parameters']; | |
50 | - | |
51 | - $this->cache->setParamsNumber(count($paramHeaders)); | |
52 | 41 | $this->cache->setParamsSizes($paramHeaders); |
53 | 42 | $this->cache->setParamsTypes($paramHeaders); |
54 | - | |
55 | - unset($intervals_res); | |
56 | - | |
57 | - //Update cache | |
58 | - $this->cache->updateIndexes(); | |
59 | - | |
60 | 43 | //Save cache file |
61 | - return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), | |
62 | - 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); | |
44 | + return $result + array('parameters' => $paramHeaders); | |
63 | 45 | } |
64 | 46 | |
65 | - public function initFromUploadedFile($name, $format) | |
47 | + public function initFromObject($id, $type) | |
66 | 48 | { |
67 | - //Create new cache | |
68 | - $this->resetCache(); | |
69 | - | |
70 | - //Load intervals from uploaded file | |
71 | - $intervals_res = $this->objectMgr->getUploadedObject($name, $format); | |
72 | - | |
73 | - if (!isset($intervals_res)) | |
74 | - return array('success' => false, 'message' => 'Cannot get Uploaded Object'); | |
75 | - | |
76 | - if (array_key_exists('intervals', $intervals_res)) | |
77 | - { | |
78 | - foreach ($intervals_res['intervals'] as $interval) | |
79 | - { | |
80 | - //Add interval | |
81 | - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); | |
82 | - } | |
49 | + $result = parent::initFromObject($id, $type); | |
50 | + if (!$result['success']) { | |
51 | + return $result; | |
52 | + } | |
53 | + | |
54 | + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); | |
55 | + if (!$params_desc['success']) { | |
56 | + return $params_desc; | |
83 | 57 | } |
84 | 58 | |
85 | - $this->cache->setIsModified(true); | |
86 | - $paramHeaders = $intervals_res['parameters']; | |
59 | + $paramHeaders = $params_desc['parameters']; | |
87 | 60 | |
88 | 61 | $this->cache->setParamsNumber(count($paramHeaders)); |
89 | 62 | $this->cache->setParamsSizes($paramHeaders); |
90 | 63 | $this->cache->setParamsTypes($paramHeaders); |
91 | 64 | |
92 | - unset($intervals_res); | |
93 | - | |
94 | - //Update cache | |
95 | - $this->cache->updateIndexes(); | |
96 | - | |
97 | 65 | //Save cache file |
98 | - return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), | |
99 | - 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); | |
66 | + return $result+ array('parameters' => $paramHeaders); | |
100 | 67 | } |
101 | 68 | |
102 | - public function initFromObject($id, $type) | |
103 | - { | |
104 | - //Create new cache | |
105 | - $this->resetCache(); | |
106 | - | |
107 | - //Load intervals from catalog file and add to cache | |
108 | - $intervals_res = $this->objectMgr->loadIntervalsFromObject($id,$type); | |
109 | - | |
110 | - if (!$intervals_res['success']) | |
111 | - return $intervals_res; | |
69 | + public function initFromTmpObject($folderId, $name) { | |
70 | + $result = parent::initFromTmpObject($folderId, $name); | |
71 | + if (!$result['success']) { | |
72 | + return $result; | |
73 | + } | |
112 | 74 | |
113 | - foreach ($intervals_res['intervals'] as $interval) | |
114 | - { | |
115 | - //Add interval | |
116 | - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); | |
75 | + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); | |
76 | + if (!$params_desc['success']) { | |
77 | + return $params_desc; | |
117 | 78 | } |
118 | 79 | |
119 | - $paramHeaders = $intervals_res['parameters']; | |
80 | + $paramHeaders = $params_desc['parameters']; | |
120 | 81 | |
121 | 82 | $this->cache->setParamsNumber(count($paramHeaders)); |
122 | 83 | $this->cache->setParamsSizes($paramHeaders); |
123 | 84 | $this->cache->setParamsTypes($paramHeaders); |
124 | 85 | |
125 | - unset($intervals_res); | |
126 | - | |
127 | - //Update cache | |
128 | - $this->cache->updateIndexes(); | |
129 | - | |
130 | - //Save cache file | |
131 | - return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), | |
132 | - 'status' => $this->cache->getStatus(),'parameters' => $paramHeaders); | |
86 | + return $result+ array('parameters' => $paramHeaders); | |
133 | 87 | } |
134 | 88 | |
135 | - | |
136 | - protected function loadFromFile() | |
89 | + public function initFromUploadedFile($name, $format) | |
137 | 90 | { |
138 | - if (!file_exists($this->getCacheFilePath())) | |
139 | - return false; | |
140 | - $this->resetCache(); | |
141 | - $handle = fopen($this->getCacheFilePath(), 'rb'); | |
142 | - $result = false; | |
143 | - if (flock($handle, LOCK_SH)) | |
144 | - { | |
145 | - $this->cache->loadBin($handle); | |
146 | - flock( $handle, LOCK_UN ); | |
147 | - $result = true; | |
91 | + $result = parent::initFromUploadedFile($name, $format); | |
92 | + if (!$result['success']) { | |
93 | + return $result; | |
148 | 94 | } |
149 | - fclose($handle); | |
150 | - return $result; | |
151 | - } | |
152 | 95 | |
153 | - public function saveInObject($id, $action, $token) | |
154 | - { | |
155 | - if (!$this->loadFromFile()) | |
156 | - return array('success' => false, 'message' => 'Cannot load cache file'); | |
157 | - | |
158 | - if ($token != $this->cache->getToken()) | |
159 | - return array('success' => false, 'message' => 'Cache token check error'); | |
160 | - | |
161 | - $this->cache->updateIndexes(); | |
162 | - $this->saveToFile(); | |
163 | - | |
164 | - $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); | |
165 | - | |
166 | - $this->cache->reset(); | |
167 | - | |
168 | - return $this->objectMgr->saveIntervals($id, $intervals, $action); | |
169 | - } | |
170 | - | |
171 | - public function addInterval($index, $start, $stop, $params = array()) { | |
172 | - if (!$this->loadFromFile()) | |
173 | - return array('success' => false, 'message' => 'Cannot load cache file'); | |
174 | - | |
175 | - if (!isset($index)) | |
176 | - $index = 0; | |
177 | - | |
178 | - if (!isset($start)) | |
179 | - $start = date('Y-m-d\TH:i:s'); | |
180 | - | |
181 | - if (!isset($stop)) | |
182 | - $stop = date('Y-m-d\TH:i:s'); | |
183 | - | |
184 | - if (!isset($params)) | |
185 | - $params = []; | |
186 | - | |
187 | - $this->cache->addInterval($start, $stop, $params, true, $index); | |
188 | - | |
189 | - //$this->cache->updateIndexes(); | |
190 | - | |
191 | - $this->saveToFile(); | |
192 | - | |
193 | - return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); | |
194 | - } | |
195 | - | |
196 | - public function modifyIntervalFromId($obj) { | |
197 | - if (!$this->loadFromFile()) | |
198 | - return array('success' => false, 'message' => 'Cannot load cache file'); | |
199 | - | |
200 | - $this->cache->modifyIntervalFromId($obj); | |
201 | - | |
202 | - $this->saveToFile(); | |
203 | - | |
204 | - return array('success' => true, 'status' => $this->cache->getStatus()); | |
205 | - } | |
206 | - | |
207 | - public function initObjectCache($options = array()) { | |
208 | - //Create new cache | |
209 | - $nparams = isset($options['nparams']) ? $options['nparams'] : 1; | |
96 | + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); | |
97 | + if (!$params_desc['success']) { | |
98 | + return $params_desc; | |
99 | + } | |
210 | 100 | |
211 | - $this->resetCache(); | |
212 | - $this->cache->setParamsNumber((int)$nparams); | |
213 | - $paramHeaders = array(); | |
101 | + $paramHeaders = $params_desc['parameters']; | |
214 | 102 | |
215 | - for ($i = 0; $i < (int)$nparams; $i++) { | |
216 | - $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); | |
217 | - $paramHeaders[$i]['name'] = 'param_'.(string)($i+1); | |
218 | - $paramHeaders[$i]['size'] = 1; | |
219 | - $paramHeaders[$i]['type'] = 'Float'; | |
220 | - | |
221 | - } | |
103 | + $this->cache->setParamsNumber(count($paramHeaders)); | |
222 | 104 | $this->cache->setParamsSizes($paramHeaders); |
223 | 105 | $this->cache->setParamsTypes($paramHeaders); |
224 | - //Save cache file | |
225 | - return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), | |
226 | - 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); | |
106 | + | |
107 | + return $result+ array('parameters' => $paramHeaders); | |
227 | 108 | } |
228 | - } | |
109 | + | |
110 | +} | |
229 | 111 | ?> | ... | ... |
php/classes/CatalogCacheObject.php
... | ... | @@ -6,17 +6,17 @@ class CatalogCacheObject extends TimeTableCacheObject |
6 | 6 | private $paramsSizes = array(); |
7 | 7 | private $paramsTypes = array(); |
8 | 8 | |
9 | - public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) | |
9 | + public function addInterval($interval, $isNew = false, $index = -1) | |
10 | 10 | { |
11 | - $interval = new CatalogCacheIntervalObject($this->lastId, count($this->intervals)); | |
11 | + $intervalObj = new CatalogCacheIntervalObject($this->lastId, count($this->intervals)); | |
12 | 12 | ++$this->lastId; |
13 | - $interval->setStartFromISO($startIso); | |
14 | - $interval->setStopFromISO($stopIso); | |
13 | + $intervalObj->setStartFromISO($interval['start']); | |
14 | + $intervalObj->setStopFromISO($interval['stop']); | |
15 | 15 | // for catalog |
16 | - $interval->setParams($params); | |
16 | + $intervalObj->setParams($interval['paramTable']); | |
17 | 17 | |
18 | - $interval->setIsNew($isNew); | |
19 | - array_push($this->intervals, $interval); | |
18 | + $intervalObj->setIsNew($isNew); | |
19 | + array_push($this->intervals, $intervalObj); | |
20 | 20 | |
21 | 21 | if ($index < 0) |
22 | 22 | array_push($this->indexes, count($this->intervals) - 1); |
... | ... | @@ -26,7 +26,7 @@ class CatalogCacheObject extends TimeTableCacheObject |
26 | 26 | if ($isNew) |
27 | 27 | $this->isModified = true; |
28 | 28 | |
29 | - return $interval; | |
29 | + return $intervalObj; | |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function setParamsNumber($number) |
... | ... | @@ -167,29 +167,23 @@ class CatalogCacheObject extends TimeTableCacheObject |
167 | 167 | return true; |
168 | 168 | } |
169 | 169 | |
170 | - public function modifyIntervalFromId($obj) { | |
170 | + public function modifyIntervalFromId($cacheId, $data) { | |
171 | + $result = parent::modifyIntervalFromId($cacheId, $data); | |
171 | 172 | |
172 | 173 | foreach ($this->intervals as $interval) |
173 | 174 | { |
174 | - if ($interval->getId() == $obj->cacheId) | |
175 | + if ($interval->getId() == $cacheId) | |
175 | 176 | { |
176 | - foreach((array)$obj as $key => $val) { | |
177 | - | |
178 | - if ($key == 'start') | |
179 | - $interval->setStartFromISO($val); | |
180 | - else if ($key == 'stop') | |
181 | - $interval->setStopFromISO($val); | |
182 | - else { | |
183 | - if (strpos($key, 'param') === false) | |
184 | - continue; | |
177 | + foreach($data as $key => $value) { | |
178 | + if (strpos($key, 'param') !== FALSE) { | |
185 | 179 | $params = $interval->getParams(); |
186 | 180 | $paramIndex = (int)substr($key,5); |
187 | 181 | $params[$paramIndex-2] = $val; |
188 | 182 | $interval->setParams($params); |
183 | + $interval->setIsModified(true); | |
184 | + $this->isModified = true; | |
189 | 185 | } |
190 | 186 | } |
191 | - $interval->setIsModified(true); | |
192 | - $this->isModified = true; | |
193 | 187 | return true; |
194 | 188 | } |
195 | 189 | } | ... | ... |
php/classes/TimeTableCacheMgr.php
1 | 1 | <?php |
2 | 2 | |
3 | +/** | |
4 | + * @class CatalogCacheMgr | |
5 | + */ | |
6 | + | |
3 | 7 | class TimeTableCacheMgr |
4 | 8 | { |
5 | 9 | protected $objectMgr = null; |
... | ... | @@ -42,7 +46,7 @@ |
42 | 46 | foreach ($intervals_res['intervals'] as $interval) |
43 | 47 | { |
44 | 48 | //Add interval |
45 | - $this->cache->addInterval($interval['start'], $interval['stop']); | |
49 | + $this->cache->addInterval($interval); | |
46 | 50 | } |
47 | 51 | |
48 | 52 | unset($intervals_res); |
... | ... | @@ -68,7 +72,7 @@ |
68 | 72 | foreach ($intervals_res['intervals'] as $interval) |
69 | 73 | { |
70 | 74 | //Add interval |
71 | - $this->cache->addInterval($interval['start'], $interval['stop']); | |
75 | + $this->cache->addInterval($interval); | |
72 | 76 | } |
73 | 77 | |
74 | 78 | unset($intervals_res); |
... | ... | @@ -96,7 +100,7 @@ |
96 | 100 | foreach ($intervals_res['intervals'] as $interval) |
97 | 101 | { |
98 | 102 | //Add interval |
99 | - $this->cache->addInterval($interval['start'], $interval['stop']); | |
103 | + $this->cache->addInterval($interval); | |
100 | 104 | } |
101 | 105 | } |
102 | 106 | |
... | ... | @@ -126,7 +130,7 @@ |
126 | 130 | foreach ($intervals_res['intervals'] as $interval) |
127 | 131 | { |
128 | 132 | //Add interval |
129 | - $this->cache->addInterval($interval['start'], $interval['stop']); | |
133 | + $this->cache->addInterval($interval); | |
130 | 134 | } |
131 | 135 | } |
132 | 136 | |
... | ... | @@ -155,21 +159,7 @@ |
155 | 159 | |
156 | 160 | $this->cache->reset(); |
157 | 161 | |
158 | - $res_intervals = array(); | |
159 | - foreach ($intervals as $interval) | |
160 | - { | |
161 | - array_push( | |
162 | - $res_intervals, | |
163 | - (object)array( | |
164 | - 'start' => $interval['start'], | |
165 | - 'stop' => $interval['stop'] | |
166 | - ) | |
167 | - ); | |
168 | - } | |
169 | - | |
170 | - unset($intervals); | |
171 | - | |
172 | - return $this->objectMgr->saveIntervals($id, $res_intervals, $action); | |
162 | + return $this->objectMgr->saveIntervals($id, $intervals, $action); | |
173 | 163 | } |
174 | 164 | |
175 | 165 | public function getIntervals($start,$limit,$sort_obj,$filter_json) { |
... | ... | @@ -241,7 +231,7 @@ |
241 | 231 | if (!isset($stop)) |
242 | 232 | $stop = date('Y-m-d\TH:i:s'); |
243 | 233 | |
244 | - $this->cache->addInterval($start, $stop, true, $index); | |
234 | + $this->cache->addInterval(array('start' => $start, 'stop' => $stop), true, $index); | |
245 | 235 | |
246 | 236 | //$this->cache->updateIndexes(); |
247 | 237 | |
... | ... | @@ -263,11 +253,11 @@ |
263 | 253 | return array('success' => true, 'status' => $this->cache->getStatus()); |
264 | 254 | } |
265 | 255 | |
266 | - public function modifyIntervalFromId($id, $start, $stop) { | |
256 | + public function modifyIntervalFromId($cacheId, $data) { | |
267 | 257 | if (!$this->loadFromFile()) |
268 | 258 | return array('success' => false, 'message' => 'Cannot load cache file'); |
269 | 259 | |
270 | - $this->cache->modifyIntervalFromId($id, $start, $stop); | |
260 | + $this->cache->modifyIntervalFromId($cacheId, $data); | |
271 | 261 | |
272 | 262 | $this->saveToFile(); |
273 | 263 | ... | ... |
php/classes/TimeTableCacheObject.php
... | ... | @@ -39,20 +39,20 @@ class TimeTableCacheObject |
39 | 39 | $this->isModified = $isModified; |
40 | 40 | } |
41 | 41 | |
42 | - public function addInterval($startIso, $stopIso, $isNew = false, $index = -1) { | |
43 | - $interval = new TimeTableCacheIntervalObject($this->lastId, count($this->intervals)); | |
42 | + public function addInterval($interval, $isNew = false, $index = -1) { | |
43 | + $intervalObj = new TimeTableCacheIntervalObject($this->lastId, count($this->intervals)); | |
44 | 44 | ++$this->lastId; |
45 | - $interval->setStartFromISO($startIso); | |
46 | - $interval->setStopFromISO($stopIso); | |
47 | - $interval->setIsNew($isNew); | |
48 | - array_push($this->intervals, $interval); | |
45 | + $intervalObj->setStartFromISO($interval['start']); | |
46 | + $intervalObj->setStopFromISO($interval['stop']); | |
47 | + $intervalObj->setIsNew($isNew); | |
48 | + array_push($this->intervals, $intervalObj); | |
49 | 49 | if ($index < 0) |
50 | 50 | array_push($this->indexes, count($this->intervals) - 1); |
51 | 51 | else |
52 | 52 | array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); |
53 | 53 | if ($isNew) |
54 | 54 | $this->isModified = true; |
55 | - return $interval; | |
55 | + return $intervalObj; | |
56 | 56 | } |
57 | 57 | |
58 | 58 | public function removeIntervalFromId($id) { |
... | ... | @@ -85,18 +85,26 @@ class TimeTableCacheObject |
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
88 | - public function modifyIntervalFromId($id, $start, $stop) { | |
88 | + public function modifyIntervalFromId($cacheId, $data) { | |
89 | 89 | foreach ($this->intervals as $interval) |
90 | 90 | { |
91 | - if ($interval->getId() == $id) | |
91 | + if ($interval->getId() == $cacheId) | |
92 | 92 | { |
93 | - if (isset($start)) | |
94 | - $interval->setStartFromISO($start); | |
95 | - if (isset($stop)) | |
96 | - $interval->setStopFromISO($stop); | |
97 | - $interval->setIsModified(true); | |
98 | - $this->isModified = true; | |
99 | - return true; | |
93 | + foreach ($data as $key => $value) { | |
94 | + switch ($key) { | |
95 | + case 'start' : | |
96 | + $interval->setStartFromISO($start); | |
97 | + $interval->setIsModified(true); | |
98 | + $this->isModified = true; | |
99 | + break; | |
100 | + case 'stop': | |
101 | + $interval->setStopFromISO($stop); | |
102 | + $interval->setIsModified(true); | |
103 | + $this->isModified = true; | |
104 | + break; | |
105 | + } | |
106 | + } | |
107 | + return $this->isModified; | |
100 | 108 | } |
101 | 109 | } |
102 | 110 | ... | ... |
php/config.php
... | ... | @@ -156,16 +156,16 @@ $API = array( |
156 | 156 | 'loadTTIntervals'=>array('len'=>1), |
157 | 157 | 'saveTTCacheIntervalsInTT'=>array('len'=>1), |
158 | 158 | 'initObjectCache'=>array ('len'=>2), |
159 | - 'initObjectCacheFromTT'=>array('len'=>2), | |
159 | + 'initObjectCacheFromObject'=>array('len'=>2), | |
160 | 160 | 'initForChart'=>array('len'=>4), |
161 | 161 | 'initObjectCacheFromTmpObject'=>array('len'=>3), |
162 | 162 | 'initObjectCacheFromUploadedFile'=>array('len'=>3), |
163 | 163 | 'initObjectCacheFromCatalog'=>array('len'=>2), |
164 | - 'readTTCacheIntervals'=>array('len'=>1), | |
164 | + 'readCacheIntervals'=>array('len'=>1), | |
165 | 165 | 'readIntervalsForChart'=>array('len'=>1), |
166 | - 'addTTCacheInterval'=>array('len'=>1), | |
166 | + 'addCacheInterval'=>array('len'=>1), | |
167 | 167 | 'removeTTCacheIntervalFromId'=>array('len'=>2), |
168 | - 'modifyTTCacheInterval'=>array('len'=>1), | |
168 | + 'modifyCacheInterval'=>array('len'=>1), | |
169 | 169 | 'operationTTCacheIntervals'=>array('len'=>2), |
170 | 170 | 'mergeTTCacheIntervals'=>array('len'=>0), |
171 | 171 | 'getTTCacheStatistics'=>array('len'=>1), | ... | ... |