コード例 #1
0
ファイル: UserController.php プロジェクト: Techraav/PolyMusic
 public function updateLevel(Request $request)
 {
     $user = User::with(['level', 'courses' => function ($query) {
         $query->where('level', '1')->where('validated', 1);
     }])->where('id', $request->id)->first();
     $oldLevel = ucfirst($user->level->name);
     if (Auth::check()) {
         if (Auth::user()->id != $user->id) {
             if (Auth::user()->level_id == 5 || Auth::user()->level_id == 4 && $user->level_id < 4) {
                 if ($request->level < 3 && $user->courses->count() > 0) {
                     Flash::error('Impossible de rétrograder cet utilisateur à ce level car il est professeur de ' . $user->courses->count() . ' cours.');
                     return Redirect::back();
                 }
                 $newLevel = ucfirst(Level::find($request->level)->name);
                 $modif = $user->level_id > $request->level ? 'downgraded' : 'upgraded';
                 $user->level_id = $request->level;
                 $user->save();
                 Flash::success('Le changement a été effectué avec succès.');
                 makeModification('users', printUserLinkV2($user) . ' as been ' . $modif . ' from ' . $oldLevel . ' to ' . $newLevel . '.');
                 return Redirect::back();
             }
         }
     }
     Flash::error('Vous n\'avez pas les droits nécéssaires pour cela.');
     return Redirect::back();
 }
コード例 #2
0
 public function downgrade(Request $request, $course_id)
 {
     $course = Course::find($course_id);
     $user = User::find($request->user_id);
     $user_id = $request->user_id;
     $user->courses()->updateExistingPivot($course_id, ['level' => 0]);
     $test = CourseUser::where('user_id', $user_id)->where('level', 1)->where('validated', 1)->count();
     if ($test == 0 && $user->level->level == 2) {
         if (!empty(Band::where('user_id', $user_id)->first())) {
             $user->level_id = 2;
         } else {
             $user->level_id = 1;
         }
         makeModification('users', printUserLinkV2($user) . ' is no longer a teacher.');
         $user->save();
     }
     CourseModification::create(['author_id' => Auth::user()->id, 'user_id' => $user_id, 'course_id' => $id, 'value' => 5]);
     Flash::success("{$user->first_name} {$user->last_name} est maintenant un élève du cours ucfirst({$course->name})");
     return redirect('admin/courses/' . $course->slug . '/members');
 }
コード例 #3
0
 public function accept(Request $request, $id)
 {
     $course = Course::find($id);
     $manager = $course->user_id;
     if (Auth::user()->id != $manager && Auth::user()->level->level < 3) {
         Flash::error("Vous n'avez pas l'autorisation pour ça !");
         return Redirect::back();
     }
     $user_id = $request->user_id;
     $pivot = CourseUser::where('user_id', $user_id)->where('course_id', $id)->where('validated', 0)->where('level', 1)->first();
     $pivot->validated = 1;
     $pivot->save();
     $user = User::find($user_id);
     $user->sendNotification('Votre demande d\'inscription au cours &laquo; ' . ucfirst($course->name) . ' &raquo; en tant que professeur à été <b>acceptée</b> !', 'courses/show/' . $course->slug);
     if ($user->level_id < 3) {
         $user->level_id = 3;
         $user->save();
         makeModification('users', printUserLinkV2($user) . ' is now a teacher.');
         $user->sendNotification('Vous êtes maintenant <b>Professeur</b> !');
     }
     CourseModification::create(['author_id' => Auth::user()->id, 'user_id' => $user_id, 'course_id' => $id, 'value' => 3]);
     return Redirect::back();
 }