diff --git a/js/app/models/TimeTable.js b/js/app/models/TimeTable.js index 5269c47..00cc30a 100644 --- a/js/app/models/TimeTable.js +++ b/js/app/models/TimeTable.js @@ -1,10 +1,10 @@ /** * Project  : AMDA-NG - * Name : timeTable.js + * Name : timeTable.js * Description : TimeTable Business Object Definition * @class amdaModel.TimeTable - * @extends amdaModel.AmdaObject - * + * @extends amdaModel.AmdaObject + * * @author cdarmon * @version $Id: TimeTable.js 1907 2013-11-25 15:59:42Z myriam $ ****************************************************************************** @@ -16,7 +16,7 @@ Ext.define('amdaModel.Interval', { - extend: 'amdaModel.AmdaObject', + extend: 'amdaModel.AmdaObject', fields: [ { name: 'id', @@ -80,19 +80,19 @@ Ext.define('amdaModel.Interval', { { name: 'isNew', type : 'boolean', defaultValue: false}, { name: 'isModified', type : 'boolean', defaultValue: false} ], - + getJsonValues : function () { var values = new Object(); values.start = this.get('start'); values.stop = this.get('stop'); return values; }, - + proxy: { type: 'direct', api : { - read : AmdaAction.readTTCacheIntervals + read : AmdaAction.readCacheIntervals }, extraParams : {'typeTT' : ''}, reader: @@ -102,8 +102,8 @@ Ext.define('amdaModel.Interval', { totalProperty : 'totalCount' } } - - /* + + /* validations: [ {type: 'presence', field: 'age'}, {type: 'length', field: 'name', min: 2}, @@ -112,49 +112,49 @@ Ext.define('amdaModel.Interval', { {type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/} ], */ - + }); Ext.define('amdaModel.TimeTable', { - + extend: 'amdaModel.AmdaObject', - + fields : [ {name: 'fromPlugin', type: 'boolean', defaultValue: false}, {name: 'created', type: 'date'}, {name: 'description', type: 'string'}, - {name: 'history', type: 'string'}, + {name: 'history', type: 'string'}, {name: 'nbIntervals', type: 'int'}, {name: 'objName', type: 'string', defaultValue: ""}, {name: 'objFormat', type: 'string', defaultValue: ""}, {name: 'folderId', type: 'string', defaultValue: ""}, {name: 'cacheToken', type: 'string', defaultValue: ""}, {name: 'relatedCatalogId', type: 'string', defaultValue: ""} - ], - + ], + /*commit: function(){ this.callParent(arguments); - + // fix the modifications for its intervals - Ext.Array.each(this.get('intervals'), function(item, index, all) { -//TODO check if JSON object should be processed - if (item.$className) { + Ext.Array.each(this.get('intervals'), function(item, index, all) { +//TODO check if JSON object should be processed + if (item.$className) { item.commit(); - } + } }); - + },*/ - + // hasMany: {model: 'amdaModel.Interval', name: 'intervals'}, - + /** * get TimeTable values to sent to Server * @return object */ //TODO utf8_encode() and Ext.urlEncode() ??? getJsonValues : function (hasId) { - var values = new Object(); + var values = new Object(); if (hasId) { values.id = this.get('id'); } @@ -171,13 +171,10 @@ Ext.define('amdaModel.TimeTable', { values.folderId = this.get('folderId'); values.nbIntervals = this.get('nbIntervals'); values.cacheToken = this.get('cacheToken'); - + values.leaf = true; values.nodeType = amdaModel.TimeTableNode.nodeType; return values; } }); - - - diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index 53aaec8..2149517 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -98,7 +98,7 @@ Ext.define('amdaUI.CatalogUI', { var row = this.TTGrid.getStore().getTotalCount(); var me = this; this.TTGrid.getSelectionModel().deselectAll(); - AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) { + AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) { this.status = result.status; if (!this.TTGrid.getStore().loading) { this.TTGrid.getStore().reload({ @@ -395,7 +395,7 @@ Ext.define('amdaUI.CatalogUI', { remoteSort: true, proxy: { type: 'direct', - api : { read : AmdaAction.readTTCacheIntervals }, + api : { read : AmdaAction.readCacheIntervals }, // remplir automatiquement tt, sharedtt , catalog, shared catalog extraParams : {'typeTT' : 'catalog'}, reader: @@ -466,7 +466,7 @@ Ext.define('amdaUI.CatalogUI', { } else { //From existing TT file - AmdaAction.initObjectCacheFromTT(this.object.get('id'), typeTT, this.onAfterInit, this); + AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, this.onAfterInit, this); } } //Statistical plugin @@ -588,16 +588,17 @@ Ext.define('amdaUI.CatalogUI', { // Only update the record if the new value is different than the // startValue. When the view refreshes its el will gain focus if (!record.isEqual(value, startValue)) { - var obj = {}; - - obj['cacheId'] = record.get('cacheId'); - obj['isCatalog'] = true; - obj[activeColumn.dataIndex] = value; + var obj = { + 'cacheId' : record.get('cacheId'), + 'isCatalog' : true, + 'data' : {} + }; + obj['data']['activeColumn.dataIndex'] = value; //Interval is modified on the server side me.editing = true; - AmdaAction.modifyTTCacheInterval(obj, function (result, e) { + AmdaAction.modifyCacheInterval(obj, function (result, e) { var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); if (module) module.getUiContent().status = result.status; @@ -647,7 +648,7 @@ Ext.define('amdaUI.CatalogUI', { this.TTGrid.getSelectionModel().deselectAll(); var me = this; - AmdaAction.addTTCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) { + AmdaAction.addCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) { this.status = result.status; if (!this.TTGrid.getStore().loading) { this.TTGrid.getStore().reload({ diff --git a/js/app/views/TimeTableUI.js b/js/app/views/TimeTableUI.js index 0394676..c4b5c18 100755 --- a/js/app/views/TimeTableUI.js +++ b/js/app/views/TimeTableUI.js @@ -139,7 +139,7 @@ Ext.define('amdaUI.TimeTableUI', { else { //From existing TT file - AmdaAction.initObjectCacheFromTT(this.object.get('id'), typeTT, onAfterInit); + AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, onAfterInit); } } }, @@ -249,7 +249,7 @@ Ext.define('amdaUI.TimeTableUI', { var row = this.TTGrid.getStore().getTotalCount(); var me = this; this.TTGrid.getSelectionModel().deselectAll(); - AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) { + AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) { this.status = result.status; if (!this.TTGrid.getStore().loading) { this.TTGrid.getStore().reload({ @@ -405,28 +405,18 @@ Ext.define('amdaUI.TimeTableUI', { // Only update the record if the new value is different than the // startValue. When the view refreshes its el will gain focus if (!record.isEqual(value, startValue)) { - var obj = null; - if (activeColumn.dataIndex == 'start') - obj = { - 'cacheId' : record.get('cacheId'), - 'start' : value - }; - else if (activeColumn.dataIndex == 'stop') - obj = { - 'cacheId' : record.get('cacheId'), - 'stop' : value - }; - else - { - me.editing = false; - return; - } + var obj = { + 'cacheId' : record.get('cacheId'), + 'isCatalog' : false, + 'data' : {} + }; + obj['data'][activeColumn.dataIndex] = value; //context.grid.getSelectionModel().deselectAll(); //Interval is modified on the server side me.editing = true; - AmdaAction.modifyTTCacheInterval(obj, function (result, e) { + AmdaAction.modifyCacheInterval(obj, function (result, e) { var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id); if (ttModule) @@ -585,7 +575,7 @@ Ext.define('amdaUI.TimeTableUI', { this.TTGrid.getSelectionModel().deselectAll(); var me = this; - AmdaAction.addTTCacheInterval({'index' : row}, function (result, e) { + AmdaAction.addCacheInterval({'index' : row}, function (result, e) { this.status = result.status; if (!this.TTGrid.getStore().loading) { this.TTGrid.getStore().reload({ diff --git a/php/TTCacheDump.php b/php/TTCacheDump.php index 80e4473..5780cd4 100644 --- a/php/TTCacheDump.php +++ b/php/TTCacheDump.php @@ -1,11 +1,22 @@ dump(); diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index 4aae42f..8adc914 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -1079,7 +1079,7 @@ class AmdaAction } - public function initObjectCacheFromTT($id, $type) + public function initObjectCacheFromObject($id, $type) { if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); @@ -1121,7 +1121,7 @@ class AmdaAction return $cacheMgr->initFromUploadedFile($name, $format); } - public function readTTCacheIntervals($o) + public function readCacheIntervals($o) { if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); @@ -1151,7 +1151,7 @@ class AmdaAction return $cacheMgr->saveInObject($o->ttId,$o->action,$o->cacheToken); } - public function addTTCacheInterval($o) + public function addCacheInterval($o) { if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); @@ -1167,16 +1167,15 @@ class AmdaAction return $cacheMgr->removeIntervalFromId($id); } - public function modifyTTCacheInterval($o) + public function modifyCacheInterval($o) { if ($o->isCatalog) { $cacheMgr = new CatalogCacheMgr(); - return $cacheMgr->modifyIntervalFromId($o); } else $cacheMgr = new TimeTableCacheMgr(); - return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop); + return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->data); } public function operationTTCacheIntervals($extendTime, $shiftTime) diff --git a/php/classes/CatalogCacheIntervalObject.php b/php/classes/CatalogCacheIntervalObject.php index d5b5358..18a6201 100644 --- a/php/classes/CatalogCacheIntervalObject.php +++ b/php/classes/CatalogCacheIntervalObject.php @@ -98,7 +98,12 @@ class CatalogCacheIntervalObject extends TimeTableCacheIntervalObject public function dump() { - echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; + parent::dump(); + echo " parameters = "; + foreach ($this->params as $param) { + echo $param.", "; + } + echo PHP_EOL; } } diff --git a/php/classes/CatalogCacheMgr.php b/php/classes/CatalogCacheMgr.php index a9b9b3a..26f91d2 100644 --- a/php/classes/CatalogCacheMgr.php +++ b/php/classes/CatalogCacheMgr.php @@ -6,11 +6,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr { - protected $objectMgr = null; - protected $cache = null; function __construct() { - $this->objectMgr = new CatalogMgr(); } @@ -22,208 +19,93 @@ class CatalogCacheMgr extends TimeTableCacheMgr $this->cache = new CatalogCacheObject(); } + public function initObjectCache($options = array()) { + $result = parent::initObjectCache($options); + if (!$result['success']) { + return $result; + } - public function initFromTmpObject($folderId, $name) { - - //Create new cache - $this->resetCache(); - - //Load intervals from TmpObject file (Statistics Module) - $intervals_res = $this->objectMgr->getTmpObject($folderId, $name); + //init parameters + $nparams = isset($options['nparams']) ? $options['nparams'] : 1; + $this->cache->setParamsNumber((int)$nparams); - if (!isset($intervals_res)) - return array('success' => false, 'message' => 'Cannot get Tmp Object'); + $paramHeaders = array(); - if (array_key_exists('intervals', $intervals_res)) - { - foreach ($intervals_res['intervals'] as $interval) - { - //Add interval - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); + for ($i = 0; $i < (int)$nparams; $i++) { + $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); + $paramHeaders[$i]['name'] = 'column_'.(string)($i+1); + $paramHeaders[$i]['size'] = 1; + $paramHeaders[$i]['type'] = 'Float'; - } } - - $this->cache->setIsModified(true); - - $paramHeaders = $intervals_res['parameters']; - - $this->cache->setParamsNumber(count($paramHeaders)); $this->cache->setParamsSizes($paramHeaders); $this->cache->setParamsTypes($paramHeaders); - - 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'=>$paramHeaders); + return $result + array('parameters' => $paramHeaders); } - public function initFromUploadedFile($name, $format) + public function initFromObject($id, $type) { - //Create new cache - $this->resetCache(); - - //Load intervals from uploaded file - $intervals_res = $this->objectMgr->getUploadedObject($name, $format); - - if (!isset($intervals_res)) - return array('success' => false, 'message' => 'Cannot get Uploaded Object'); - - if (array_key_exists('intervals', $intervals_res)) - { - foreach ($intervals_res['intervals'] as $interval) - { - //Add interval - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); - } + $result = parent::initFromObject($id, $type); + if (!$result['success']) { + return $result; + } + + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); + if (!$params_desc['success']) { + return $params_desc; } - $this->cache->setIsModified(true); - $paramHeaders = $intervals_res['parameters']; + $paramHeaders = $params_desc['parameters']; $this->cache->setParamsNumber(count($paramHeaders)); $this->cache->setParamsSizes($paramHeaders); $this->cache->setParamsTypes($paramHeaders); - 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'=>$paramHeaders); + return $result+ array('parameters' => $paramHeaders); } - public function initFromObject($id, $type) - { - //Create new cache - $this->resetCache(); - - //Load intervals from catalog file and add to cache - $intervals_res = $this->objectMgr->loadIntervalsFromObject($id,$type); - - if (!$intervals_res['success']) - return $intervals_res; + public function initFromTmpObject($folderId, $name) { + $result = parent::initFromTmpObject($folderId, $name); + if (!$result['success']) { + return $result; + } - foreach ($intervals_res['intervals'] as $interval) - { - //Add interval - $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); + if (!$params_desc['success']) { + return $params_desc; } - $paramHeaders = $intervals_res['parameters']; + $paramHeaders = $params_desc['parameters']; $this->cache->setParamsNumber(count($paramHeaders)); $this->cache->setParamsSizes($paramHeaders); $this->cache->setParamsTypes($paramHeaders); - 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' => $paramHeaders); + return $result+ array('parameters' => $paramHeaders); } - - protected function loadFromFile() + public function initFromUploadedFile($name, $format) { - if (!file_exists($this->getCacheFilePath())) - return false; - $this->resetCache(); - $handle = fopen($this->getCacheFilePath(), 'rb'); - $result = false; - if (flock($handle, LOCK_SH)) - { - $this->cache->loadBin($handle); - flock( $handle, LOCK_UN ); - $result = true; + $result = parent::initFromUploadedFile($name, $format); + if (!$result['success']) { + return $result; } - fclose($handle); - return $result; - } - public function saveInObject($id, $action, $token) - { - if (!$this->loadFromFile()) - return array('success' => false, 'message' => 'Cannot load cache file'); - - if ($token != $this->cache->getToken()) - return array('success' => false, 'message' => 'Cache token check error'); - - $this->cache->updateIndexes(); - $this->saveToFile(); - - $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); - - $this->cache->reset(); - - return $this->objectMgr->saveIntervals($id, $intervals, $action); - } - - public function addInterval($index, $start, $stop, $params = array()) { - if (!$this->loadFromFile()) - return array('success' => false, 'message' => 'Cannot load cache file'); - - if (!isset($index)) - $index = 0; - - if (!isset($start)) - $start = date('Y-m-d\TH:i:s'); - - if (!isset($stop)) - $stop = date('Y-m-d\TH:i:s'); - - if (!isset($params)) - $params = []; - - $this->cache->addInterval($start, $stop, $params, true, $index); - - //$this->cache->updateIndexes(); - - $this->saveToFile(); - - return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); - } - - public function modifyIntervalFromId($obj) { - if (!$this->loadFromFile()) - return array('success' => false, 'message' => 'Cannot load cache file'); - - $this->cache->modifyIntervalFromId($obj); - - $this->saveToFile(); - - return array('success' => true, 'status' => $this->cache->getStatus()); - } - - public function initObjectCache($options = array()) { - //Create new cache - $nparams = isset($options['nparams']) ? $options['nparams'] : 1; + $params_desc = $this->objectMgr->getCatalogParamDescription($id, $name, FALSE, $type); + if (!$params_desc['success']) { + return $params_desc; + } - $this->resetCache(); - $this->cache->setParamsNumber((int)$nparams); - $paramHeaders = array(); + $paramHeaders = $params_desc['parameters']; - for ($i = 0; $i < (int)$nparams; $i++) { - $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); - $paramHeaders[$i]['name'] = 'param_'.(string)($i+1); - $paramHeaders[$i]['size'] = 1; - $paramHeaders[$i]['type'] = 'Float'; - - } + $this->cache->setParamsNumber(count($paramHeaders)); $this->cache->setParamsSizes($paramHeaders); $this->cache->setParamsTypes($paramHeaders); - //Save cache file - return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), - 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); + + return $result+ array('parameters' => $paramHeaders); } - } + +} ?> diff --git a/php/classes/CatalogCacheObject.php b/php/classes/CatalogCacheObject.php index 89290b3..4de4828 100644 --- a/php/classes/CatalogCacheObject.php +++ b/php/classes/CatalogCacheObject.php @@ -6,17 +6,17 @@ class CatalogCacheObject extends TimeTableCacheObject private $paramsSizes = array(); private $paramsTypes = array(); - public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) + public function addInterval($interval, $isNew = false, $index = -1) { - $interval = new CatalogCacheIntervalObject($this->lastId, count($this->intervals)); + $intervalObj = new CatalogCacheIntervalObject($this->lastId, count($this->intervals)); ++$this->lastId; - $interval->setStartFromISO($startIso); - $interval->setStopFromISO($stopIso); + $intervalObj->setStartFromISO($interval['start']); + $intervalObj->setStopFromISO($interval['stop']); // for catalog - $interval->setParams($params); + $intervalObj->setParams($interval['paramTable']); - $interval->setIsNew($isNew); - array_push($this->intervals, $interval); + $intervalObj->setIsNew($isNew); + array_push($this->intervals, $intervalObj); if ($index < 0) array_push($this->indexes, count($this->intervals) - 1); @@ -26,7 +26,7 @@ class CatalogCacheObject extends TimeTableCacheObject if ($isNew) $this->isModified = true; - return $interval; + return $intervalObj; } public function setParamsNumber($number) @@ -167,29 +167,23 @@ class CatalogCacheObject extends TimeTableCacheObject return true; } - public function modifyIntervalFromId($obj) { + public function modifyIntervalFromId($cacheId, $data) { + $result = parent::modifyIntervalFromId($cacheId, $data); foreach ($this->intervals as $interval) { - if ($interval->getId() == $obj->cacheId) + if ($interval->getId() == $cacheId) { - foreach((array)$obj as $key => $val) { - - if ($key == 'start') - $interval->setStartFromISO($val); - else if ($key == 'stop') - $interval->setStopFromISO($val); - else { - if (strpos($key, 'param') === false) - continue; + foreach($data as $key => $value) { + if (strpos($key, 'param') !== FALSE) { $params = $interval->getParams(); $paramIndex = (int)substr($key,5); $params[$paramIndex-2] = $val; $interval->setParams($params); + $interval->setIsModified(true); + $this->isModified = true; } } - $interval->setIsModified(true); - $this->isModified = true; return true; } } diff --git a/php/classes/TimeTableCacheMgr.php b/php/classes/TimeTableCacheMgr.php index 7a67a57..3ed0036 100644 --- a/php/classes/TimeTableCacheMgr.php +++ b/php/classes/TimeTableCacheMgr.php @@ -1,5 +1,9 @@ cache->addInterval($interval['start'], $interval['stop']); + $this->cache->addInterval($interval); } unset($intervals_res); @@ -68,7 +72,7 @@ foreach ($intervals_res['intervals'] as $interval) { //Add interval - $this->cache->addInterval($interval['start'], $interval['stop']); + $this->cache->addInterval($interval); } unset($intervals_res); @@ -96,7 +100,7 @@ foreach ($intervals_res['intervals'] as $interval) { //Add interval - $this->cache->addInterval($interval['start'], $interval['stop']); + $this->cache->addInterval($interval); } } @@ -126,7 +130,7 @@ foreach ($intervals_res['intervals'] as $interval) { //Add interval - $this->cache->addInterval($interval['start'], $interval['stop']); + $this->cache->addInterval($interval); } } @@ -155,21 +159,7 @@ $this->cache->reset(); - $res_intervals = array(); - foreach ($intervals as $interval) - { - array_push( - $res_intervals, - (object)array( - 'start' => $interval['start'], - 'stop' => $interval['stop'] - ) - ); - } - - unset($intervals); - - return $this->objectMgr->saveIntervals($id, $res_intervals, $action); + return $this->objectMgr->saveIntervals($id, $intervals, $action); } public function getIntervals($start,$limit,$sort_obj,$filter_json) { @@ -241,7 +231,7 @@ if (!isset($stop)) $stop = date('Y-m-d\TH:i:s'); - $this->cache->addInterval($start, $stop, true, $index); + $this->cache->addInterval(array('start' => $start, 'stop' => $stop), true, $index); //$this->cache->updateIndexes(); @@ -263,11 +253,11 @@ return array('success' => true, 'status' => $this->cache->getStatus()); } - public function modifyIntervalFromId($id, $start, $stop) { + public function modifyIntervalFromId($cacheId, $data) { if (!$this->loadFromFile()) return array('success' => false, 'message' => 'Cannot load cache file'); - $this->cache->modifyIntervalFromId($id, $start, $stop); + $this->cache->modifyIntervalFromId($cacheId, $data); $this->saveToFile(); diff --git a/php/classes/TimeTableCacheObject.php b/php/classes/TimeTableCacheObject.php index 5960d0d..cb299ce 100644 --- a/php/classes/TimeTableCacheObject.php +++ b/php/classes/TimeTableCacheObject.php @@ -39,20 +39,20 @@ class TimeTableCacheObject $this->isModified = $isModified; } - public function addInterval($startIso, $stopIso, $isNew = false, $index = -1) { - $interval = new TimeTableCacheIntervalObject($this->lastId, count($this->intervals)); + public function addInterval($interval, $isNew = false, $index = -1) { + $intervalObj = new TimeTableCacheIntervalObject($this->lastId, count($this->intervals)); ++$this->lastId; - $interval->setStartFromISO($startIso); - $interval->setStopFromISO($stopIso); - $interval->setIsNew($isNew); - array_push($this->intervals, $interval); + $intervalObj->setStartFromISO($interval['start']); + $intervalObj->setStopFromISO($interval['stop']); + $intervalObj->setIsNew($isNew); + array_push($this->intervals, $intervalObj); if ($index < 0) array_push($this->indexes, count($this->intervals) - 1); else array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); if ($isNew) $this->isModified = true; - return $interval; + return $intervalObj; } public function removeIntervalFromId($id) { @@ -85,18 +85,26 @@ class TimeTableCacheObject return false; } - public function modifyIntervalFromId($id, $start, $stop) { + public function modifyIntervalFromId($cacheId, $data) { foreach ($this->intervals as $interval) { - if ($interval->getId() == $id) + if ($interval->getId() == $cacheId) { - if (isset($start)) - $interval->setStartFromISO($start); - if (isset($stop)) - $interval->setStopFromISO($stop); - $interval->setIsModified(true); - $this->isModified = true; - return true; + foreach ($data as $key => $value) { + switch ($key) { + case 'start' : + $interval->setStartFromISO($start); + $interval->setIsModified(true); + $this->isModified = true; + break; + case 'stop': + $interval->setStopFromISO($stop); + $interval->setIsModified(true); + $this->isModified = true; + break; + } + } + return $this->isModified; } } diff --git a/php/config.php b/php/config.php index 75b9ece..a077bb1 100644 --- a/php/config.php +++ b/php/config.php @@ -156,16 +156,16 @@ $API = array( 'loadTTIntervals'=>array('len'=>1), 'saveTTCacheIntervalsInTT'=>array('len'=>1), 'initObjectCache'=>array ('len'=>2), - 'initObjectCacheFromTT'=>array('len'=>2), + 'initObjectCacheFromObject'=>array('len'=>2), 'initForChart'=>array('len'=>4), 'initObjectCacheFromTmpObject'=>array('len'=>3), 'initObjectCacheFromUploadedFile'=>array('len'=>3), 'initObjectCacheFromCatalog'=>array('len'=>2), - 'readTTCacheIntervals'=>array('len'=>1), + 'readCacheIntervals'=>array('len'=>1), 'readIntervalsForChart'=>array('len'=>1), - 'addTTCacheInterval'=>array('len'=>1), + 'addCacheInterval'=>array('len'=>1), 'removeTTCacheIntervalFromId'=>array('len'=>2), - 'modifyTTCacheInterval'=>array('len'=>1), + 'modifyCacheInterval'=>array('len'=>1), 'operationTTCacheIntervals'=>array('len'=>2), 'mergeTTCacheIntervals'=>array('len'=>0), 'getTTCacheStatistics'=>array('len'=>1), -- libgit2 0.21.2