Exemplo n.º 1
0
 public function init()
 {
     $roles = new Model_Roles();
     $result = $roles->getRoles();
     if ($result) {
         foreach ($result as $row) {
             $this->_list["role"][$row->getPkId()] = $row->getRoleName();
         }
     }
     $resources = new Model_Resources();
     $result2 = $resources->getAllResources();
     if ($result2) {
         foreach ($result2 as $row2) {
             $resource = $row2->getResourceName();
             $arr_resources = explode("/", $resource);
             $second_name = !empty($arr_resources[1]) ? ucfirst($arr_resources[1]) . " - " : "";
             $this->_list["resource"][$row2->getPkId()] = ucfirst($arr_resources[0]) . " - " . $second_name . $row2->getDescription();
         }
     }
     foreach ($this->_fields as $col => $name) {
         if (in_array($col, array_keys($this->_list))) {
             $this->addElement("select", $col, array("attribs" => array("class" => "form-control"), "filters" => array("StringTrim", "StripTags"), "allowEmpty" => true, "required" => false, "registerInArrayValidator" => false, "multiOptions" => $this->_list[$col], "validators" => array()));
             $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag");
         }
     }
 }
 public function roleResourcesAction()
 {
     $form = new Form_Iadmin_RoleComboSearch();
     $form_add = new Form_Iadmin_RoleResource();
     $params = array();
     $rr = new Model_Resources();
     $roles = new Model_Roles();
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $role_name = $form->getValue('role');
             $description = $form->getValue('description');
             $resource_name = $form->getValue('resource_name');
             $resource_type = $form->getValue('resource_type');
             if (!empty($role_name)) {
                 $params['role'] = $role_name;
             }
             if (!empty($description)) {
                 $params['description'] = $description;
             }
             if (!empty($resource_name)) {
                 $params['resourceName'] = $resource_name;
             }
             if (!empty($resource_type)) {
                 $params['resourceType'] = $resource_type;
             }
         }
     } else {
         $role_name = $this->_getParam('role', '');
         $description = $this->_getParam('description');
         $resource_name = $this->_getParam('resource_name');
         $resource_type = $this->_getParam('resource_type');
         if (!empty($role_name)) {
             $params['role'] = $role_name;
             $form->role->setValue($role_name);
         }
         if (!empty($description)) {
             $params['description'] = $description;
             $form->description->setValue($description);
         }
         if (!empty($resource_name)) {
             $params['resourceName'] = $resource_name;
             $form->resource_name->setValue($resource_name);
         }
         if (!empty($resource_type)) {
             $params['resourceType'] = $resource_type;
             $form->resource_type->setValue($resource_type);
         }
     }
     //App_Controller_Functions::pr($params);
     $rr->form_values = $params;
     //  var_dump($params);
     $result = $rr->getAllResources();
     $roles->form_values['role'] = $params['role'];
     $role_result = $roles->getAllRolesResources();
     $this->view->roles = $role_result;
     $this->view->form = $form;
     $this->view->form_add = $form_add;
     $this->view->paginator = $result;
     $this->view->pagination_params = $params;
 }