예제 #1
0
 /**
  * New Role
  */
 public function newAction()
 {
     //Add toolbar button
     $this->_toolbar->addSaveButton();
     $this->_toolbar->addCancelButton('index');
     $this->_addCSSAndJS();
     //Get rules
     $this->getRules();
     if ($this->request->isPost()) {
         //Begin transaction
         $this->db->begin();
         //Save admin role
         $user_role = new UserRoles();
         $user_role->name = $this->request->getPost('name', 'striptags');
         $user_role->is_super_admin = 0;
         $user_role->location = (int) $this->request->getPost('location');
         $user_role->is_default = (int) $this->request->getPost('is_default');
         if ($user_role->save() == false) {
             $this->db->rollback();
             $this->setFlashSession($user_role->getMessages(), 'notice');
             return $this->flashSession->error('m_system_role_message_cannot_save_role');
         }
         //Save admin role mapping
         $userRulesPost = trim($this->request->getPost("admin_rules"), ' ');
         if ($userRulesPost == '') {
             $this->db->commit();
             $this->flashSession->success('m_system_role_message_new_role_was_created_successfully');
             $this->response->redirect('/admin/system/role/');
             return true;
         }
         $user_rules = explode(',', $userRulesPost);
         foreach ($user_rules as $rule) {
             $user_role_mapping = new UserRoleMapping();
             $user_role_mapping->role_id = $user_role->role_id;
             $user_role_mapping->rule_id = $rule;
             if ($user_role_mapping->save() == false) {
                 $this->setFlashSession($user_role_mapping->getMessages(), 'notice');
                 $this->db->rollback();
                 return $this->flashSession->error('m_system_role_message_cannot_save_ruler_in_role');
             }
         }
         //After all success full, commit transaction
         $this->db->commit();
         $this->flashSession->success('m_system_role_message_new_role_was_created_successfully');
         return $this->response->redirect('/admin/system/role/');
     }
     return null;
 }