diff --git a/src/Ajax/CmdAjax.php b/src/Ajax/CmdAjax.php index 19230c3a4..e8dd90b61 100644 --- a/src/Ajax/CmdAjax.php +++ b/src/Ajax/CmdAjax.php @@ -19,6 +19,7 @@ use NextDom\Enums\ActionRight; use NextDom\Enums\AjaxParams; +use NextDom\Enums\CmdConfigKey; use NextDom\Enums\CmdType; use NextDom\Enums\CmdViewType; use NextDom\Enums\Common; @@ -57,7 +58,6 @@ class CmdAjax extends BaseAjax * Get one or more command(s) HTML render * * @throws CoreException - * @throws \ReflectionException */ public function toHtml() { @@ -71,7 +71,7 @@ public function toHtml() } $result[$cmd->getId()] = [ 'html' => $cmd->toHtml($value[Common::VERSION]), - 'id' => $cmd->getId(), + AjaxParams::ID => $cmd->getId(), ]; } $this->ajax->success($result); @@ -79,10 +79,10 @@ public function toHtml() // Render one command $cmd = CmdManager::byId(Utils::init(AjaxParams::ID)); if (!is_object($cmd)) { - throw new CoreException(__('Commande inconnue - Vérifiez l\'id')); + throw new CoreException(__('Commande inconnue - Vérifiez l\'ID')); } $result = []; - $result['id'] = $cmd->getId(); + $result[AjaxParams::ID] = $cmd->getId(); $result['html'] = $cmd->toHtml(Utils::init(AjaxParams::VERSION), Utils::init(AjaxParams::OPTION), Utils::init('cmdColor', null)); $this->ajax->success($result); } @@ -92,7 +92,6 @@ public function toHtml() * Execute a command * * @throws CoreException - * @throws \ReflectionException */ public function execCmd() { @@ -306,7 +305,7 @@ public function save() { AuthentificationHelper::isConnectedAsAdminOrFail(); $cmdAjaxData = NextDomHelper::fromHumanReadable(json_decode(Utils::init(NextDomObj::CMD), true)); - $cmd = CmdManager::byId($cmdAjaxData['id']); + $cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]); if (!is_object($cmd)) { $cmd = new Cmd(); } @@ -326,7 +325,7 @@ public function multiSave() AuthentificationHelper::isConnectedAsAdminOrFail(); $cmds = json_decode(Utils::init(NextDomObj::CMD), true); foreach ($cmds as $cmdAjaxData) { - $cmd = CmdManager::byId($cmdAjaxData['id']); + $cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]); if (!is_object($cmd)) { continue; } @@ -419,8 +418,8 @@ public function getHistory() if ($dateStart !== '') { $dateStart = Utils::init(AjaxParams::DATE_START, date(DateFormat::FULL_DAY, strtotime(ConfigManager::byKey('history::defautShowPeriod') . ' ' . date(DateFormat::FULL_DAY)))); } - $result['maxValue'] = ''; - $result['minValue'] = ''; + $result[CmdConfigKey::MAX_VALUE] = ''; + $result[CmdConfigKey::MIN_VALUE] = ''; if ($dateStart === null) { $result['dateStart'] = ''; } else { @@ -482,11 +481,11 @@ public function getHistory() } $infoHistory[] = $value; if (!$NEXTDOM_INTERNAL_CONFIG[NextDomObj::CMD][Common::TYPE][Common::INFO][Common::SUBTYPE][$cmd->getSubType()][Common::IS_HISTORIZED][Common::TIMELINE_ONLY]) { - if (($value !== null && $value > $result['maxValue']) || $result['maxValue'] == '') { - $result['maxValue'] = round($value, 1); + if (($value !== null && $value > $result[CmdConfigKey::MAX_VALUE]) || $result[CmdConfigKey::MAX_VALUE] == '') { + $result[CmdConfigKey::MAX_VALUE] = round($value, 1); } - if (($value !== null && $value < $result['minValue']) || $result['minValue'] == '') { - $result['minValue'] = round($value, 1); + if (($value !== null && $value < $result[CmdConfigKey::MIN_VALUE]) || $result[CmdConfigKey::MIN_VALUE] == '') { + $result[CmdConfigKey::MIN_VALUE] = round($value, 1); } } $data[] = $infoHistory; @@ -498,18 +497,18 @@ public function getHistory() $infoHistory = []; $infoHistory[] = floatval($datetime) * 1000; $infoHistory[] = ($value === null) ? null : floatval($value); - if ($value > $result['maxValue'] || $result['maxValue'] == '') { - $result['maxValue'] = round($value, 1); + if ($value > $result[CmdConfigKey::MAX_VALUE] || $result[CmdConfigKey::MAX_VALUE] == '') { + $result[CmdConfigKey::MAX_VALUE] = round($value, 1); } - if ($value < $result['minValue'] || $result['minValue'] == '') { - $result['minValue'] = round($value, 1); + if ($value < $result[CmdConfigKey::MIN_VALUE] || $result[CmdConfigKey::MIN_VALUE] == '') { + $result[CmdConfigKey::MIN_VALUE] = round($value, 1); } $data[] = $infoHistory; } } $result['cmd_name'] = $cmdId; $result['history_name'] = $cmdId; - $result['unite'] = Utils::init('unite'); + $result[Common::UNITE] = Utils::init(Common::UNITE); } $result['data'] = $data; $this->ajax->success($result); @@ -544,10 +543,10 @@ public function setOrder() $cmds = json_decode(Utils::init('cmds'), true); $eqLogics = []; foreach ($cmds as $cmdJsonData) { - if (!isset($cmdJsonData['id']) || trim($cmdJsonData['id']) == '') { + if (!isset($cmdJsonData[AjaxParams::ID]) || trim($cmdJsonData[AjaxParams::ID]) == '') { continue; } - $cmd = CmdManager::byId($cmdJsonData['id']); + $cmd = CmdManager::byId($cmdJsonData[AjaxParams::ID]); if (!is_object($cmd)) { continue; } @@ -555,16 +554,16 @@ public function setOrder() $cmd->setOrder($cmdJsonData['order']); $cmd->save(); } - if (isset($cmdJsonData['line']) && isset($cmdJsonData['column'])) { + if (isset($cmdJsonData['line']) && isset($cmdJsonData[Common::COLUMN])) { $renderVersion = Utils::init(AjaxParams::VERSION, CmdViewType::DASHBOARD); if (!isset($eqLogics[$cmd->getEqLogic_id()])) { $eqLogics[$cmd->getEqLogic_id()] = [NextDomObj::EQLOGIC => $cmd->getEqLogic(), Common::CHANGED => false]; } $layoutDisplay = 'layout::' . $renderVersion . '::table::cmd::' . $cmd->getId(); if ($eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::line') != $cmdJsonData['line'] - || $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData['column']) { + || $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData[Common::COLUMN]) { $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::line', $cmdJsonData['line']); - $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData['column']); + $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData[Common::COLUMN]); $eqLogics[$cmd->getEqLogic_id()][Common::CHANGED] = true; } } diff --git a/src/Ajax/EqLogicAjax.php b/src/Ajax/EqLogicAjax.php index 619b226f1..c03fbf0a2 100644 --- a/src/Ajax/EqLogicAjax.php +++ b/src/Ajax/EqLogicAjax.php @@ -26,9 +26,11 @@ use NextDom\Helpers\AuthentificationHelper; use NextDom\Helpers\NextDomHelper; use NextDom\Helpers\Utils; +use NextDom\Managers\CmdManager; use NextDom\Managers\EqLogicManager; use NextDom\Managers\JeeObjectManager; use NextDom\Model\Entity\Cmd; +use NextDom\Model\Entity\EqLogic; /** * Class EqLogicAjax @@ -52,7 +54,7 @@ public function getEqLogicObject() foreach ($linkedObject->getEqLogic() as $eqLogic) { if ($eqLogic->isVisible()) { $info_eqLogic = []; - $info_eqLogic[Common::ID] = $eqLogic->getId(); + $info_eqLogic[AjaxParams::ID] = $eqLogic->getId(); $info_eqLogic[Common::TYPE] = $eqLogic->getEqType_name(); $info_eqLogic[Common::OBJECT_ID] = $eqLogic->getObject_id(); $info_eqLogic[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION)); @@ -84,7 +86,7 @@ public function toHtml() throw new CoreException(__('Pas de version indiqué pour le rendu HTML')); } $result[$eqLogic->getId()] = [ - Common::ID => $eqLogic->getId(), + AjaxParams::ID => $eqLogic->getId(), Common::TYPE => $eqLogic->getEqType_name(), Common::OBJECT_ID => $eqLogic->getObject_id(), Common::HTML => $eqLogic->toHtml($eqLogicData[AjaxParams::VERSION]), @@ -97,7 +99,7 @@ public function toHtml() throw new CoreException(__('Eqlogic inconnu. Vérifiez l\'ID')); } $eqLogicInfo = []; - $eqLogicInfo[Common::ID] = $eqLogic->getId(); + $eqLogicInfo[AjaxParams::ID] = $eqLogic->getId(); $eqLogicInfo[Common::TYPE] = $eqLogic->getEqType_name(); $eqLogicInfo[Common::OBJECT_ID] = $eqLogic->getObject_id(); $eqLogicInfo[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION)); @@ -114,7 +116,7 @@ public function htmlAlert() } $result[$eqLogic->getId()] = [ Common::HTML => $eqLogic->toHtml(Utils::init(AjaxParams::VERSION)), - Common::ID => $eqLogic->getId(), + AjaxParams::ID => $eqLogic->getId(), Common::TYPE => $eqLogic->getEqType_name(), Common::OBJECT_ID => $eqLogic->getObject_id(), ]; @@ -145,7 +147,7 @@ public function htmlBattery() foreach ($list as $eqLogic) { $result[] = [ Common::HTML => $eqLogic->batteryWidget(Utils::init(AjaxParams::VERSION)), - Common::ID => $eqLogic->getId(), + AjaxParams::ID => $eqLogic->getId(), Common::TYPE => $eqLogic->getEqType_name(), Common::OBJECT_ID => $eqLogic->getObject_id(), ]; @@ -197,7 +199,7 @@ public function listByTypeAndCmdType() $eqLogicList = EqLogicManager::listByTypeAndCmdType(Utils::init(AjaxParams::TYPE), Utils::init(AjaxParams::TYPE_CMD), Utils::init(AjaxParams::SUB_TYPE_CMD)); $result = []; foreach ($eqLogicList as $eqLogic) { - $eqLogic = EqLogicManager::byId($eqLogic[Common::ID]); + $eqLogic = EqLogicManager::byId($eqLogic[AjaxParams::ID]); $info[NextDomObj::EQLOGIC] = Utils::o2a($eqLogic); $info[NextDomObj::OBJECT] = ['name' => 'Aucun']; if (is_object($eqLogic)) { @@ -230,10 +232,10 @@ public function setOrder() { $eqLogics = json_decode(Utils::init('eqLogics'), true); foreach ($eqLogics as $eqLogic_json) { - if (!isset($eqLogic_json[Common::ID]) || trim($eqLogic_json[Common::ID]) == '') { + if (!isset($eqLogic_json[AjaxParams::ID]) || trim($eqLogic_json[AjaxParams::ID]) == '') { continue; } - $eqLogic = EqLogicManager::byId($eqLogic_json[Common::ID]); + $eqLogic = EqLogicManager::byId($eqLogic_json[AjaxParams::ID]); if (!is_object($eqLogic)) { continue; } @@ -297,9 +299,9 @@ public function simpleSave() { AuthentificationHelper::isConnectedAsAdminOrFail(); $eqLogicSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true); - $eqLogic = EqLogicManager::byId($eqLogicSave[Common::ID]); + $eqLogic = EqLogicManager::byId($eqLogicSave[AjaxParams::ID]); if (!is_object($eqLogic)) { - throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[Common::ID]); + throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[AjaxParams::ID]); } if (!$eqLogic->hasRight(ActionRight::WRITE)) { @@ -355,7 +357,6 @@ public function get() public function save() { AuthentificationHelper::isConnectedAsAdminOrFail(); - $eqLogicsSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true); foreach ($eqLogicsSave as $eqLogicSave) { @@ -363,14 +364,15 @@ public function save() if (!is_array($eqLogicSave)) { throw new CoreException(__('Informations reçues incorrectes')); } - $typeEqLogic = Utils::init(AjaxParams::TYPE); + $typeEqLogic = Utils::initStr(AjaxParams::TYPE); $typeCmd = $typeEqLogic . NextDomObj::CMD; if ($typeEqLogic == '' || !class_exists($typeEqLogic) || !class_exists($typeCmd)) { throw new CoreException(__('Type incorrect, (classe commande inexistante)') . $typeCmd); } + /** @var EqLogic $eqLogic */ $eqLogic = null; - if (isset($eqLogicSave[Common::ID])) { - $eqLogic = $typeEqLogic::byId($eqLogicSave[Common::ID]); + if (isset($eqLogicSave[AjaxParams::ID])) { + $eqLogic = $typeEqLogic::byId($eqLogicSave[AjaxParams::ID]); } if (!is_object($eqLogic)) { $eqLogic = new $typeEqLogic(); @@ -385,7 +387,7 @@ public function save() } $eqLogicSave = NextDomHelper::fromHumanReadable($eqLogicSave); Utils::a2o($eqLogic, $eqLogicSave); - $dbList = $typeCmd::byEqLogicId($eqLogic->getId()); + $dbList = CmdManager::byEqLogicId($eqLogic->getId()); $eqLogic->save(); $enableList = []; @@ -393,8 +395,8 @@ public function save() $cmd_order = 0; foreach ($eqLogicSave[NextDomObj::CMD] as $cmd_info) { $cmd = null; - if (isset($cmd_info[Common::ID])) { - $cmd = $typeCmd::byId($cmd_info[Common::ID]); + if (isset($cmd_info[AjaxParams::ID])) { + $cmd = CmdManager::byId($cmd_info[AjaxParams::ID]); } if (!is_object($cmd)) { $cmd = new $typeCmd(); @@ -415,6 +417,7 @@ public function save() if (method_exists($eqLogic, 'postAjax')) { $eqLogic->postAjax(); } + $this->ajax->success(Utils::o2a($eqLogic)); } catch (\Exception $e) { if (strpos($e->getMessage(), '[MySQL] Error code : 23000') !== false) { if ($e->getTrace()[2]['class'] == NextDomObj::EQLOGIC) { @@ -426,7 +429,6 @@ public function save() throw new CoreException($e->getMessage()); } } - $this->ajax->success(Utils::o2a($eqLogic)); } $this->ajax->success(null); } diff --git a/src/Ajax/InteractAjax.php b/src/Ajax/InteractAjax.php index 95518869c..7bd230697 100644 --- a/src/Ajax/InteractAjax.php +++ b/src/Ajax/InteractAjax.php @@ -18,6 +18,8 @@ namespace NextDom\Ajax; use NextDom\Enums\AjaxParams; +use NextDom\Enums\Common; +use NextDom\Enums\SQLField; use NextDom\Enums\UserRight; use NextDom\Exceptions\CoreException; use NextDom\Helpers\NextDomHelper; @@ -42,18 +44,18 @@ public function all() $results = Utils::o2a(InteractDefManager::all()); foreach ($results as &$result) { // @TODO TOus sélectionnés dans tous les cas - $result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id'])); - $result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id'])); - if ($result['link_type'] == 'cmd' && $result['link_id'] != '') { - $link_id = ''; - foreach (explode('&&', $result['link_id']) as $cmd_id) { + $result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID])); + $result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID])); + if ($result[SQLField::LINK_TYPE] == 'cmd' && $result[SQLField::LINK_ID] != '') { + $linkId = ''; + foreach (explode('&&', $result[SQLField::LINK_ID]) as $cmd_id) { $cmd = CmdManager::byId($cmd_id); if (is_object($cmd)) { - $link_id .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && '); + $linkId .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && '); } } - $result['link_id'] = trim(trim($link_id), '&&'); + $result[SQLField::LINK_ID] = trim(trim($linkId), '&&'); } } $this->ajax->success($results); @@ -62,16 +64,16 @@ public function all() public function byId() { $result = Utils::o2a(InteractDefManager::byId(Utils::init(AjaxParams::ID))); - $result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id'])); - $result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id'])); + $result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID])); + $result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID])); $this->ajax->success(NextDomHelper::toHumanReadable($result)); } public function save() { $interact_json = NextDomHelper::fromHumanReadable(json_decode(Utils::init('interact'), true)); - if (isset($interact_json['id'])) { - $interact = InteractDefManager::byId($interact_json['id']); + if (isset($interact_json[AjaxParams::ID])) { + $interact = InteractDefManager::byId($interact_json[AjaxParams::ID]); } if (!isset($interact) || !is_object($interact)) { $interact = new InteractDef(); diff --git a/src/Ajax/ListenerAjax.php b/src/Ajax/ListenerAjax.php index 5898edcf9..bf0efa1b4 100644 --- a/src/Ajax/ListenerAjax.php +++ b/src/Ajax/ListenerAjax.php @@ -18,6 +18,7 @@ namespace NextDom\Ajax; use NextDom\Enums\AjaxParams; +use NextDom\Enums\Common; use NextDom\Enums\UserRight; use NextDom\Exceptions\CoreException; use NextDom\Helpers\NextDomHelper; @@ -54,11 +55,11 @@ public function all() { $listeners = Utils::o2a(ListenerManager::all()); foreach ($listeners as &$listener) { - $listener['event_str'] = ''; - foreach ($listener['event'] as $event) { - $listener['event_str'] .= $event . ','; + $listener[AjaxParams::EVENT_STR] = ''; + foreach ($listener[Common::EVENT] as $event) { + $listener[AjaxParams::EVENT_STR] .= $event . ','; } - $listener['event_str'] = NextDomHelper::toHumanReadable(trim($listener['event_str'], ',')); + $listener[AjaxParams::EVENT_STR] = NextDomHelper::toHumanReadable(trim($listener[AjaxParams::EVENT_STR], ',')); } $this->ajax->success($listeners); } diff --git a/src/Ajax/ObjectAjax.php b/src/Ajax/ObjectAjax.php index 073f2a8a7..973579058 100644 --- a/src/Ajax/ObjectAjax.php +++ b/src/Ajax/ObjectAjax.php @@ -113,8 +113,8 @@ public function save() { AuthentificationHelper::isConnectedAsAdminOrFail(); $jsonObject = json_decode(Utils::init(AjaxParams::OBJECT), true); - if (isset($jsonObject['id'])) { - $resultObject = JeeObjectManager::byId($jsonObject['id']); + if (isset($jsonObject[AjaxParams::ID])) { + $resultObject = JeeObjectManager::byId($jsonObject[AjaxParams::ID]); } if (!isset($resultObject) || !is_object($resultObject)) { $resultObject = new JeeObject(); @@ -157,80 +157,68 @@ public function toHtml() } else { $objectsList = []; if (Utils::init(AjaxParams::SUMMARY) == '') { - foreach (JeeObjectManager::buildTree(null, true) as $object) { - if ($object->getConfiguration('hideOnDashboard', 0) == 1) { + foreach (JeeObjectManager::buildTree(null, true) as $objectId) { + if ($objectId->getConfiguration('hideOnDashboard', 0) == 1) { continue; } - $objects[] = $object->getId(); + $objects[] = $objectId->getId(); } } else { - foreach (JeeObjectManager::all() as $object) { - $objects[] = $object->getId(); + foreach (JeeObjectManager::all() as $objectId) { + $objects[] = $objectId->getId(); } } } $result = []; $scenariosResult = []; $i = 0; - foreach ($objectsList as $id) { - $html = []; - if (Utils::init(AjaxParams::SUMMARY) == '') { - $eqLogics = EqLogicManager::byObjectId($id, true, true); - } else { - $resultObject = JeeObjectManager::byId($id); - $eqLogics = $resultObject->getEqLogicBySummary(Utils::init(AjaxParams::SUMMARY), true, false); - } - $this->toHtmlEqLogics($html, $eqLogics); - $scenarios = ScenarioManager::byObjectId($id, false, true); - if (count($scenarios) > 0) { - $scenariosResult[$i . '::' . $id] = []; - /** - * @var Scenario $scenario - */ - foreach ($scenarios as $scenario) { - $scenariosResult[$i . '::' . $id][] = [ - 'scenario_id' => $scenario->getId(), - 'state' => $scenario->getState(), - 'name' => $scenario->getName(), - 'icon' => $scenario->getDisplay(Common::ICON), - 'active' => $scenario->getIsActive() - ]; - } - } - ksort($html); - $result[$i . '::' . $id] = implode($html); + foreach ($objectsList as $objectId) { + $objectId = intval($objectId); + $htmlObject = $this->renderObjectAsHtml($objectId); + $scenariosResult = array_merge($scenariosResult, $this->renderScenariosAsHtml($objectId)); + $result[$i . '::' . $objectId] = implode($htmlObject); $i++; } $this->ajax->success([Common::OBJECT_HTML => $result, NextDomObj::SCENARIOS => $scenariosResult]); } else { $objectId = intval($objectId); - $html = []; - if (Utils::init(AjaxParams::SUMMARY) == '') { - $eqLogics = EqLogicManager::byObjectId($objectId, true, true); - } else { - $resultObject = JeeObjectManager::byId($objectId); - $eqLogics = $resultObject->getEqLogicBySummary($objectId, true, false); - } - $this->toHtmlEqLogics($html, $eqLogics); - $scenarios = ScenarioManager::byObjectId($objectId, false, true); - $scenariosResult = []; - if (count($scenarios) > 0) { - /** - * @var Scenario $scenario - */ - foreach ($scenarios as $scenario) { - $scenariosResult[] = [ - 'scenario_id' => $scenario->getId(), - 'state' => $scenario->getState(), - 'name' => $scenario->getName(), - 'icon' => $scenario->getDisplay('icon'), - 'active' => $scenario->getIsActive() - ]; - } + $htmlObject = $this->renderObjectAsHtml($objectId); + $scenariosObject = $this->renderScenariosAsHtml($objectId); + $this->ajax->success([Common::OBJECT_HTML => implode($htmlObject), NextDomObj::SCENARIOS => $scenariosObject]); + } + } + + private function renderObjectAsHtml($objectId) + { + $result = []; + if (Utils::init(AjaxParams::SUMMARY) == '') { + $eqLogics = EqLogicManager::byObjectId($objectId, true, true); + } else { + $resultObject = JeeObjectManager::byId($objectId); + $eqLogics = $resultObject->getEqLogicBySummary($objectId, true, false); + } + $this->toHtmlEqLogics($result, $eqLogics); + ksort($result); + return $result; + } + + private function renderScenariosAsHtml($objectId) + { + $scenarios = ScenarioManager::byObjectId($objectId, false, true); + $result = []; + if (count($scenarios) > 0) { + /** @var Scenario $scenario */ + foreach ($scenarios as $scenario) { + $result[] = [ + 'scenario_id' => $scenario->getId(), + 'state' => $scenario->getState(), + 'name' => $scenario->getName(), + 'icon' => $scenario->getDisplay('icon'), + 'active' => $scenario->getIsActive() + ]; } - ksort($html); - $this->ajax->success([Common::OBJECT_HTML => implode($html), NextDomObj::SCENARIOS => $scenariosResult]); } + return $result; } /** @@ -310,7 +298,7 @@ public function getSummaryHtml() if ($id == Common::GLOBAL) { $result[Common::GLOBAL] = [ Common::HTML => JeeObjectManager::getGlobalHtmlSummary($value[Common::VERSION]), - Common::ID => Common::GLOBAL + AjaxParams::ID => Common::GLOBAL ]; continue; } @@ -320,7 +308,7 @@ public function getSummaryHtml() } $result[$resultObject->getId()] = [ Common::HTML => $resultObject->getHtmlSummary($value[Common::VERSION]), - Common::ID => $resultObject->getId() + AjaxParams::ID => $resultObject->getId() ]; } $this->ajax->success($result); @@ -330,7 +318,7 @@ public function getSummaryHtml() throw new CoreException(__('Objet inconnu. Vérifiez l\'ID')); } $infoObject = []; - $infoObject[Common::ID] = $resultObject->getId(); + $infoObject[AjaxParams::ID] = $resultObject->getId(); $infoObject[Common::HTML] = $resultObject->getHtmlSummary(Utils::init(AjaxParams::VERSION)); $this->ajax->success($infoObject); } diff --git a/src/Ajax/ScenarioAjax.php b/src/Ajax/ScenarioAjax.php index aa4b87a52..6a73bcee1 100644 --- a/src/Ajax/ScenarioAjax.php +++ b/src/Ajax/ScenarioAjax.php @@ -67,6 +67,7 @@ public function changeState() throw new CoreException(__('Vous n\'êtes pas autorisé à faire cette action')); } switch (Utils::init(AjaxParams::STATE)) { + default: case 'start': if (!$scenario->getIsActive()) { throw new CoreException(__('Impossible de lancer le scénario car il est désactivé. Veuillez l\'activer')); @@ -110,10 +111,10 @@ public function setOrder() { $scenarios = json_decode(Utils::init(AjaxParams::SCENARIOS), true); foreach ($scenarios as $scenario_json) { - if (!isset($scenario_json[Common::ID]) || trim($scenario_json[Common::ID]) == '') { + if (!isset($scenario_json[AjaxParams::ID]) || trim($scenario_json[AjaxParams::ID]) == '') { continue; } - $scenario = ScenarioManager::byId($scenario_json[Common::ID]); + $scenario = ScenarioManager::byId($scenario_json[AjaxParams::ID]); if (!is_object($scenario)) { continue; } @@ -310,7 +311,7 @@ public function saveAll() $scenarios = json_decode(Utils::init(AjaxParams::SCENARIOS), true); if (is_array($scenarios)) { foreach ($scenarios as $scenario_ajax) { - $scenario = ScenarioManager::byId($scenario_ajax[Common::ID]); + $scenario = ScenarioManager::byId($scenario_ajax[AjaxParams::ID]); if (!is_object($scenario)) { continue; } @@ -437,7 +438,7 @@ public function get() if($scenarioLink->getId() == $scenario->getId()){ continue; } - $result['scenarioLinkBy'][NextDomObj::SCENARIO][$scenarioLink->getId()] = [Common::ID => $scenarioLink->getId(),Common::NAME => $scenarioLink->getHumanName(),'isActive' => $scenarioLink->getIsActive(),'isVisible' => $scenarioLink->getIsVisible()]; + $result['scenarioLinkBy'][NextDomObj::SCENARIO][$scenarioLink->getId()] = [AjaxParams::ID => $scenarioLink->getId(),Common::NAME => $scenarioLink->getHumanName(),'isActive' => $scenarioLink->getIsActive(),'isVisible' => $scenarioLink->getIsVisible()]; } $result['scenarioLinkIn'] = [NextDomObj::SCENARIO => []]; $scenarioUse = $scenario->getUse(); @@ -445,7 +446,7 @@ public function get() if($scenarioLink->getId() == $scenario->getId()){ continue; } - $result['scenarioLinkIn'][NextDomObj::SCENARIO][$scenarioLink->getId()] = [Common::ID => $scenarioLink->getId(),Common::NAME => $scenarioLink->getHumanName(),'isActive' => $scenarioLink->getIsActive(),'isVisible' => $scenarioLink->getIsVisible()]; + $result['scenarioLinkIn'][NextDomObj::SCENARIO][$scenarioLink->getId()] = [AjaxParams::ID => $scenarioLink->getId(),Common::NAME => $scenarioLink->getHumanName(),'isActive' => $scenarioLink->getIsActive(),'isVisible' => $scenarioLink->getIsVisible()]; } $this->ajax->success($result); } @@ -483,8 +484,8 @@ public function save() // Prepare object from Ajax data $scenarioAjaxData = json_decode(Utils::init(AjaxParams::SCENARIO), true); - if (isset($scenarioAjaxData[Common::ID])) { - $targetScenario = ScenarioManager::byId($scenarioAjaxData[Common::ID]); + if (isset($scenarioAjaxData[AjaxParams::ID])) { + $targetScenario = ScenarioManager::byId($scenarioAjaxData[AjaxParams::ID]); } if (!isset($targetScenario) || !is_object($targetScenario)) { $targetScenario = new Scenario(); @@ -533,7 +534,7 @@ public function actionToHtml() } $result[] = [ 'html' => $html, - Common::ID => $param[Common::ID], + AjaxParams::ID => $param[AjaxParams::ID], ]; } } diff --git a/src/Ajax/UpdateAjax.php b/src/Ajax/UpdateAjax.php index 655c4c00e..8593d8fb5 100644 --- a/src/Ajax/UpdateAjax.php +++ b/src/Ajax/UpdateAjax.php @@ -51,19 +51,17 @@ public function all() { AuthentificationHelper::isConnectedAsAdminOrFail(); $result = []; - /** - * @var Update $update - */ + /** @var Update $update */ foreach (UpdateManager::all(Utils::init(AjaxParams::FILTER)) as $update) { $infos = Utils::o2a($update); - if ($update->getType() == 'plugin') { + if ($update->getType() == AjaxParams::PLUGIN) { try { $plugin = PluginManager::byId($update->getLogicalId()); if (is_object($plugin)) { - $infos['plugin'] = Utils::o2a($plugin); - $infos['plugin']['icon'] = $plugin->getPathImgIcon(); + $infos[AjaxParams::PLUGIN] = Utils::o2a($plugin); + $infos[AjaxParams::PLUGIN]['icon'] = $plugin->getPathImgIcon(); } else { - $infos['plugin'] = []; + $infos[AjaxParams::PLUGIN] = []; } } catch (\Exception $e) { @@ -97,7 +95,7 @@ public function update() if ($update->getType() != 'core') { LogHelper::addAlert(LogTarget::UPDATE, __("Launch cron dependancy plugins")); try { - $cron = CronManager::byClassAndFunction('plugin', 'checkDeamon'); + $cron = CronManager::byClassAndFunction(AjaxParams::PLUGIN, 'checkDeamon'); if (is_object($cron)) { $cron->start(); } @@ -159,8 +157,8 @@ public function save() $backupUpdate = null; $updateDataJson = json_decode(Utils::init(AjaxParams::UPDATE), true); - if (isset($updateDataJson[Common::ID])) { - $targetUpdate = UpdateManager::byId($updateDataJson[Common::ID]); + if (isset($updateDataJson[AjaxParams::ID])) { + $targetUpdate = UpdateManager::byId($updateDataJson[AjaxParams::ID]); } elseif (isset($updateDataJson['logicalId'])) { $targetUpdate = UpdateManager::byLogicalId($updateDataJson[Common::LOGICAL_ID]); } diff --git a/src/Controller/Pages/AdministrationController.php b/src/Controller/Pages/AdministrationController.php index cb09121e9..9e18edf43 100644 --- a/src/Controller/Pages/AdministrationController.php +++ b/src/Controller/Pages/AdministrationController.php @@ -151,7 +151,6 @@ function ($value) { private static function countErrorLog(&$pageData) { $pageData['logCount'] = 0; - Utils::init('logfile'); $logFilesList = []; $dir = opendir(NEXTDOM_LOG); while ($file = readdir($dir)) { diff --git a/src/Enums/AjaxParams.php b/src/Enums/AjaxParams.php index af52c3325..0e2a9775a 100644 --- a/src/Enums/AjaxParams.php +++ b/src/Enums/AjaxParams.php @@ -40,6 +40,7 @@ class AjaxParams extends Enum const ENABLE = 'enable'; const EQLOGIC_NAME = 'eqLogic_name'; const EQTYPE_NAME = 'eqType_name'; + const EVENT_STR = 'event_str'; const EXPRESSION = 'expression'; const FILTER = 'filter'; const FORCE_RESTART = 'forceRestart'; diff --git a/src/Enums/Common.php b/src/Enums/Common.php index 2d9a6515d..2505adc11 100644 --- a/src/Enums/Common.php +++ b/src/Enums/Common.php @@ -36,6 +36,7 @@ class Common extends Enum const CMD_ID = 'cmd_id'; const CMD_PARAMETERS = 'cmd_parameters'; const COLOR = 'color'; + const COLUMN = 'column'; const CONFIGURATION = 'configuration'; const CORE = 'core'; const CUSTOM = 'custom';