/** * Populate the fields based on a specific route * * @param PBX_Rule $rule */ protected function populateFromRule(PBX_Rule $rule) { $srcList = $rule->getSrcList(); $src = "origObj.addItem(" . count($srcList) . ");"; foreach ($srcList as $index => $_src) { $src .= "origObj.widgets[{$index}].type='{$_src['type']}';\n"; $src .= "origObj.widgets[{$index}].value='{$_src['value']}';\n"; } $dstList = $rule->getDstList(); $dst = "dstObj.addItem(" . count($dstList) . ");"; foreach ($dstList as $index => $_dst) { $dst .= "dstObj.widgets[{$index}].type='{$_dst['type']}';\n"; $dst .= "dstObj.widgets[{$index}].value='{$_dst['value']}';\n"; } $timeList = $rule->getValidTimeList(); $time = "timeObj.addItem(" . count($timeList) . ");"; foreach ($timeList as $index => $_time) { $_time = explode('-', $_time); $time .= "timeObj.widgets[{$index}].startTime='{$_time[0]}';\n"; $time .= "timeObj.widgets[{$index}].endTime='{$_time[1]}';\n"; } // Treatment of the active time of the route $horario = $rule->getValidTimeList(); $data = explode("-", $horario['0']); $this->view->dt_agirules = array("dst" => $dst, "src" => $src, "time" => $time); $form = $this->getForm(); $form->getElement('desc')->setValue($rule->getDesc()); $form->getElement('record')->setValue($rule->isRecording()); $form->getElement('prio')->setValue("p" . $rule->getPriority()); $form->getElement('week')->setValue($rule->getValidWeekDays()); }
/** * Cadastra uma regra de negócio no banco de dados do Snep. * * @param PBX_Rule $rule */ public static function register($rule) { $srcs = ""; foreach ($rule->getSrcList() as $src) { $srcs .= "," . trim($src['type'] . ":" . $src['value'], ':'); } $srcs = trim($srcs, ','); $dsts = ""; foreach ($rule->getDstList() as $dst) { $dsts .= "," . trim($dst['type'] . ":" . $dst['value'], ':'); } $dsts = trim($dsts, ','); $validade = implode(",", $rule->getValidTimeList()); $diasDaSemana = implode(",", $rule->getValidWeekDays()); $insert_data = array("prio" => $rule->getPriority(), "desc" => $rule->getDesc(), "origem" => $srcs, "destino" => $dsts, "validade" => $validade, "diasDaSemana" => $diasDaSemana, "record" => $rule->isRecording()); $db = Snep_Db::getInstance(); $db->beginTransaction(); try { $db->insert("regras_negocio", $insert_data); $rule->setId((int) $db->lastInsertId('regras_negocio_id')); $action_prio = 0; foreach ($rule->getAcoes() as $acao) { $action_insert_data = array("regra_id" => $rule->getId(), "prio" => $action_prio, "action" => get_class($acao)); $db->insert("regras_negocio_actions", $action_insert_data); foreach ($acao->getConfigArray() as $chave => $valor) { $action_config_data = array("regra_id" => $rule->getId(), "prio" => $action_prio, "key" => $chave, "value" => $valor); $db->insert("regras_negocio_actions_config", $action_config_data); } $action_prio++; } $db->commit(); } catch (Exception $ex) { $db->rollBack(); throw $ex; } }