Example #1
0
 protected function get_rule_actions($data)
 {
     if (!isset($data->rule_id)) {
         throw new Snep_Rest_Exception_BadRequest("Missing or wrong parameter 'rule_id'.");
     }
     $rule_id = $data->rule_id;
     try {
         $rule = PBX_Rules::get($rule_id);
     } catch (PBX_Exception_NotFound $ex) {
         throw new Snep_Rest_Exception_NotFound("Cant find a rule with id '{$rule_id}'");
     }
     $actions = array();
     foreach ($rule->getActions() as $id => $action) {
         $config = new Snep_Rule_ActionConfig($action->getConfig());
         $config->setActionId("action_{$id}");
         $form = $config->getForm();
         $action_type_element = new Zend_Form_Element_Hidden("action_type");
         $action_type_element->setDecorators(array("ViewHelper"));
         $action_type_element->setValue(get_class($action));
         $form->addElement($action_type_element);
         $form->setView(new Zend_View());
         $form->removeDecorator('form');
         $form->removeElement('submit');
         $form->removeElement('cancel');
         $form_html = $form->render();
         $actions["action_{$id}"] = array("id" => "action_{$id}", "status" => "success", "type" => get_class($action), "label" => $action->getName(), "form" => $form_html);
     }
     return $actions;
 }
Example #2
0
 /**
  * Executa a análise das regras para encontrar a que melhor se enquadra na
  * requisição.
  */
 public function parse()
 {
     $execution_time = date("H:i");
     $this->foundRule = null;
     $rules = PBX_Rules::getAll();
     if (count($rules) > 0) {
         foreach ($rules as $rule) {
             $rule->setRequest($this->request);
             if ($rule->isActive() && $rule->isValidDst($this->request->destino) && $rule->isValidSrc($this->request->origem) && $rule->isValidTime($execution_time)) {
                 $this->foundRule = $rule;
                 break;
                 // paramos na primeira regra totalmente válida
             }
         }
         if (!is_object($this->foundRule)) {
             // Caso nenhuma regra tenha sido encontrada
             throw new PBX_Exception_NotFound("No rule found for this request");
         }
     } else {
         throw new PBX_Exception_NotFound("No rules in database");
     }
 }
Example #3
0
 /**
  * Sobreescreve PBX_Dialplan::parse() fazendo uma análise mais detalhada de
  * cada regra de negócio.
  */
 public function parse()
 {
     if (!isset($this->execution_time)) {
         $this->execution_time = date("H:i");
     }
     $this->foundRule = null;
     $this->matches = array();
     $rules = PBX_Rules::getAll();
     if (count($rules) > 0) {
         foreach ($rules as $rule) {
             $rule->setRequest($this->request);
             if ($rule->isValidDst($this->request->destino) && $rule->isValidSrc($this->request->origem) && $rule->isActive()) {
                 // Armazenando a regra válida (parcialmente)
                 $this->matches[] = $rule;
                 // Caso seja a primeira regra válida (e com tempo válido), ela é a que queremos executar
                 if (is_null($this->foundRule) && $rule->isValidTime($this->execution_time)) {
                     $this->foundRule = $rule;
                 }
             }
         }
         if (!is_object($this->foundRule)) {
             // Caso nenhuma regra tenha sido encontrada
             throw new PBX_Exception_NotFound("No rule found for this request");
         }
     } else {
         throw new PBX_Exception_NotFound("No rules in database");
     }
 }
Example #4
0
 public function toogleAction()
 {
     $route = $this->getRequest()->getParam('route');
     $regras = PBX_Rules::get($route);
     if ($regras->isActive()) {
         $regras->disable();
     } else {
         $regras->enable();
     }
     PBX_Rules::update($regras);
 }