示例#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;
 }
示例#2
0
 /**
  * Validates $_POST for the required fields of the form.
  *
  * This method is implemented to validate the fields that can't be validated by
  * Zend_Form like the fields of Action Rules.
  *
  * @param array $post
  * @return boolean
  */
 protected function isValidPost($post = null)
 {
     $post = $post === null ? $_POST : $post;
     $assert = true;
     parse_str($post['actions_order'], $actions_order);
     $forms = array();
     foreach ($actions_order['actions_list'] as $action) {
         $real_action = new $post["action_{$action}"]["action_type"]();
         $action_config = new Snep_Rule_ActionConfig($real_action->getConfig());
         $action_config->setActionId("action_{$action}");
         $form = $action_config->getForm();
         $form->removeElement("submit");
         $form->removeElement("cancel");
         $action_type_element = new Zend_Form_Element_Hidden("action_type");
         $action_type_element->setValue(get_class($real_action));
         $action_type_element->setDecorators(array("ViewHelper"));
         $form->addElement($action_type_element);
         if (!$form->isValid($post["action_{$action}"])) {
             $assert = false;
             $status = "error";
         } else {
             $status = "success";
         }
         $form->setView(new Zend_View());
         $forms["action_{$action}"] = array("type" => $post["action_{$action}"]["action_type"], "formData" => $form->render(), "status" => $status);
     }
     if (!$this->form->isValid($_POST)) {
         $assert = false;
         $status = "error";
     }
     if (!$assert) {
         $this->forms = $forms;
         return false;
     } else {
         $this->forms = null;
         return true;
     }
 }