Exemplo n.º 1
0
 /**
  * Retorna instancia dessa classe
  *
  * @return PBX_Rule_Actions
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 protected function new_action($data)
 {
     if (!isset($data->id)) {
         throw new Snep_Rest_Exception_BadRequest("Missing or wrong parameter 'id'. You must specify an id for the new action form.");
     }
     $id = $data->id;
     if (!isset($data->type)) {
         throw new Snep_Rest_Exception_BadRequest("Missing parameter 'type'. You must specify the classname for the action.");
     }
     $classname = $data->type;
     $actions = PBX_Rule_Actions::getInstance();
     if ($actions->isRegistered($classname)) {
         $action = new $classname();
     } else {
         throw new Snep_Rest_Exception_BadRequest("{$classname} is not a registered action");
     }
     $config = new Snep_Rule_ActionConfig($action->getConfig());
     $config->setActionId($id);
     $form = $config->getForm();
     $action_type_element = new Zend_Form_Element_Hidden("action_type");
     $action_type_element->setValue(get_class($action));
     $action_type_element->setDecorators(array("ViewHelper"));
     $form->addElement($action_type_element);
     $form->setView(new Zend_View());
     $form->removeDecorator('form');
     $form->removeElement('submit');
     $form->removeElement('cancel');
     $form_html = $form->render();
     return array("id" => $id, "status" => "success", "type" => get_class($action), "label" => $action->getName(), "form" => $form_html);
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Default Configs")));
     $actionsDisp = PBX_Rule_Actions::getInstance();
     $infoActions = array();
     foreach ($actionsDisp->getInstalledActions() as $actionTmp) {
         $action = new $actionTmp();
         if ($action->getDefaultConfigXML() != "") {
             $infoActions[] = array("id" => $actionTmp, "name" => $action->getName(), "description" => $action->getDesc());
         }
     }
     $this->view->infoAcoes = $infoActions;
 }
Exemplo n.º 4
0
 /**
  * Generate the form for routes
  *
  * @return Zend_Form
  */
 protected function getForm()
 {
     if ($this->form === Null) {
         $form_xml = new Zend_Config_Xml(Zend_Registry::get("config")->system->path->base . "/modules/default/forms/route.xml");
         $form = new Snep_Form($form_xml);
         $actions = PBX_Rule_Actions::getInstance();
         $installed_actions = array();
         foreach ($actions->getInstalledActions() as $action) {
             $action_instance = new $action();
             $installed_actions[$action] = $action_instance->getName();
         }
         asort($installed_actions);
         $this->view->actions = $installed_actions;
         $src = new Snep_Form_Element_Html("route/elements/src.phtml", "src", false);
         $src->setLabel($this->view->translate("Source"));
         $src->setOrder(1);
         $form->addElement($src);
         $dst = new Snep_Form_Element_Html("route/elements/dst.phtml", "dst", false);
         $dst->setLabel($this->view->translate("Destiny"));
         $dst->setOrder(2);
         $form->addElement($dst);
         $time = new Snep_Form_Element_Html("route/elements/time.phtml", "time", false);
         $time->setOrder(4);
         $time->setLabel($this->view->translate("Valid times"));
         $form->addElement($time);
         $form->addElement(new Snep_Form_Element_Html("route/elements/actions.phtml", "actions"));
         $this->form = $form;
         $groups = new Snep_GruposRamais();
         $groups = $groups->getAll();
         $group_list = "";
         foreach ($groups as $group) {
             $group_list .= "[\"{$group['name']}\", \"{$group['name']}\"],";
         }
         $group_list = "[" . trim($group_list, ",") . "]";
         $this->view->group_list = $group_list;
         $alias_list = "";
         foreach (PBX_ExpressionAliases::getInstance()->getAll() as $alias) {
             $alias_list .= "[\"{$alias['id']}\", \"{$alias['name']}\"],";
         }
         $alias_list = "[" . trim($alias_list, ",") . "]";
         $this->view->alias_list = $alias_list;
         $trunks = "";
         foreach (PBX_Trunks::getAll() as $trunk) {
             $trunks .= "[\"{$trunk->getId()}\", \"{$trunk->getName()}\"],";
         }
         $trunks = "[" . trim($trunks, ",") . "]";
         $this->view->trunk_list = $trunks;
         $cgroup_list = "";
         $cgroup_manager = new Snep_ContactGroups_Manager();
         foreach ($cgroup_manager->getAll() as $cgroup) {
             $cgroup_list .= "[\"{$cgroup['id']}\", \"{$cgroup['name']}\"],";
         }
         $cgroup_list = "[" . trim($cgroup_list, ",") . "]";
         $this->view->contact_groups_list = $cgroup_list;
     }
     return $this->form;
 }
Exemplo n.º 5
0
 /**
  * Take care of module registering details.
  *
  * @param Snep_Module_Descriptor $module
  */
 protected function registerModule($path)
 {
     $info = simplexml_load_file($path . "/info.xml");
     $pathinfo = pathinfo($path);
     $descriptor = $this->parseInfo($pathinfo['filename'], $info);
     $this->registeredModules[] = $descriptor;
     // Adding module lib to include path
     if (is_dir($path . "/lib")) {
         set_include_path(implode(PATH_SEPARATOR, array("{$path}/lib", get_include_path())));
         foreach (scandir("{$path}/lib") as $namespace) {
             if (is_dir("{$path}/lib/{$namespace}")) {
                 Zend_Loader_Autoloader::getInstance()->registerNamespace($namespace . "_");
             }
         }
     }
     // Parsing and registering module resources
     if (file_exists("{$path}/resources.xml")) {
         Snep_Acl::getInstance()->addResource($descriptor->getModuleId());
         $this->loadResources(simplexml_load_file("{$path}/resources.xml"), $descriptor->getModuleId());
     }
     // Finding and registering module Rule Actions.
     require_once "PBX/Rule/Actions.php";
     $actions = PBX_Rule_Actions::getInstance();
     if (is_dir($path . "/actions")) {
         foreach (scandir($path . "/actions") as $file) {
             if (substr($file, -4) == ".php") {
                 require_once $path . "/actions/" . $file;
                 $classname = basename($file, '.php');
                 if (class_exists($classname)) {
                     $actions->registerAction($classname);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 protected function startActions()
 {
     $config = Zend_Registry::get('config');
     $actions_dir = $config->system->path->base . "/lib/PBX/Rule/Action";
     $actions = PBX_Rule_Actions::getInstance();
     foreach (scandir($actions_dir) as $filename) {
         // Todos os arquivos .php devem ser classes de Actions
         if (preg_match("/.*\\.php\$/", $filename)) {
             // Tentar instanciar e Adicionar no array
             $classname = 'PBX_Rule_Action_' . basename($filename, '.php');
             if (class_exists($classname)) {
                 $actions->registerAction($classname);
             }
         }
     }
     foreach (Snep_Modules::getInstance()->getRegisteredModules() as $module) {
         if ($module->getModuleId() != null) {
             $actions_dir = $config->system->path->base . "/modules/" . $module->getModuleDir() . "/actions";
         } else {
             $actions_dir = $config->system->path->base . "/" . $module->getModuleDir() . "/actions";
         }
         if (file_exists($actions_dir)) {
             foreach (scandir($actions_dir) as $filename) {
                 // Todos os arquivos .php devem ser classes de Actions
                 if (preg_match("/.*\\.php\$/", $filename)) {
                     // Tentar instanciar e Adicionar no array
                     require_once $actions_dir . "/" . $filename;
                     $classname = basename($filename, '.php');
                     if (class_exists($classname)) {
                         $actions->registerAction($classname);
                     }
                 }
             }
         }
     }
 }