public function preSave() { if ($this->getType() == 'action') { if ($this->getConfiguration('infoName') == '') { throw new Exception('Le nom de la commande info ne peut etre vide'); } $actionInfo = virtualCmd::byEqLogicIdCmdName($this->getEqLogic_id(), $this->getConfiguration('infoName')); if (!is_object($actionInfo)) { $actionInfo = new virtualCmd(); $actionInfo->setType('info'); $actionInfo->setSubType('string'); $actionInfo->setCache('enable', 0); } $actionInfo->setEventOnly(0); $actionInfo->setConfiguration('virtualAction', 1); $actionInfo->setName($this->getConfiguration('infoName')); $actionInfo->setEqLogic_id($this->getEqLogic_id()); $actionInfo->setConfiguration('value', $this->getConfiguration('value')); $actionInfo->save(); $this->setConfiguration('infoId', $actionInfo->getId()); } else { $this->setConfiguration('calcul', cmd::humanReadableToCmd($this->getConfiguration('calcul'))); } }
public static function durationBetween($_cmd_id, $_value, $_startDate, $_endDate) { if (!is_numeric(str_replace('#', '', $_cmd_id))) { $cmd = cmd::byId(str_replace('#', '', cmd::humanReadableToCmd($_cmd_id))); } else { $cmd = cmd::byId(str_replace('#', '', $_cmd_id)); } if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } $cmd_id = $cmd->getId(); $_startDate = date('Y-m-d H:i:s', strtotime(self::setTags($_startDate))); $_endDate = date('Y-m-d H:i:s', strtotime(self::setTags($_endDate))); $_value = str_replace(',', '.', $_value); $_decimal = strlen(substr(strrchr($_value, "."), 1)); $histories = $cmd->getHistory(); $duration = 0; $lastDuration = strtotime($histories[0]->getDatetime()); $lastValue = $histories[0]->getValue(); foreach ($histories as $history) { if ($history->getDatetime() >= $_startDate) { if ($history->getDatetime() <= $_endDate) { if ($lastValue == $_value) { $duration = $duration + (strtotime($history->getDatetime()) - $lastDuration); } } else { if ($lastValue == $_value) { $duration = $duration + (strtotime($_endDate) - $lastDuration); } break; } $lastDuration = strtotime($history->getDatetime()); } else { $lastDuration = strtotime($_startDate); } $lastValue = round($history->getValue(), $_decimal); } if ($lastValue == $_value and $lastDuration <= strtotime($_endDate)) { $duration = $duration + (strtotime($_endDate) - $lastDuration); } return floor($duration / 60); }
public static function fromHumanReadable($_input) { return scenario::fromHumanReadable(eqLogic::fromHumanReadable(cmd::humanReadableToCmd($_input))); }
if (init('action') == 'getByObjectNameCmdName') { $cmd = cmd::byObjectNameCmdName(init('object_name'), init('cmd_name')); if (!is_object($cmd)) { throw new Exception(__('Cmd inconnu : ', __FILE__) . init('object_name') . '/' . init('cmd_name'), 9999); } ajax::success(utils::o2a($cmd)); } if (init('action') == 'byId') { $cmd = cmd::byId(init('id')); if (!is_object($cmd)) { throw new Exception(__('Cmd inconnu : ', __FILE__) . init('id'), 9999); } ajax::success(utils::o2a($cmd)); } if (init('action') == 'byHumanName') { $cmd_id = cmd::humanReadableToCmd(init('humanName')); $cmd = cmd::byId(str_replace('#', '', $cmd_id)); if (!is_object($cmd)) { throw new Exception(__('Cmd inconnu : ', __FILE__) . init('humanName'), 9999); } ajax::success(utils::o2a($cmd)); } if (init('action') == 'usedBy') { $cmd = cmd::byId(init('id')); if (!is_object($cmd)) { throw new Exception(__('Cmd inconnu : ', __FILE__) . init('id'), 9999); } $result = $cmd->getUsedBy(); $return = array('cmd' => array(), 'eqLogic' => array(), 'scenario' => array()); foreach ($result['cmd'] as $cmd) { $info = utils::o2a($cmd);
public function setTrigger($trigger) { if (is_array($trigger)) { $trigger = json_encode($trigger, JSON_UNESCAPED_UNICODE); } $this->trigger = cmd::humanReadableToCmd($trigger); }