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; }
/** * Parse a route based on it's POST. * It's assumed here that all fields are already validated * * @param array $postData optional for ovewrite post data * @return PBX_Rule */ protected function parseRuleFromPost($post = null) { $post = $post === null ? $_POST : $post; $rule = new PBX_Rule(); // Adicionando dias da semana $weekDays = array("sun", "mon", "tue", "wed", "thu", "fri", "sat"); $rule->cleanValidWeekList(); foreach ($weekDays as $day) { if (in_array($day, $post['week'])) { $rule->addWeekDay($day); } } // Adicionando Origens foreach (explode(',', $post['srcValue']) as $src) { if (!strpos($src, ':')) { $rule->addSrc(array("type" => $src, "value" => "")); } else { $info = explode(':', $src); if (!is_array($info) or count($info) != 2) { throw new PBX_Exception_BadArg("Valor errado para origem da regra de negocio."); } if ($info[0] == "T") { try { PBX_Trunks::get($info[1]); } catch (PBX_Exception_NotFound $ex) { throw new PBX_Exception_BadArg("Tronco inválido para origem da regra"); } } $rule->addSrc(array("type" => $info[0], "value" => $info[1])); } } // Adding destinys foreach (explode(',', $post['dstValue']) as $dst) { if (!strpos($dst, ':')) { $rule->addDst(array("type" => $dst, "value" => "")); } else { $info = explode(':', $dst); if (!is_array($info) or count($info) != 2) { throw new PBX_Exception_BadArg("Valor errado para destino da regra de negocio."); } if ($info[0] == "T") { try { PBX_Trunks::get($info[1]); } catch (PBX_Exception_NotFound $ex) { throw new PBX_Exception_BadArg("Tronco inválido para destino da regra"); } } $rule->addDst(array("type" => $info[0], "value" => $info[1])); } } // Adding time $rule->cleanValidTimeList(); foreach (explode(',', $post['timeValue']) as $time_period) { $rule->addValidTime($time_period); } // Adding Description $rule->setDesc($post['desc']); // Defining recording order if (isset($post['record']) && $post['record']) { $rule->record(); } // Defining priority $rule->setPriority(substr($post['prio'], 1)); if (isset($post['actions_order'])) { parse_str($post['actions_order'], $actions_order); foreach ($actions_order['actions_list'] as $action) { $real_action = new $post["action_{$action}"]["action_type"](); $action_config = new Snep_Rule_ActionConfig($real_action->getConfig()); $real_action->setConfig($action_config->parseConfig($post["action_{$action}"])); $rule->addAction($real_action); } } return $rule; }