From d8ec16238fd8c36b0daf77df7a6219cad1062ab2 Mon Sep 17 00:00:00 2001 From: Nathanaƫl Jourdane Date: Fri, 1 Jun 2018 11:47:49 +0200 Subject: [PATCH] fix phpcs warnings --- php/classes/TimeTableMgr.php | 403 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 237 insertions(+), 166 deletions(-) diff --git a/php/classes/TimeTableMgr.php b/php/classes/TimeTableMgr.php index 071efeb..0dd8a33 100644 --- a/php/classes/TimeTableMgr.php +++ b/php/classes/TimeTableMgr.php @@ -7,28 +7,20 @@ * */ -function timeFormat($myString) -{ - if (format == "Y z H i s") { - $tt = getdate(strtotime($myString)); - return sprintf("%04d", $tt["year"]) . " " - . sprintf("%03d", $tt["yday"] + 1) . " " - . sprintf("%02d", $tt["hours"]) . " " - . sprintf("%02d", $tt["minutes"]) . " " - . sprintf("%02d", $tt["seconds"]); - } - return date(format, strtotime($myString)); -} - class TimeTableMgr extends AmdaObjectMgr { - function __construct($user = null, $sharedObject = false) + /** + * TimeTableMgr constructor. + * @param null $user The user + * @param bool $sharedObject Shared object + */ + public function __construct($user = null, $sharedObject = false) { parent::__construct('Tt.xml'); $this->contentRootId = 'timeTable-treeRootNode'; $this->contentRootTag = 'timetabList'; - $this->attributes = array('name' => '', 'intervals' => ''); - $this->optionalAttributes = array(); + $this->attributes = ['name' => '', 'intervals' => '']; + $this->optionalAttributes = []; $this->objTagName = 'timetab'; $this->id_prefix = 'tt_'; @@ -40,7 +32,7 @@ class TimeTableMgr extends AmdaObjectMgr protected function createDom() { - $types = array('timetab' => 'timeTable', 'catalog' => 'catalog'); + $types = ['timetab' => 'timeTable', 'catalog' => 'catalog']; $rootElement = $this->contentDom->createElement('ws'); @@ -55,12 +47,13 @@ class TimeTableMgr extends AmdaObjectMgr $this->contentDom->save($this->xmlName); } - /* - * rename Time Table in id.xml - */ - - - function getObject($id, $nodeType) + /** + * Get object + * @param $id + * @param $nodeType + * @return array + */ + public function getObject($id, $nodeType = null) { if (substr($nodeType, 0, 6) == 'shared') { //Shared object @@ -71,11 +64,11 @@ class TimeTableMgr extends AmdaObjectMgr } if (!file_exists($path)) { - return array('error' => NO_OBJECT_FILE); + return ['error' => NO_OBJECT_FILE]; } $this->objectDom->load($path); if (!($objToGet = $this->objectDom->getElementById($id))) { - return array('error' => NO_SUCH_ID); + return ['error' => NO_SUCH_ID]; } $attributesToReturn['id'] = $objToGet->getAttribute('xml:id'); $attributes = $objToGet->childNodes; @@ -98,12 +91,16 @@ class TimeTableMgr extends AmdaObjectMgr } } } - $attributesToReturn['nbIntervals'] = $nbInt; return $attributesToReturn; } + /** + * Modify an object + * @param $p + * @return array + */ public function modifyObject($p) { $folder = $this->getObjectFolder($p->id); @@ -127,21 +124,23 @@ class TimeTableMgr extends AmdaObjectMgr if ($tmpFileExist) { unlink($ttFilePath . ".tmp"); } - return array('id' => $p->id, 'info' => $result['info']); - } catch (Exception $e) { + return ['id' => $p->id, 'info' => $result['info']]; + } catch (Exception $exception) { //Restore TT file if ($tmpFileExist) { copy($ttFilePath . ".tmp", $ttFilePath); unlink($ttFilePath . ".tmp"); } - return array('error' => $e->getMessage()); + return ['error' => $exception->getMessage()]; } } - /* - * Check if difference is name and info only - */ - + /** + * Create an object + * @param $p + * @param $folder + * @return array + */ public function createObject($p, $folder) { if ($p->leaf) { @@ -154,25 +153,26 @@ class TimeTableMgr extends AmdaObjectMgr $resultSaveInt = $cacheMgr->saveInTT($result['id'], "update", $p->cacheToken); if (!$resultSaveInt['success']) { if ($resultSaveInt['message']) { - return array('error' => $resultSaveInt['message']); + return ['error' => $resultSaveInt['message']]; } else { - return array('error' => 'Unknown error during intervals save'); + return ['error' => 'Unknown error during intervals save']; } } } return $result; - } - // else return $this->createFolder($p); - //TODO check if this is possible? - else { - return array('error' => 'createFolder should be called from RENAME'); + } else { + return ['error' => 'createFolder should be called from RENAME']; + // return $this->createFolder($p); + // TODO check if this is possible? } } - /* - * In case of catalogs - */ - + /** + * Create parameter (in case of catalogs) + * @param $p + * @param $folder + * @return array + */ protected function createParameter($p, $folder) { if ($this->objectExistsByName($p->name)) { @@ -183,11 +183,11 @@ class TimeTableMgr extends AmdaObjectMgr $this->id = $this->setId(); $this->created = date('Y-m-d\TH:i:s'); if (!$this->id) { - return array('error' => ID_CREATION_ERROR); + return ['error' => ID_CREATION_ERROR]; } $this->resFileName = USERTTDIR . $this->id . '.xml'; - //TODO catalog root element = 'timetable' + // TODO catalog root element = 'timetable' $rootElement = $this->objectDom->createElement('timetable'); $rootElement->setAttribute('xml:id', $this->id); @@ -203,7 +203,6 @@ class TimeTableMgr extends AmdaObjectMgr if ($paramsElement) { $rootElement->appendChild($paramsElement); } - } else { if ($key != 'intervals') { $rootElement->appendChild($this->objectDom->createElement($key, htmlspecialchars($value))); @@ -219,18 +218,28 @@ class TimeTableMgr extends AmdaObjectMgr $obj->name = $p->name; $obj->intervals = $p->nbIntervals; $this->addToContent($obj, $folder); - return array('id' => $this->id, 'created' => $this->created, 'info' => $obj->intervals . ' intervals'); + // FIXME field created is undefined + return ['id' => $this->id, 'created' => $this->created, 'info' => $obj->intervals . ' intervals']; } - - /* - * Create Time Table + /** + * Set parameter description + * TODO + * @param $param string The parameter + * @return DOMNode */ - protected function setParamDescription($param) { + return new DOMNode(); } + /** + * Get uploaded object + * @param $name + * @param $format + * @param bool $onlyDescription + * @return mixed + */ public function getUploadedObject($name, $format, $onlyDescription = false) { if (strpos($name, '.txt') !== false || strpos($name, '.asc') !== false || strpos($name, '.') == false) { @@ -255,13 +264,13 @@ class TimeTableMgr extends AmdaObjectMgr } if (!file_exists(USERTEMPDIR . $name . '.xml')) { - return array('error' => 'no such name'); + return ['error' => 'no such name']; } $this->objectDom->load(USERTEMPDIR . $name . '.xml'); if (!($objToGet = $this->objectDom->getElementsByTagName('timetable')->item(0)) && !($objToGet = $this->objectDom->getElementsByTagName('TimeTable')->item(0))) { - return array('error' => 'no time table'); + return ['error' => 'no time table']; } $attributes = $objToGet->childNodes; @@ -269,28 +278,29 @@ class TimeTableMgr extends AmdaObjectMgr $attributesToReturn['objName'] = $name; $attributesToReturn['objFormat'] = $format; + /** @var DOMElement $attribute */ foreach ($attributes as $attribute) { if ($attribute->nodeType == XML_ELEMENT_NODE) { if ($attribute->tagName == 'intervals') { $start = $attribute->getElementsByTagName('start')->item(0)->nodeValue; $stop = $attribute->getElementsByTagName('stop')->item(0)->nodeValue; if (!$onlyDescription) { - $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop); + $attributesToReturn['intervals'][] = ['start' => $start, 'stop' => $stop]; } } else { if ($attribute->tagName == 'Interval') { $start = $attribute->getElementsByTagName('Start')->item(0)->nodeValue; $stop = $attribute->getElementsByTagName('Stop')->item(0)->nodeValue; if (!$onlyDescription) { - $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop); + $attributesToReturn['intervals'][] = ['start' => $start, 'stop' => $stop]; } } else { switch (strtolower($attribute->tagName)) { - case 'created' : + case 'created': $attributesToReturn['created'] = $attribute->nodeValue; break; - case 'chain' : - case 'source' : + case 'chain': + case 'source': $attributesToReturn['description'] = $attribute->nodeValue; break; default: @@ -307,6 +317,12 @@ class TimeTableMgr extends AmdaObjectMgr * Uploaded text file => convert to array */ + /** + * Convert text to AMDA attributes + * @param $tmp_file + * @param bool $onlyDescription + * @return mixed + */ protected function text2amda($tmp_file, $onlyDescription = false) { $suffix = explode('.', basename($tmp_file)); @@ -340,12 +356,12 @@ class TimeTableMgr extends AmdaObjectMgr $tempStop = $date[$dateLength]; if ($dateLength > 1) { - for ($i = 1; $i < $dateLength; $i++) { - $tempStart .= $date[$i]; + for ($iDate = 1; $iDate < $dateLength; $iDate++) { + $tempStart .= $date[$iDate]; } - for ($i = $dateLength + 1; $i < $dateLength * 2; $i++) { - $tempStop .= $date[$i]; + for ($iDate = $dateLength + 1; $iDate < $dateLength * 2; $iDate++) { + $tempStop .= $date[$iDate]; } } @@ -353,11 +369,11 @@ class TimeTableMgr extends AmdaObjectMgr $stopDate = date('Y-m-d\TH:i:s', strtotime($tempStop)); if (!$onlyDescription) { - $attributesToReturn['intervals'][] = array('start' => $startDate, 'stop' => $stopDate); + $attributesToReturn['intervals'][] = ['start' => $startDate, 'stop' => $stopDate]; } } else { if (!$onlyDescription) { - $attributesToReturn['intervals'][] = array('start' => trim($date[0]), 'stop' => trim($date[1])); + $attributesToReturn['intervals'][] = ['start' => trim($date[0]), 'stop' => trim($date[1])]; } } } @@ -373,9 +389,12 @@ class TimeTableMgr extends AmdaObjectMgr return $attributesToReturn; } - /* - * Uploaded vot TT => convert to array - */ + /** + * Convert VOTable time table to AMDA attributes + * @param $tmp_file + * @param bool $onlyDescription + * @return mixed + */ protected function vot2amda($tmp_file, $onlyDescription = false) { // Load Time table @@ -383,19 +402,22 @@ class TimeTableMgr extends AmdaObjectMgr $objToGet = $this->objectDom->getElementsByTagName('TABLEDATA')->item(0); $attributesToReturn['name'] = $tmp_file; $attributes = $objToGet->childNodes; + + /** @var DOMElement $attribute */ foreach ($attributes as $attribute) { if ($attribute->tagName == 'TR') { $start = $attribute->getElementsByTagName('TD')->item(0)->nodeValue; $stop = $attribute->getElementsByTagName('TD')->item(1)->nodeValue; if (!$onlyDescription) { - $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop); + $attributesToReturn['intervals'][] = ['start' => $start, 'stop' => $stop]; } } } $suffix = explode('.', basename($tmp_file)); $attributesToReturn['name'] = basename($tmp_file, '.' . $suffix[1]); $attributesToReturn['created'] = date('Y-m-d') . "T" . date('H:i:s'); - $attributesToReturn['description'] = htmlspecialchars($this->objectDom->getElementsByTagName('DESCRIPTION')->item(0)->nodeValue); + $description = $this->objectDom->getElementsByTagName('DESCRIPTION')->item(0)->nodeValue; + $attributesToReturn['description'] = htmlspecialchars($description); return ($attributesToReturn); } @@ -410,14 +432,14 @@ class TimeTableMgr extends AmdaObjectMgr { $filePath = USERWORKINGDIR . $folderId . '/' . $name . '.xml'; if (!file_exists($filePath)) { - return array('error' => 'Cannot find result file'); + return ['error' => 'Cannot find result file']; } $dom = new DomDocument('1.0'); $dom->formatOutput = true; if (!$dom->load($filePath)) { - return array('error' => 'Cannot load result file'); + return ['error' => 'Cannot load result file']; } $descNodes = $dom->getElementsByTagName('description'); @@ -440,25 +462,32 @@ class TimeTableMgr extends AmdaObjectMgr if (!$onlyDescription) { $intNodes = $dom->getElementsByTagName('intervals'); + + /** @var DOMElement $intNode */ foreach ($intNodes as $intNode) { $startNodes = $intNode->getElementsByTagName('start'); if ($startNodes->length <= 0) { - return array('error' => 'Error detected in result file'); + return ['error' => 'Error detected in result file']; } $stopNodes = $intNode->getElementsByTagName('stop'); if ($stopNodes->length <= 0) { - return array('error' => 'Error detected in result file'); + return ['error' => 'Error detected in result file']; } - $attributesToReturn['intervals'][] = array( + $attributesToReturn['intervals'][] = [ 'start' => $startNodes->item(0)->nodeValue, 'stop' => $stopNodes->item(0)->nodeValue - ); + ]; } } return $attributesToReturn; } + /** + * Merge time tables + * @param $obj + * @return array + */ public function merge($obj) { /** @@ -468,47 +497,45 @@ class TimeTableMgr extends AmdaObjectMgr */ $intervals = 0; - - for ($i = 0; $i < count($obj->ids); $i++) { - $table[$i] = $this->loadIntervalsFromTT($obj->ids[$i]); - for ($j = 0; $j < count($table[$i]['intervals']); $j++) { - $interval[$i][$j][0] = $table[$i]['intervals'][$j]['start']; - $interval[$i][$j][1] = $table[$i]['intervals'][$j]['stop']; + for ($iId = 0; $iId < count($obj->ids); $iId++) { + $table[$iId] = $this->loadIntervalsFromTT($obj->ids[$iId]); + for ($jId = 0; $jId < count($table[$iId]['intervals']); $jId++) { + $interval[$iId][$jId][0] = $table[$iId]['intervals'][$jId]['start']; + $interval[$iId][$jId][1] = $table[$iId]['intervals'][$jId]['stop']; } - $intervals += count($interval[$i]); + $intervals += count($interval[$iId]); } if ($intervals > 10000) { set_time_limit(1800); } - $final = array(); - for ($i = 0; $i < count($obj->ids); $i++) { - $final = array_merge($final, $interval[$i]); + $final = []; + for ($iId = 0; $iId < count($obj->ids); $iId++) { + $final = array_merge($final, $interval[$iId]); } sort($final); // Algorithm of union $line = 0; - $i = 0; - $a = $final[$i][0]; - while ($i < count($final) - 1) { - if ($final[$i + 1][1] <= $final[$i][1]) { - array_splice($final, $i + 1, 1); + $iId = 0; + $val = $final[$iId][0]; + while ($iId < count($final) - 1) { + if ($final[$iId + 1][1] <= $final[$iId][1]) { + array_splice($final, $iId + 1, 1); } else { - if (($final[$i + 1][0] <= $final[$i][1]) && ($final[$i + 1][1] >= $final[$i][1])) { - $i++; + if (($final[$iId + 1][0] <= $final[$iId][1]) && ($final[$iId + 1][1] >= $final[$iId][1])) { + $iId++; } else { - $start[$line] = $a; - $stop[$line] = $final[$i][1]; - $i++; + $start[$line] = $val; + $stop[$line] = $final[$iId][1]; + $iId++; $line++; - $a = $final[$i][0]; + $val = $final[$iId][0]; } } } - $start[$line] = $a; - $stop[$line] = $final[$i][1]; - $line++; + $start[$line] = $val; + $stop[$line] = $final[$iId][1]; $objTT = new stdClass(); $objTT->name = $obj->name; @@ -516,28 +543,34 @@ class TimeTableMgr extends AmdaObjectMgr $objTT->leaf = true; $objTT->created = null; $objTT->history = $obj->history; - for ($i = 0; $i < count($start); $i++) { + for ($iId = 0; $iId < count($start); $iId++) { $inter = new stdClass(); - $inter->start = $start[$i]; - $inter->stop = $stop[$i]; + $inter->start = $start[$iId]; + $inter->stop = $stop[$iId]; $objTT->intervals[] = $inter; } $objTT->nbIntervals = count($start); $this->objectDom = new DomDocument('1.0'); $this->objectDom->formatOutput = true; - $res = $this->createParameter($objTT, $folder); + $res = $this->createParameter($objTT, $folder); // FIXME $folder is undefined if ($res['error']) { return $res; } $this->saveIntervals($res['id'], $objTT->intervals, 'merge'); - return $res; - } - public function loadIntervalsFromTT($id, $typeTT, $start = null, $limit = null) + /** + * Load intervals from time table + * @param $id + * @param $typeTT + * @param null $start + * @param null $limit + * @return array + */ + public function loadIntervalsFromTT($id, $typeTT = '', $start = null, $limit = null) { if ($typeTT == 'sharedtimeTable') { //Shared object @@ -549,59 +582,68 @@ class TimeTableMgr extends AmdaObjectMgr //load intervals from TT id if (!file_exists($path)) { - return array('success' => false, 'message' => "Cannot find TT file " . $id); + return ['success' => false, 'message' => "Cannot find TT file " . $id]; } $this->objectDom->load($path); if (!($objToGet = $this->objectDom->getElementById($id))) { - return array('success' => false, 'message' => NO_SUCH_ID . " " . $id); + return ['success' => false, 'message' => NO_SUCH_ID . " " . $id]; } $xpath = new DOMXPath($this->objectDom); $intervals = $xpath->query('//intervals'); - $result = array(); + $result = []; if (!isset($start) || !isset($limit)) { + + /** @var DOMElement $interval */ foreach ($intervals as $interval) { $startTime = $interval->getElementsByTagName('start')->item(0)->nodeValue; $stopTime = $interval->getElementsByTagName('stop')->item(0)->nodeValue; - array_push($result, array('start' => $startTime, 'stop' => $stopTime)); + array_push($result, ['start' => $startTime, 'stop' => $stopTime]); } } else { - for ($i = 0; $i < $limit; ++$i) { - if ($start + $i >= $intervals->length) { + for ($iInt = 0; $iInt < $limit; ++$iInt) { + if ($start + $iInt >= $intervals->length) { break; } - $startTime = $intervals->item($start + $i)->getElementsByTagName('start')->item(0)->nodeValue; - $stopTime = $intervals->item($start + $i)->getElementsByTagName('stop')->item(0)->nodeValue; - array_push($result, array('start' => $startTime, 'stop' => $stopTime)); + $startTime = $intervals->item($start + $iInt)->getElementsByTagName('start')->item(0)->nodeValue; + $stopTime = $intervals->item($start + $iInt)->getElementsByTagName('stop')->item(0)->nodeValue; + array_push($result, ['start' => $startTime, 'stop' => $stopTime]); } } - return array( + return [ 'totalCount' => $intervals->length, 'intervals' => $result, 'start' => isset($start) ? $start : 0, 'limit' => isset($limit) ? $limit : 0, 'success' => true - ); + ]; } + /** + * Save intervals + * @param $id + * @param $intervals + * @param $action + * @return array + */ public function saveIntervals($id, $intervals, $action) { if (substr($id, 0, 6) == 'shared') { - return array('success' => false, 'message' => "Cannot save shared TimeTable"); + return ['success' => false, 'message' => "Cannot save shared TimeTable"]; } else { $path = USERTTDIR . $id . '.xml'; } if (!file_exists($path)) { - return array('success' => false, 'message' => "Cannot find TT file " . $id); + return ['success' => false, 'message' => "Cannot find TT file " . $id]; } $this->objectDom->load($path); if (!($objToGet = $this->objectDom->getElementById($id))) { - return array('success' => false, 'message' => NO_SUCH_ID . " " . $id); + return ['success' => false, 'message' => NO_SUCH_ID . " " . $id]; } //remove old intervals @@ -631,9 +673,14 @@ class TimeTableMgr extends AmdaObjectMgr unset($this->objectDom); - return array('success' => true, 'action' => $action, 'nbIntervals' => count($intervals)); + return ['success' => true, 'action' => $action, 'nbIntervals' => count($intervals)]; } + /** + * Create interval element + * @param $interval + * @return DOMElement + */ protected function createIntervalElement($interval) { $newInterval = $this->objectDom->createElement('intervals'); @@ -642,16 +689,21 @@ class TimeTableMgr extends AmdaObjectMgr return $newInterval; } + /** + * Intersect time tables + * @param $obj + * @return array|string + */ public function intersect($obj) { - - for ($i = 0; $i < count($obj->ids); $i++) { - $table[$i] = $this->loadIntervalsFromTT($obj->ids[$i]); - for ($j = 0; $j < count($table[$i]['intervals']); $j++) { - $interval[$i][$j][0] = $table[$i]['intervals'][$j]['start']; - $interval[$i][$j][1] = $table[$i]['intervals'][$j]['stop']; + $intervals = 0; + for ($iId = 0; $iId < count($obj->ids); $iId++) { + $table[$iId] = $this->loadIntervalsFromTT($obj->ids[$iId]); + for ($jId = 0; $jId < count($table[$iId]['intervals']); $jId++) { + $interval[$iId][$jId][0] = $table[$iId]['intervals'][$jId]['start']; + $interval[$iId][$jId][1] = $table[$iId]['intervals'][$jId]['stop']; } - $intervals += count($interval[$i]); + $intervals += count($interval[$iId]); } if ($intervals > 10000) { set_time_limit(1800); @@ -661,12 +713,12 @@ class TimeTableMgr extends AmdaObjectMgr sort($interval[0]); sort($interval[1]); - $i = 0; - $j = 0; + $iId = 0; + $jId = 0; $line = 0; - while (($i < count($interval[0])) && ($j < count($interval[1]))) { - $inter = $this->call_intersection($interval[0][$i], $interval[1][$j]); + while (($iId < count($interval[0])) && ($jId < count($interval[1]))) { + $inter = $this->callIntersection($interval[0][$iId], $interval[1][$jId]); if ($inter[0][0] != 0 && $inter[0][1] != 0) { $start[$line] = $inter[0][0]; @@ -674,10 +726,10 @@ class TimeTableMgr extends AmdaObjectMgr $line++; } - if ($interval[0][$i][1] < $interval[1][$j][1]) { - $i++; + if ($interval[0][$iId][1] < $interval[1][$jId][1]) { + $iId++; } else { - $j++; + $jId++; } } @@ -685,15 +737,15 @@ class TimeTableMgr extends AmdaObjectMgr if ($line == 0) { $result = "empty"; } else { - $objTT->name = $obj->name; + $objTT->name = $obj->name; // FIXME $objTT is undefined $objTT->nodeType = 'timeTable'; $objTT->leaf = true; $objTT->created = null; $objTT->history = $obj->history; - for ($i = 0; $i < count($start); $i++) { + for ($iId = 0; $iId < count($start); $iId++) { $inter = new stdClass(); - $inter->start = $start[$i]; - $inter->stop = $stop[$i]; + $inter->start = $start[$iId]; + $inter->stop = $stop[$iId]; $objTT->intervals[] = $inter; } $objTT->nbIntervals = count($start); @@ -703,32 +755,37 @@ class TimeTableMgr extends AmdaObjectMgr } else { $this->objectDom = new DomDocument('1.0'); $this->objectDom->formatOutput = true; - $result = $this->createObject($objTT, $folder); + $result = $this->createObject($objTT, $folder); // FIXME $folder is undefined if (!isset($result['error'])) { $this->saveIntervals($result['id'], $objTT->intervals, 'intersect'); } - } } return $result; } - protected function call_intersection($fst, $snd) + /** + * Call intersection + * @param $fst + * @param $snd + * @return array + */ + protected function callIntersection($fst, $snd) { $inf = ($fst[0] > $snd[0]) ? $fst[0] : $snd[0]; $sup = ($fst[1] < $snd[1]) ? $fst[1] : $snd[1]; - if ($inf >= $sup) { - $inter[] = array(0, 0); - } else { - $inter[] = array($inf, $sup); - } + $inter[] = ($inf >= $sup) ? [0, 0] : [$inf, $sup]; return $inter; } - //TODO getObject only!!!! => change DD_Search output - - function validNameObject($p) + /** + * Valid name object + * TODO getObject only!!!! => change DD_Search output + * @param $p + * @return array + */ + public function validNameObject($p) { // overwritten $res = parent::validNameObject($p); @@ -739,16 +796,21 @@ class TimeTableMgr extends AmdaObjectMgr //no space if (strpos($p->name, ' ') === false) { - return array('valid' => true); + return ['valid' => true]; } - return array('valid' => false, 'error' => 'Space character is not allowed'); + return ['valid' => false, 'error' => 'Space character is not allowed']; } - /* - * merge time tables - */ - + /** + * Copy time table + * @param $src_path + * @param $dst_path + * @param $newId + * @param $newName + * @param null $newDescription + * @return bool + */ public function copyTT($src_path, $dst_path, $newId, $newName, $newDescription = null) { if (!file_exists($src_path)) { @@ -800,21 +862,23 @@ class TimeTableMgr extends AmdaObjectMgr $descriptionNode->nodeValue = $newDescription; } - $dst_file_path = $dst_path . "/" . $newId . ".xml"; - if ($dom->save($dst_file_path) === false) { + $dstFilePath = $dst_path . "/" . $newId . ".xml"; + if ($dom->save($dstFilePath) === false) { return false; } - chgrp($dst_file_path, APACHE_USER); - chmod($dst_file_path, 0775); + chgrp($dstFilePath, APACHE_USER); + chmod($dstFilePath, 0775); return true; } - /* - * intersect time tables + /** + * Rename in resource + * @param $name + * @param $id + * @return bool */ - protected function renameInResource($name, $id) { if (!file_exists(USERTTDIR . $id . '.xml')) { @@ -831,6 +895,10 @@ class TimeTableMgr extends AmdaObjectMgr return true; } + /** + * Delete parameter + * @param $id + */ protected function deleteParameter($id) { if (file_exists(USERTTDIR . $id . '.xml')) { @@ -838,11 +906,14 @@ class TimeTableMgr extends AmdaObjectMgr } } + /** + * Rename only + * @param $p + * @return bool + */ protected function renameOnly($p) { //if (!($p->intervals)) return true; return false; } } - -?> -- libgit2 0.21.2