Пример #1
0
 public function export()
 {
     $return = '';
     if ($this->getType() == 'element') {
         $element = scenarioElement::byId($this->getExpression());
         if (is_object($element)) {
             $exports = explode("\n", $element->export());
             foreach ($exports as $export) {
                 $return .= "    " . $export . "\n";
             }
         }
         return rtrim($return);
     }
     $options = $this->getOptions();
     if ($this->getType() == 'action') {
         if ($this->getExpression() == 'icon') {
             return '';
         } else {
             if ($this->getExpression() == 'sleep') {
                 return '(sleep) Pause de  : ' . $options['duration'];
             } else {
                 if ($this->getExpression() == 'stop') {
                     return '(stop) Arret du scenario';
                 } else {
                     if ($this->getExpression() == 'scenario') {
                         $actionScenario = scenario::byId($this->getOptions('scenario_id'));
                         if (is_object($actionScenario)) {
                             return '(scenario) ' . $this->getOptions('action') . ' de ' . $actionScenario->getHumanName();
                         }
                     } else {
                         if ($this->getExpression() == 'variable') {
                             return '(variable) Affectation de la variable : ' . $this->getOptions('name') . ' à ' . $this->getOptions('value');
                         } else {
                             $return = jeedom::toHumanReadable($this->getExpression());
                             if (is_array($options) && count($options) != 0) {
                                 $return .= ' - Options : ' . print_r(jeedom::toHumanReadable($options), true);
                             }
                             return $return;
                         }
                     }
                 }
             }
         }
     } else {
         if ($this->getType() == 'condition') {
             return jeedom::toHumanReadable($this->getExpression());
         }
     }
     if ($this->getType() == 'code') {
     }
 }
Пример #2
0
     if (!isset($scenario_db) || !is_object($scenario_db)) {
         $scenario_db = new scenario();
     } else {
         if (!$scenario_db->hasRight('w')) {
             throw new Exception(__('Vous n\'etês pas autorisé à faire cette action', __FILE__));
         }
     }
     $scenario_db->setTrigger(array());
     $scenario_db->setSchedule(array());
     utils::a2o($scenario_db, $scenario_ajax);
     $scenario_db->setConfiguration('timeDependency', $time_dependance);
     $scenario_db->save();
     $scenario_element_list = array();
     if (isset($scenario_ajax['elements'])) {
         foreach ($scenario_ajax['elements'] as $element_ajax) {
             $scenario_element_list[] = scenarioElement::saveAjaxElement($element_ajax);
         }
         $scenario_db->setScenarioElement($scenario_element_list);
     }
     $scenario_db->save();
     ajax::success(utils::o2a($scenario_db));
 }
 if (init('action') == 'actionToHtml') {
     ajax::success(scenarioExpression::getExpressionOptions(init('expression'), init('option')));
 }
 if (init('action') == 'templateupload') {
     $uploaddir = dirname(__FILE__) . '/../../core/config/scenario/';
     if (!file_exists($uploaddir)) {
         mkdir($uploaddir);
     }
     if (!file_exists($uploaddir)) {
Пример #3
0
 public function getElement()
 {
     if (count($this->_elements) > 0) {
         return $this->_elements;
     }
     $return = array();
     $elements = $this->getScenarioElement();
     if (is_array($elements)) {
         foreach ($this->getScenarioElement() as $element_id) {
             $element = scenarioElement::byId($element_id);
             if (is_object($element)) {
                 $return[] = $element;
             }
         }
         $this->_elements = $return;
         return $return;
     }
     if ($elements != '') {
         $element = scenarioElement::byId($element_id);
         if (is_object($element)) {
             $return[] = $element;
             $this->_elements = $return;
             return $return;
         }
     }
     return array();
 }
Пример #4
0
 public static function saveAjaxElement($element_ajax)
 {
     if (isset($element_ajax['id']) && $element_ajax['id'] != '') {
         $element_db = scenarioElement::byId($element_ajax['id']);
     } else {
         $element_db = new scenarioElement();
     }
     if (!isset($element_db) || !is_object($element_db)) {
         throw new Exception(__('Elément inconnu - Vérifiez l\'id : ', __FILE__) . $element_ajax['id']);
     }
     utils::a2o($element_db, $element_ajax);
     $element_db->save();
     $subElement_order = 0;
     $subElement_list = $element_db->getSubElement();
     $enable_subElement = array();
     foreach ($element_ajax['subElements'] as $subElement_ajax) {
         if (isset($subElement_ajax['id']) && $subElement_ajax['id'] != '') {
             $subElement_db = scenarioSubElement::byId($subElement_ajax['id']);
         } else {
             $subElement_db = new scenarioSubElement();
         }
         if (!isset($subElement_db) || !is_object($subElement_db)) {
             throw new Exception(__('Elément inconnu vérifier l\'id : ', __FILE__) . $subElement_ajax['id']);
         }
         utils::a2o($subElement_db, $subElement_ajax);
         $subElement_db->setScenarioElement_id($element_db->getId());
         $subElement_db->setOrder($subElement_order);
         $subElement_db->save();
         $subElement_order++;
         $enable_subElement[$subElement_db->getId()] = true;
         $expression_list = $subElement_db->getExpression();
         $expression_order = 0;
         $enable_expression = array();
         foreach ($subElement_ajax['expressions'] as &$expression_ajax) {
             if (isset($expression_ajax['scenarioSubElement_id']) && $expression_ajax['scenarioSubElement_id'] != $subElement_db->getId() && isset($expression_ajax['id']) && $expression_ajax['id'] != '') {
                 $expression_ajax['id'] = '';
             }
             if (isset($expression_ajax['id']) && $expression_ajax['id'] != '') {
                 $expression_db = scenarioExpression::byId($expression_ajax['id']);
             } else {
                 $expression_db = new scenarioExpression();
             }
             if (!isset($expression_db) || !is_object($expression_db)) {
                 throw new Exception(__('Expression inconnue vérifié l\'id : ', __FILE__) . $expression_ajax['id']);
             }
             $expression_db->emptyOptions();
             utils::a2o($expression_db, $expression_ajax);
             $expression_db->setScenarioSubElement_id($subElement_db->getId());
             if ($expression_db->getType() == 'element') {
                 $expression_db->setExpression(self::saveAjaxElement($expression_ajax['element']));
             }
             $expression_db->setOrder($expression_order);
             $expression_db->save();
             $expression_order++;
             $enable_expression[$expression_db->getId()] = true;
         }
         foreach ($expression_list as $expresssion) {
             if (!isset($enable_expression[$expresssion->getId()])) {
                 $expresssion->remove();
             }
         }
     }
     foreach ($subElement_list as $subElement) {
         if (!isset($enable_subElement[$subElement->getId()])) {
             $subElement->remove();
         }
     }
     return $element_db->getId();
 }
Пример #5
0
 public function getElement()
 {
     return scenarioElement::byId($this->getScenarioElement_id());
 }