/**
  * add Action
  * Insert row in 'role_resources'
  * @return type
  * Author: Tahmina Khatoon
  */
 public function addAction()
 {
     $form = new RoleResourcesForm();
     /**
      * Set Roles List
      */
     $options = $this->getRolesTable()->dropdownRoles();
     $form->get('role_id')->setOptions(array('value_options' => $options));
     /**
      * Set Resource List
      */
     $options = $this->getResourcesTable()->dropdownResources();
     $form->get('resource_id')->setOptions(array('value_options' => $options));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $role_resources = new RoleResources();
         $form->setInputFilter($role_resources->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $role_resources->exchangeArray($form->getData());
             $confirm = $this->getRoleResourcesTable()->saveRoleResources($role_resources);
             $redirect = false;
             if (!empty($confirm['status'])) {
                 switch ($confirm['status']) {
                     case '1':
                         $redirect = true;
                         $this->flashMessenger()->addMessage(array('success' => $this->message->success));
                         break;
                     default:
                         $this->flashMessenger()->addMessage(array('error' => $this->message->error));
                         break;
                 }
             }
             if ($redirect) {
                 // Redirect to list of role_resourcess
                 return $this->redirect()->toRoute('role_resources');
             }
         }
     }
     $this->vm->setVariables(array('flashMessages' => $this->flashMessenger()->getMessages(), 'form' => $form));
     return $this->vm;
 }
예제 #2
0
 /**
  * Reset Application 
  */
 public function resetAction()
 {
     //      remove all role_resources
     $this->getUserRolesTable()->truncate();
     $this->getRoleResourcesTable()->truncate();
     $this->getResourcesTable()->truncate();
     $this->getUsersTable()->truncate();
     $this->getRolesTable()->truncate();
     //      Read All link from Module.config
     $routerConfig = $this->getRouterConfig();
     $data_resources = array();
     foreach ($routerConfig['routes'] as $node => $data) {
         $data_resources[] = $node;
         if (!empty($data['child_routes'])) {
             foreach ($data['child_routes'] as $childnode => $childdata) {
                 $data_resources[] = $node . '/' . $childnode;
             }
         }
     }
     //        All Roles
     $data_roles = array(array('name' => 'Administrator', 'label' => 'Admin', 'weight' => 100, 'order' => 1), array('name' => 'Manager', 'label' => 'Manager', 'weight' => 90, 'order' => 2), array('name' => 'User', 'label' => 'User', 'weight' => 20, 'order' => 2), array('name' => 'Guest', 'label' => 'Guest', 'weight' => 0, 'order' => 100));
     //        All Users
     $data_users = array(array('name' => 'Tahmina Khatoon', 'username' => 'admin', 'email' => '*****@*****.**', 'password' => md5('123456'), 'salt' => md5('123456+5'), 'is_disabled' => 0));
     //        All User_roles
     $data_user_roles = array(array('user_id' => 1, 'role_id' => 1));
     //        add resources
     foreach ($data_resources as $row) {
         $data = array('name' => $row);
         $resources = new Resources();
         $resources->exchangeArray($data);
         $confirm = $this->getResourcesTable()->saveResources($resources);
     }
     //        add roles
     foreach ($data_roles as $data) {
         $roles = new \Zf2auth\Entity\Roles();
         $roles->exchangeArray($data);
         $confirm = $this->getRolesTable()->saveRoles($roles);
     }
     //        add users
     foreach ($data_users as $data) {
         $users = new \Zf2auth\Entity\Users();
         $users->exchangeArray($data);
         $confirm = $this->getUsersTable()->saveUsers($users);
     }
     //        add user_roles
     foreach ($data_user_roles as $data) {
         $user_roles = new \Zf2auth\Entity\UserRoles();
         $user_roles->exchangeArray($data);
         $confirm = $this->getUserRolesTable()->saveUserRoles($user_roles);
     }
     //        add primary_role_resources
     $primary_resources = $this->getResourcesTable()->getPrimaryResources();
     if ($primary_resources->count() > 0) {
         foreach ($primary_resources as $row) {
             $data = array('role_id' => 4, 'resource_id' => $row->id);
             $role_resources = new RoleResources();
             $role_resources->exchangeArray($data);
             $confirm = $this->getRoleResourcesTable()->saveRoleResources($role_resources);
         }
     }
 }