當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Group::isValidRole方法代碼示例

本文整理匯總了PHP中app\models\Group::isValidRole方法的典型用法代碼示例。如果您正苦於以下問題:PHP Group::isValidRole方法的具體用法?PHP Group::isValidRole怎麽用?PHP Group::isValidRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Group的用法示例。


在下文中一共展示了Group::isValidRole方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: changeMemberRole

 public function changeMemberRole($memberId)
 {
     $retval = array('success' => false, 'message' => "Unknown Error");
     try {
         $groupMember = GroupMember::where('id', '=', $memberId)->first();
         if (!$groupMember) {
             $retval['message'] = "Could not locate member";
             return Response::json($retval);
         }
         $group = Group::where('id', '=', $groupMember->group_id)->first();
         if (!$group) {
             $retval['message'] = "Could not locate group";
             return Response::json($retval);
         }
         if (!$group->isGroupOwner(Auth::user()->id)) {
             $retval['message'] = "You aren't the group owner!";
             return Response::json($retval);
         }
         $newRole = Input::all('role')['role'];
         if (!Group::isValidRole($newRole)) {
             $retval['message'] = "Invalid Role: {$newRole}";
             return Response::json($retval);
         }
         if ($newRole != Group::ROLE_OWNER) {
             $owners = GroupMember::where('group_id', '=', $groupMember->group_id)->where('role', '=', Group::ROLE_OWNER)->count();
             if ($owners <= 1) {
                 $retval['message'] = "Group must have an owner!";
                 return Response::json($retval);
             }
         }
         $groupMember->role = $newRole;
         $groupMember->save();
         $retval['success'] = true;
         $retval['message'] = "Member Updated";
         return Response::json($retval);
     } catch (\Exception $e) {
         $retval['message'] = "Exception Caught: {$e->getMessage()}";
         return Response::json($retval);
     }
     return Response::json($retval);
 }
開發者ID:DCgov,項目名稱:dc-madison,代碼行數:41,代碼來源:GroupController.php


注:本文中的app\models\Group::isValidRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。