Example #1
0
 /**
  * Save User Permission into acl_user_permissions
  */
 public static function saveUserPermission($userId, $data = array())
 {
     UserPermissions::where('user_id', '=', $userId)->delete();
     foreach ($data as $key => $val) {
         if ($val != "" || $val != null) {
             $userpermission = new UserPermissions();
             $userpermission->user_id = $userId;
             $userpermission->permission_id = $key;
             $userpermission->value = $val;
             $userpermission->date_created = new DateTime();
             $userpermission->save();
         }
     }
 }
 public function actionGrandpermission($id)
 {
     $model = $this->loadModeluser($id);
     $permission = Permission::model()->findAll();
     $grand = UserPermissions::model()->findAll("userid = :uid", array(":uid" => $model->id));
     $arr = array();
     foreach ($grand as $allow) {
         array_push($arr, $allow->permission_id);
     }
     if (isset($_POST['permission'])) {
         $collect = $_POST["permission"];
         UserPermissions::model()->deleteAll("userid = :uid", array(":uid" => $model->id));
         foreach ($collect as $item) {
             $up = new UserPermissions();
             $up->userid = $model->id;
             $up->permission_id = $item;
             $up->save();
         }
         $this->redirect("/adminuser");
     }
     $this->render('grandpermission', array('model' => $model, 'permission' => $permission, 'grand' => $arr));
 }