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


PHP UserController::findUser方法代碼示例

本文整理匯總了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;
 }
開發者ID:aanyun,項目名稱:PHP-Sample-Code,代碼行數:36,代碼來源:EnrollmentController.php

示例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);
                 }
             }
         }
     }
 }
開發者ID:aanyun,項目名稱:PHP-Sample-Code,代碼行數:72,代碼來源:GroupController.php

示例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;
 }
開發者ID:aanyun,項目名稱:PHP-Sample-Code,代碼行數:18,代碼來源:AuthController.php


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