Beispiel #1
0
 /**
  * Logout function
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function logout(Request $request)
 {
     $error = 0;
     $error_msg = "Logout completed";
     $session = Session::where('token', $request->get('token'))->first();
     $session->is_expired = 1;
     $session->save();
     return response()->json(['error' => $error, 'error_msg' => $error_msg]);
 }
Beispiel #2
0
 public function read($sessionId)
 {
     $session = Session::where('sid', '=', $sessionId)->first();
     if (is_null($session)) {
         return null;
     }
     $objects = \App\Object::where('session_id', '=', $sessionId)->get()->toArray();
     return new GamingSession($session->sid, $session->name, $objects, $session->scope, $session->password, $session->style);
 }
 /** Удаление файлов всей сессии **/
 public static function deleteSession($sessionId)
 {
     Session::where('id', $sessionId)->delete();
 }
Beispiel #4
0
 public function getSessionsByLoginID(Request $request, $id)
 {
     $Sessions = Session::where('loginID', $id)->where('sessionDeleted', 0)->whereBetween('sessionStartTime', [$request->input('sessionStartTime'), $request->input('sessionEndTime')])->get();
     return response()->json($Sessions);
 }
Beispiel #5
0
 /**
  * Store a newly created post in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // check who is token owner.
     $session = Session::where('token', $request->get('token'))->first();
     //find user_id from token
     if ($session == null) {
         $error = 1;
         $error_msg = "Token error!";
         return response()->json(['error' => $error, 'error_msg' => $error_msg]);
     } else {
         // check user token isn't expired.
         if ($session->is_expired == 0) {
             $post_is_anonymous = "";
             $error = 0;
             // post with out image
             if ($request->file('image') == null || $request->file('image')->getClientSize() <= 0) {
                 // store the text post.
                 $post = new Post();
                 $post->user_id = $session->user_id;
                 $post->text = $request->get('text');
                 $post->latitude = $request->get('latitude');
                 $post->longitude = $request->get('longitude');
                 $post->is_anonymous = $request->get('is_anonymous');
                 $post_is_anonymous = $post->is_anonymous;
                 $post->save();
                 $error_msg = "Shout completed. :)";
             } else {
                 // upload image to imgur.com
                 $result = $this->upload_image($request->file('image'));
                 //echo $result;
                 $result = json_decode($result);
                 // check upload image to imgur.com isn't failed.
                 if ($result->success != false) {
                     // store image information.
                     $image = new Image();
                     $image->imgur_url = $result->data->link;
                     $image->post_id = null;
                     $error_msg = "Upload completed";
                     $image->save();
                     // store the text post.
                     $post = new Post();
                     $post->user_id = $session->user_id;
                     $post->text = $request->get('text');
                     $post->latitude = $request->get('latitude');
                     $post->longitude = $request->get('longitude');
                     $post->is_anonymous = $request->get('is_anonymous');
                     $post_is_anonymous = $post->is_anonymous;
                     $post->save();
                     // update post id of image.
                     $image->post_id = $post->id;
                     $image->save();
                     $error_msg = "Shout completed. :)";
                 } else {
                     $error = 1;
                     // show error msg from imgur.com API
                     $error_msg = $result->data->error;
                 }
             }
             return response()->json(['error' => $error, 'error_msg' => $error_msg, 'is_anonymous' => $post_is_anonymous]);
         } else {
             $error = 1;
             $error_msg = "Your session has expired. Please Login again!";
             return response()->json(['error' => $error, 'error_msg' => $error_msg]);
         }
     }
 }
 public function AverageHoursFitness(Request $request, $id)
 {
     $SleepSessionType = SessionType::where('stName', 'Fitness')->first();
     $date1 = new \DateTime('last sunday');
     $date2 = new \DateTime('last sunday +7 days');
     $Sessions = Session::where('loginID', $id)->where('sessionDeleted', 0)->whereRaw("sessions.sessionStartTime between '" + $date1->format('Y-m-d H:i:s') + '" and "' + $date2->format('Y-m-d H:i:s') + "'")->get();
     $length = 0;
     for ($i = 0; $i < 7; $i++) {
         foreach ($Sessions as $Session) {
             $today = new \DateTime('last sunday');
             $today->setTime(0, 0);
             $today->add(new \DateInterval('P' . $i . 'D'));
             $lateToday = new \DateTime('last sunday');
             $lateToday->add(new \DateInterval('P' . $i . 'D'));
             $lateToday->setTime(23, 59);
             $sessionStartTime = new \DateTime($Session->sessionStartTime);
             $sessionEndTime = new \DateTime($Session->sessionEndTime);
             if ($Session->sessionTypeID == $SleepSessionType->id) {
                 if ($sessionStartTime > $today) {
                     if ($sessionStartTime <= $lateToday) {
                         $length += $sessionEndTime->diff($sessionStartTime)->h;
                     }
                 }
             }
         }
     }
     return response()->json(number_format($length / 7, 2));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $exercise = Auth::user()->exercises()->findOrFail($id);
     $sessions = Session::where('exercise_id', '=', $exercise->id)->orderBy('session_date', 'desc')->with('sessionSets')->paginate(2);
     return view('exercises.showOne', compact('exercise', 'sessions'));
 }
 public function bookClass(Request $request, User $user)
 {
     //		var_dump($demoQuery->isEmpty());
     //		var_dump(Auth::user()->id);
     //		var_dump($user->id);
     $topic = $request->input('topic');
     $dates = $request->input('date');
     $waqt = [];
     //		var_dump($request->all());
     foreach ($request->input('time') as $key => $time) {
         $pieces[$key] = explode(":", $time);
         $waqt[$key] = '';
         foreach ($pieces[$key] as $value) {
             $waqt[$key][] = sprintf("%02d", $value);
         }
     }
     $time = [];
     foreach ($waqt as $key => $value) {
         $time[] = implode(":", $value);
     }
     //		var_dump($time);
     $slots = [];
     foreach ($dates as $date) {
         foreach ($time as $samay) {
             $slots[] = Carbon::createFromFormat('Y-n-j H:i', $date . ' ' . $samay);
         }
     }
     //		var_dump($slots);
     $groups = [];
     $i = 0;
     foreach ($slots as $key => $slot) {
         if ($key === 0) {
             $groups[$i][] = $slot;
         } else {
             $diff = $slot->diffInMinutes(end($groups[$i - 1]));
             if (\App\Session::where('teacher_id', $user->deriveable->id)->where('student_id', Auth::user()->id)->where('demo', 1)->get()->isEmpty() && $key === 2) {
                 //	Means demo not done yet
                 $groups[$i][] = $slot;
                 $i++;
                 continue;
             }
             if ($diff === 30) {
                 $i--;
             }
             $groups[$i][] = $slot;
         }
         $i++;
     }
     if (count($groups[0]) !== 2 && count($groups) > 1) {
         $groups[0][] = $groups[1][0];
         unset($groups[1]);
         $groups = array_values($groups);
     }
     //		var_dump($groups);
     $status = [];
     foreach ($groups as $key => $group) {
         $demo = $key === 0 ? true : false;
         $status[] = $this->saveClass($topic, $user->id, $group, $demo);
     }
     //dd($request->all());
     flash('Your class sessions have been booked.');
     return redirect('/profile/' . $request->user->id . '/book');
 }