public function init()
 {
     parent::init();
     $role_mapper = new Application_Model_RoleMapper();
     $roles = $role_mapper->fetchAll();
     $resource_mapper = new Application_Model_ResourceMapper();
     $resources = $resource_mapper->fetchAll();
     $privilege_mapper = new Application_Model_PrivilegeMapper();
     $privileges = $privilege_mapper->fetchAll();
     $multi_options = array('' => 'Select option');
     if ($roles) {
         foreach ($roles as $row) {
             $multi_options[$row->getId()] = $row->getRole();
         }
     }
     $this->addElement('select', 'role_id', array('required' => true, 'label' => 'Role:', 'MultiOptions' => $multi_options));
     $multi_options = array('' => 'Select option');
     if ($resources) {
         foreach ($resources as $row) {
             $multi_options[$row->getId()] = $row->getResource();
         }
     }
     $this->addElement('select', 'resource_id', array('label' => 'Resource:', 'MultiOptions' => $multi_options));
     $multi_options = array('' => 'Select option');
     if ($privileges) {
         foreach ($privileges as $row) {
             $multi_options[$row->getId()] = $row->getPrivilege();
         }
     }
     $this->addElement('select', 'privilege_id', array('label' => 'Privilege:', 'MultiOptions' => $multi_options));
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Add Role-Resource-Privilege'));
 }
Example #2
0
 private function __getDataRole()
 {
     $roleMapper = new Application_Model_RoleMapper();
     $listRole = $roleMapper->fetchAll();
     $data[''] = 'Chọn quyền';
     if ($listRole) {
         foreach ($listRole->toArray() as $role) {
             $data[$role['roleId']] = $role['roleName'];
         }
     }
     return $data;
 }
Example #3
0
 public function init()
 {
     parent::init();
     $role_mapper = new Application_Model_RoleMapper();
     $roles = $role_mapper->fetchAll();
     $this->addElement('text', 'role', array('label' => 'Role:', 'required' => true));
     $multi_options = array('' => 'Select option');
     if ($roles) {
         foreach ($roles as $row) {
             $multi_options[$row->getId()] = $row->getRole();
         }
     }
     $this->addElement('select', 'inherited_role_id', array('label' => 'Role to Inherit From:', 'MultiOptions' => $multi_options));
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Add Role'));
 }
Example #4
0
 public function _initAdmin()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         if (!Zend_Registry::isRegistered('is_admin')) {
             // Check if the user is an admin
             Zend_Registry::set('is_admin', false);
             $user = new Zend_Session_Namespace('user');
             $user_info = $user->user;
             $user_role_mapper = new Application_Model_UserRoleMapper();
             $user_roles = $user_role_mapper->findByUser_id($user_info['id']);
             if ($user_roles) {
                 $role_mapper = new Application_Model_RoleMapper();
                 $role = $role_mapper->findByRole('admin');
                 if ($role) {
                     $role = $role[0];
                     $role_id = $role->getId();
                     foreach ($user_roles as $row) {
                         if ($row->getRole_id() == $role_id) {
                             Zend_Registry::set('is_admin', true);
                             break;
                         }
                     }
                 }
             }
         }
     }
 }