示例#1
0
 public function updateSession(Request $request, $id)
 {
     $Session = Session::find($id);
     $Session->sessionStartTime = $request->input('sessionStartTime');
     $Session->sessionEndTime = $request->input('sessionEndTime');
     $Session->loginID = $request->input('loginID');
     $Session->sessionQuality = $request->input('sessionQuality');
     $Session->sessionTypeID = $request->input('sessionTypeID');
     $Session->sessionDeleted = 0;
     $Session->save();
     return response()->json($Session);
 }
 public function getGoogleAuth(Request $request)
 {
     $client = new Google_Client();
     $client->setScopes(SCOPES);
     $client->setAuthConfigFile(CLIENT_SECRET_PATH);
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/google_calendar_callback');
     $authCode = $request->input('code');
     $accessToken = $client->authenticate($authCode);
     $client->setAccessToken($accessToken);
     $request->session()->put('access_token', $client->getAccessToken());
     $authObj = json_decode($accessToken);
     if (isset($authObj->refresh_token)) {
         $session = Session::firstOrNew($request->session()->getId());
         $session->refresh_token = $authObj->refresh_token;
         $session->save();
     }
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken(Session::find($request->session()->getId()));
     }
     return redirect()->route('calendar_back', [$request->session()->get('dialog'), $request->session()->get('seance')], 302);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(MonthlyReportRequest $request, $id)
 {
     //Find report
     $report = MonthlyReport::find($id);
     //Getting all the information of the form, expect the user id,
     //due to keep the report related with its creator
     $report->fill($request->except('user_id'));
     $report->save();
     //If the student is absent, it is not necessary create the sessions
     if ($report->student_present == true) {
         //##Updating the old sessions
         $sessionsIds = array();
         foreach ($request->input('old', array()) as $id => $sessionData) {
             $session = Session::find($id) ?: new Session();
             $session->fill($sessionData);
             $session->save();
             $sessionsIds[] = $session->id;
         }
         //##Delete the unused sessions
         //Getting all sessions ids
         $sessionsToRemove = array();
         foreach ($report->sessions()->get() as $session) {
             $sessionsToRemove[] = $session->id;
         }
         //The ids that are different from sessionsIds, must be deleted
         $sessionsToRemove = array_diff($sessionsToRemove, $sessionsIds);
         foreach ($sessionsToRemove as $id) {
             Session::find($id)->delete();
         }
         //##Inserting new sessions
         //Creating the new sessions
         $sessionsIds = array();
         foreach ($request->input('new', array()) as $id => $sessionData) {
             $session = new Session();
             $session->fill($sessionData);
             $session->monthly_report_id = $report->id;
             $session->save();
         }
     } else {
         //If the student is absent, delete all recorded sessions
         foreach ($report->sessions()->get() as $session) {
             $session->delete();
         }
     }
     //Sending the user to the monthly report
     return redirect()->route('monthlyreport/index');
 }
示例#4
0
 /**
  * Show user information
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function show($token)
 {
     $session = Session::find($token);
     if ($session == null) {
         $error = 1;
         $error_msg = "Login are incorrect. Please try again!";
         return response()->json(['error' => $error, 'error_msg' => $error_msg]);
     } else {
         if ($session->is_expired == 1) {
             $error = 1;
             $error_msg = "Login are incorrect. Please try again!";
             return response()->json(['error' => $error, 'error_msg' => $error_msg]);
         } else {
             $user = User::where('id', $session->user_id)->first();
             return response()->json(['username' => $user->username, 'firstname' => $user->first_name, 'lastname' => $user->last_name, 'email' => $user->email]);
         }
     }
 }
 public function findSession($id)
 {
     return Session::find($id);
 }
 public function test(Request $request)
 {
     $question = $request->get('question');
     $this->trainedRecogniseIncident($question, Session::find('82'));
 }