Esempio n. 1
0
 /**
  * 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;
 }