public static function getExpressionOptions($_expression, $_options) { $startLoadTime = getmicrotime(); $cmd = cmd::byId(str_replace('#', '', cmd::humanReadableToCmd($_expression))); if (is_object($cmd)) { $return['html'] = trim($cmd->toHtml('scenario', $_options)); } else { try { $return['html'] = getTemplate('core', 'scenario', $_expression . '.default'); if (is_json($_options)) { $_options = json_decode($_options, true); } if (is_array($_options) && count($_options) > 0) { foreach ($_options as $key => $value) { $replace['#' . $key . '#'] = $value; } } if (!isset($replace['#id#'])) { $replace['#id#'] = rand(); } $return['html'] = template_replace(cmd::cmdToHumanReadable($replace), $return['html']); } catch (Exception $e) { } } $replace = array('#uid#' => 'exp' . mt_rand()); $return['html'] = translate::exec(template_replace($replace, $return['html']), 'core/template/scenario/' . $_expression . '.default'); return $return; }
public static function toHumanReadable($_input) { return scenario::toHumanReadable(eqLogic::toHumanReadable(cmd::cmdToHumanReadable($_input))); }
} $result['link_id'] = trim(trim($link_id), '&&'); } } ajax::success($results); } if (init('action') == 'byId') { $result = utils::o2a(interactDef::byId(init('id'))); $result['nbInteractQuery'] = count(interactQuery::byInteractDefId($result['id'])); $result['nbEnableInteractQuery'] = count(interactQuery::byInteractDefId($result['id'], true)); if ($result['link_type'] == 'cmd' && $result['link_id'] != '') { $link_id = ''; foreach (explode('&&', $result['link_id']) as $cmd_id) { $cmd = cmd::byId($cmd_id); if (is_object($cmd)) { $link_id .= cmd::cmdToHumanReadable('#' . $cmd->getId() . '# && '); } } $result['link_id'] = trim(trim($link_id), '&&'); } ajax::success(jeedom::toHumanReadable($result)); } if (init('action') == 'save') { $interact_json = jeedom::fromHumanReadable(json_decode(init('interact'), true)); if (isset($interact_json['id'])) { $interact = interactDef::byId($interact_json['id']); } if (!isset($interact) || !is_object($interact)) { $interact = new interactDef(); } utils::a2o($interact, $interact_json);
foreach ($result['eqLogic'] as $eqLogic) { $info = utils::o2a($eqLogic); $info['humanName'] = $eqLogic->getHumanName(); $info['link'] = $eqLogic->getLinkToConfiguration(); $return['eqLogic'][] = $info; } foreach ($result['scenario'] as $scenario) { $info = utils::o2a($cmd); $info['humanName'] = $scenario->getHumanName(); $info['link'] = $scenario->getLinkToConfiguration(); $return['scenario'][] = $info; } ajax::success($return); } if (init('action') == 'getHumanCmdName') { ajax::success(cmd::cmdToHumanReadable('#' . init('id') . '#')); } if (init('action') == 'byEqLogic') { ajax::success(utils::o2a(cmd::byEqLogicId(init('eqLogic_id')))); } if (init('action') == 'getCmd') { $cmd = cmd::byId(init('id')); if (!is_object($cmd)) { throw new Exception(__('Cmd ID inconnu : ', __FILE__) . init('id')); } $return = jeedom::toHumanReadable(utils::o2a($cmd)); $eqLogic = $cmd->getEqLogic(); $return['eqLogic_name'] = $eqLogic->getName(); $return['plugin'] = $eqLogic->getEqType_Name(); if ($eqLogic->getObject_id() > 0) { $return['object_name'] = $eqLogic->getObject()->getName();
public static function consystencyCheck() { foreach (self::all() as $scenario) { if ($scenario->getIsActive() != 1) { continue; } if ($scenario->getMode() == 'provoke' || $scenario->getMode() == 'all') { $trigger_list = ''; if (is_array($scenario->getTrigger())) { foreach ($scenario->getTrigger() as $trigger) { $trigger_list .= cmd::cmdToHumanReadable($trigger); } } else { $trigger_list = cmd::cmdToHumanReadable($scenario->getTrigger()); } preg_match_all("/#([0-9]*)#/", $trigger_list, $matches); foreach ($matches[1] as $cmd_id) { if (is_numeric($cmd_id)) { log::add('scenario', 'error', __('Un déclencheur du scénario : ', __FILE__) . $scenario->getHumanName() . __(' est introuvable', __FILE__)); } } } $expression_list = ''; foreach ($scenario->getElement() as $element) { foreach ($element->getSubElement() as $subElement) { foreach ($subElement->getExpression() as $expression) { $expression_list .= cmd::cmdToHumanReadable($expression->getExpression()) . ' _ '; if (is_array($expression->getOptions())) { foreach ($expression->getOptions() as $key => $value) { $expression_list .= cmd::cmdToHumanReadable($value) . ' _ '; } } } } } preg_match_all("/#([0-9]*)#/", $expression_list, $matches); foreach ($matches[1] as $cmd_id) { if (is_numeric($cmd_id)) { log::add('scenario', 'error', __('Une commande du scénario : ', __FILE__) . $scenario->getHumanName() . __(' est introuvable', __FILE__)); } } } }