本文整理匯總了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);
}