本文整理汇总了PHP中UserController::findUser方法的典型用法代码示例。如果您正苦于以下问题:PHP UserController::findUser方法的具体用法?PHP UserController::findUser怎么用?PHP UserController::findUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserController
的用法示例。
在下文中一共展示了UserController::findUser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enroll
/**
* Create a new Enrollment instance.
*
* @param int $idCourse
* @param int $idUser
* @return int $idEnrollment
*/
public static function enroll($idCourse, $idUser, $end_at = Null)
{
$app = \Slim\Slim::getInstance();
$user = UserController::findUser($idUser);
$course = CourseController::getCourseDetails($idCourse);
if ($end_at && date('Y-m-d H:i:s') > $end_at) {
$app->halt("400", json_encode("Enrollment already expired. Please check the end date."));
}
$data = array('user_id' => $idUser, 'course_id' => $idCourse);
$enrollment = Enrollment::firstOrNew($data);
// if there is scorm cloud id then enroll in scorm cloud
if (isset($course->scorm_id)) {
$scormRegistrationId = ScormCloudAPIController::register($idCourse, $idUser);
if (isset($scormRegistrationId)) {
$enrollment->scorm_registration_id = $scormRegistrationId;
$enrollment->scorm_status = "enrolled";
}
}
if (!$enrollment->id) {
$enrollment->isSafety = $course->safety;
$enrollment->end_at = $end_at;
$enrollment->save();
} else {
$enrollment->end_at = $end_at;
//echo $enrollment->end_at;
$enrollment->save();
}
return $enrollment->id;
}
示例2: detachUser
/**
* @api {delete} /groups/:id/users/:id/delete Leave Group by user self
* @apiName Delete from Group
* @apiGroup Group
* @apiDescription This api allow user leave group by him self.<br>
* <ul>
* <li>Nobody can leave unaffiliated company by himself.</li>
* <li>Owner cannot leave group if there is more than one member in this group.</li>
* <li>Owner cannot leave group if there is any child group of this group.</li>
* <li>Admin/Owner cannot leave group if there is any content in his bin and he is going to lose the manager role if he left.</li>
* </ul>
* <p>If user leaves company group, auto leave this user from the company, and enroll user to Unaffilited Company.<br>
* The group will be removed if the user is the last person in this group.<br>
* The company will be removed if the company group is removed.
* </p>
*
* @apiHeader (Header) {String} X_Authorization Authorization value.
*
* @apiSuccess (200) {json} SuccessDelete
* @apiError 404 Not found. This will happen if the role id/user id/group id is not in our system.
* @apiError 401 UserNotAuthorized
* @apiError 403 Permission denied.
* @apiError 412 There is unassigned content in your bin. The content in your bin must be assigned, or transferred to another manager user within the Company group, before you can leave the group.
*
*/
public static function detachUser($idGroup, $idUser)
{
$app = \Slim\Slim::getInstance();
$user = UserController::findUser($idUser);
$group = self::getGroupInfo($idGroup);
$role = self::getRole($idGroup, $idUser);
if ($idGroup == 0) {
//nobody can leave unaffiliated company by themselves
$app->halt("403", json_encode("permission denied"));
}
$childGroups = Group::where('parent_id', $idGroup)->get();
if ($role->id == 3 && count($childGroups) > 0) {
$app->halt('409', json_encode('Please transfer your ownership out before you leave.'));
}
if ($role->id >= 3) {
$contents = ManagerController::getBin($idUser);
if (count($contents) > 0) {
//check if user will lose manager role if leave
if ($user->groups()->where('role_id', '>=', 3)->where('group_id', '!=', $idGroup)->count() == 0) {
$app->halt("412", json_encode("You have unassigned contents."));
}
}
}
$members = Group::find($idGroup)->members;
if (count($members) == 1 && $members[0]->id == $idUser) {
//last member of the group
if ($group->members->contains($idUser)) {
$group->members()->detach($idUser);
}
self::removeGroup($idGroup);
if ($group->parent_id == 0) {
self::addToUnaffilitedCompany($idUser);
}
} else {
if ($role->id == 3) {
//owner cannot leave group by himself
$app->halt("403", json_encode("permission denied"));
} else {
if ($group->members->contains($idUser)) {
$group->members()->detach($idUser);
if ($group->parent_id == 0) {
self::addToUnaffilitedCompany($idUser);
}
}
}
}
}
示例3: isSuperadmin
public static function isSuperadmin($idUserCheck)
{
$user = UserController::findUser($idUserCheck);
if (!$user) {
return false;
}
$roles = $user->roles->lists('id')->toArray();
if (count($roles) < 1) {
return false;
}
foreach ($roles as $key => $value) {
$rolename = Role::find($value)->name;
if ($rolename == "SuperAdmin") {
return true;
}
}
return false;
}