예제 #1
0
파일: Registry.php 프로젝트: rootzig/SNEP
 /**
  * Retorna a instancia dessa classe
  *
  * @param string context
  * @return PBX_Registry instancia única desta classe
  */
 public static function getInstance($context)
 {
     if (!isset(self::$instance)) {
         self::$instance = new self($context);
     }
     self::$instance->setContext($context);
     return self::$instance;
 }
예제 #2
0
파일: Action.php 프로젝트: rootzig/SNEP
 /**
  * Inicializando config no construtor por padrão para evitar erros de
  * runtime mais graves.
  */
 public function __construct()
 {
     $this->config = array();
     try {
         $config = PBX_Registry::getAll(get_class($this));
     } catch (PBX_Registry_Exception_ContextNotFound $ex) {
         $config = array();
     }
     $this->setDefaultConfig($config);
 }
예제 #3
0
 public function editAction()
 {
     $idAction = $this->getRequest()->getParam('id');
     if (!class_exists($idAction)) {
         throw new PBX_Exception_BadArg("Invalid Argument");
     } else {
         $action = new $idAction();
         $registry = PBX_Registry::getInstance($idAction);
         if ($action->getDefaultConfigXML() != "") {
             $actionConfig = new PBX_Rule_ActionConfig($action->getDefaultConfigXML());
             if ($this->getRequest()->isPost()) {
                 $newConfig = $actionConfig->parseConfig($_POST);
                 foreach ($newConfig as $key => $value) {
                     $registry->{$key} = $value;
                     $registry->setContext(get_class($action));
                 }
                 // Cleaning values no longer used
                 $previousValues = $registry->getAllValues();
                 foreach ($previousValues as $key => $value) {
                     if (!key_exists($key, $newConfig)) {
                         unset($registry->{$key});
                     }
                 }
                 $this->view->success = true;
             }
             $action->setDefaultConfig($registry->getAllValues());
             $actionConfig = new PBX_Rule_ActionConfig($action->getDefaultConfigXML());
             $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Default Configs"), $action->getName()));
             $actionForm = $actionConfig->getForm();
             $actionForm->getElement('cancel')->setAttrib("onclick", "location.href='{$this->getFrontController()->getBaseUrl()}/action-configs/'");
             $actionForm->getElement('cancel')->setLabel('Voltar');
             $this->view->form = $actionForm;
         } else {
             throw new PBX_Exception_BadArg("No Configurable Action");
         }
     }
 }
예제 #4
0
파일: Rules.php 프로젝트: rootzig/SNEP
 /**
  * Obtém Regras de negócio do banco de dados.
  *
  * A REGRA É DEVOLVIDA SEM A CLASSE DE COMUNICAÇÂO COM O ASTERISK
  *
  * @param int $id Numero de identificação da regra de negócio que se deseja
  * obter do banco de dados.
  * @return PBX_Rule  $regra de negócio corresponde ao id da chamada
  */
 public static function get($id)
 {
     $db = Snep_Db::getInstance();
     $select = $db->select()->from('regras_negocio')->where("id = '{$id}'");
     $regra_raw = $db->query($select)->fetchObject();
     if (!$regra_raw) {
         throw new PBX_Exception_NotFound("Regra {$id} nao encontrada");
     }
     $regra = new PBX_Rule();
     $regra->setPriority($regra_raw->prio);
     $regra->setDesc($regra_raw->desc);
     $regra->setId($id);
     foreach (explode(',', $regra_raw->origem) as $src) {
         if (!strpos($src, ':')) {
             $regra->addSrc(array("type" => $src, "value" => ""));
         } else {
             $info = explode(':', $src);
             if (!is_array($info) or count($info) != 2) {
                 throw new PBX_Exception_DatabaseIntegrity("Valor errado para origem da regra de negocio {$regra_raw->id}: {$regra_raw->origem}");
             }
             $regra->addSrc(array("type" => $info[0], "value" => $info[1]));
         }
     }
     foreach (explode(',', $regra_raw->destino) as $dst) {
         if (!strpos($dst, ':')) {
             $regra->addDst(array("type" => $dst, "value" => ""));
         } else {
             $info = explode(':', $dst);
             if (!is_array($info) or count($info) != 2) {
                 throw new PBX_Exception_DatabaseIntegrity("Valor errado para destino da regra de negocio {$regra_raw->id}: {$regra_raw->destino}");
             }
             $regra->addDst(array("type" => $info[0], "value" => $info[1]));
         }
     }
     $regra->cleanValidWeekList();
     foreach (explode(',', $regra_raw->diasDaSemana) as $diaDaSemana) {
         if ($diaDaSemana != "") {
             $regra->addWeekDay($diaDaSemana);
         }
     }
     foreach (explode(',', $regra_raw->validade) as $time) {
         $regra->addValidTime($time);
     }
     if (!$regra_raw->ativa) {
         $regra->disable();
     }
     if ($regra_raw->record == "1") {
         $regra->record();
     }
     $select = $db->select()->from('regras_negocio_actions')->where("regra_id = {$id}")->order('prio');
     $actions = $db->query($select)->fetchAll();
     // Processing rule actions
     if (count($actions) > 0) {
         $select = $db->select()->from('regras_negocio_actions_config')->where("regra_id = {$id}")->order('prio');
         $configs_raw = $db->query($select)->fetchAll();
         // Rearranging configuration array
         $configs = array();
         if (count($configs_raw) > 0) {
             foreach ($configs_raw as $config) {
                 $configs[$config['prio']][$config['key']] = $config['value'];
             }
         }
         foreach ($actions as $acao_raw) {
             $acao = $acao_raw['action'];
             if (class_exists($acao)) {
                 $config = isset($configs[$acao_raw['prio']]) ? $configs[$acao_raw['prio']] : array();
                 $acao_object = new $acao();
                 $acao_object->setConfig($config);
                 $acao_object->setDefaultConfig(PBX_Registry::getAll($acao));
                 $regra->addAcao($acao_object);
             }
         }
     }
     return $regra;
 }