Exemplo n.º 1
0
 /**
  * delete row(s)         
  * 
  * @param  array $data 
  * @return int
  */
 public function delete($id)
 {
     //delete permission of the resource
     $permissions = new Controlmodule_Model_DbTable_Permissions();
     $permissions->delete("resource_id=" . (int) $id);
     return parent::delete('id = ' . (int) $id);
 }
Exemplo n.º 2
0
 public function install($modulename)
 {
     //add the module in the db
     $datamodule['name'] = $modulename;
     $datamodule['active'] = "1";
     $this->getTable()->insert($datamodule);
     //add the resources of the module in the db
     $dir = APPLICATION_PATH . "/modules/" . $modulename . "/controllers/";
     //TODO use config to define $dir
     echo $modulename;
     $bdmodule = $this->fetchEntry("name =  '{$modulename}'");
     Zend_Debug::dump($bdmodule["id"], '$uploadedData');
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if (is_file($dir . $file) and $file != "." and $file != "..") {
                     //take the name of the controller
                     $resource = explode("Controller.php", $file);
                     $dataresource["module_id"] = $bdmodule["id"];
                     $dataresource["name_r"] = ucwords($bdmodule["name"]) . ucwords($resource["0"]);
                     $dataresource["resource"] = $bdmodule["name"] . ":" . strtolower($resource["0"]);
                     Zend_Debug::dump($dataresource, '$uploadedData');
                     $resourcedb = new Controlmodule_Model_DbTable_Resources();
                     $idresource = $resourcedb->insert($dataresource);
                     //add the permission of the resources
                     $classname = ucwords($bdmodule["name"] . "_" . $resource["0"] . "Controller");
                     include_once $dir . $resource["0"] . 'Controller.php';
                     echo $dir . $resource["0"] . 'Controller.php';
                     $arr = get_class_methods($classname);
                     Zend_Debug::dump($arr, "atapermission");
                     foreach ($arr as $method) {
                         if (strpos($method, 'Action') != false) {
                             //method without the word Action
                             $method = explode("Action", $method);
                             //TODO hardcode para indicar que es el administrador
                             $datapermission["role_id"] = "2";
                             $datapermission["resource_id"] = $idresource;
                             //TODO guardar en el fichero config el role por defecto del permiso
                             $datapermission["role_id"] = "1";
                             $datapermission["permission"] = $method["0"];
                             $datapermission["name"] = $method["0"] . " " . $resource["0"];
                             $datapermission["menu"] = "0";
                             $permission = new Controlmodule_Model_DbTable_Permissions();
                             $permission->insert($datapermission);
                         }
                     }
                 }
             }
         }
         closedir($dh);
         return $modules;
     }
 }