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