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 function preSave() { if ($this->getConfiguration('virtualAction') == 1) { $actionInfo = virtualCmd::byEqLogicIdCmdName($this->getEqLogic_id(), $this->getName()); if (is_object($actionInfo)) { $this->setId($actionInfo->getId()); } } if ($this->getType() == 'action') { if ($this->getConfiguration('infoName') == '') { throw new Exception(__('Le nom de la commande info ne peut etre vide', __FILE__)); } $cmd = cmd::byId(str_replace('#', '', $this->getConfiguration('infoName'))); if (is_object($cmd)) { $this->setSubType($cmd->getSubType()); $this->setEventOnly(1); } else { $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(1); $actionInfo->setConfiguration('virtualAction', 1); $actionInfo->setName($this->getConfiguration('infoName')); $actionInfo->setEqLogic_id($this->getEqLogic_id()); $actionInfo->save(); $this->setConfiguration('infoId', $actionInfo->getId()); } } else { $calcul = $this->getConfiguration('calcul'); if (strpos($this->getConfiguration('calcul'), '#' . $this->getId() . '#') !== false) { throw new Exception(__('Vous ne pouvez faire un calcul sur la valeur elle meme (boucle infinie)!!!', __FILE__)); } $this->setConfiguration('calcul', $calcul); preg_match_all("/#([0-9]*)#/", $calcul, $matches); $value = ''; foreach ($matches[1] as $cmd_id) { if (is_numeric($cmd_id)) { $cmd = self::byId($cmd_id); if (is_object($cmd) && $cmd->getType() == 'info') { $value .= '#' . $cmd_id . '#'; } } } if ($value != '') { $this->setValue($value); } } }