public function postAdd(addClassRequest $request)
 {
     if (\App\ClassModel::create($request->except(['_token']))) {
         return redirect()->route('add.class')->with(['msg' => 'Add class success!']);
     }
     return redirect()->route('add.class')->withErrors('Errors database!');
 }
 /**
  *	Takes $id number and $type string
  *	Handles whether to update a class or a single user
  **/
 public function progressHandler($id, $type)
 {
     //get user
     $user = Auth::user();
     $class = ClassModel::find($user->class_id);
     //class progress
     if ($user->instructor == 1 && (isset($class) && $class->active == 1)) {
         //grab class ID
         $classID = $user->class_id;
         //set result of updating class progress
         $result = $this->classProgressHandler($id, $type, $classID);
         //check result
         switch ($result) {
             //program complete, handle certificates
             case "complete":
                 $this->createClassCertificate($classID);
                 return redirect('/class-complete');
                 break;
                 //program incomplete, back to homepage
             //program incomplete, back to homepage
             case "incomplete":
                 return redirect('/');
                 break;
                 //prior stage(s) not unlocked, trying to guess URLs
             //prior stage(s) not unlocked, trying to guess URLs
             case "cheat":
                 return redirect('/')->with(['flash_message' => 'You have not completed the prerequisites for that portion of the program.', 'alert_class' => 'alert-danger']);
                 break;
         }
     } else {
         //set result of updating progress
         $result = $this->individualProgressHandler($id, $type, $user);
         //check result
         switch ($result) {
             //program complete, handle certificates
             case "complete":
                 $certificate = $this->createCertificate();
                 return redirect('/congrats')->with(['download_certificate' => $certificate]);
                 break;
                 //program incomplete, back to homepage
             //program incomplete, back to homepage
             case "incomplete":
                 return redirect('/');
                 break;
                 //prior stage(s) not unlocked, trying to guess URLs
             //prior stage(s) not unlocked, trying to guess URLs
             case "cheat":
                 return redirect('/')->with(['flash_message' => 'You have not completed the prerequisites for that portion of the program.', 'alert_class' => 'alert-danger']);
                 break;
         }
     }
 }
Exemple #3
0
 /**
  * Remove class_id from associated students and delete class
  * 
  * Note: Calls to destroy() from inside this controller will set $internalCall to true,
  * this allows me to determine whether to redirect with error messaging or not.
  **/
 public function destroy($id, $internalCall = false)
 {
     //delete class
     $class = ClassModel::find($id);
     $class->delete();
     //set all associated users class_id to NULL
     $users = User::where('class_id', $id)->get();
     foreach ($users as $user) {
         $user->class_id = NULL;
         $user->save();
     }
     //check whether destroy() call is internal
     if ($internalCall != true) {
         //redirect with success message
         return redirect('/classes')->with(['flash_message' => 'Your class has been deleted.', 'alert_class' => 'alert-success']);
     }
 }