Ejemplo n.º 1
0
 public function dept()
 {
     if (Auth::user()->position->id == 1) {
         $this->data['items'] = Score::where('userid', Auth::id())->get();
         return view('pages.viewmark.staff', $this->data);
     } else {
         if (Request::isMethod('get')) {
             $this->data['events'] = Event::get();
             $this->data['staffs'] = null;
             return view('pages.viewmark.yes', $this->data);
         } else {
             // dd(Input::all());
             $this->data['events'] = Event::get();
             $user = Score::where('eventid', Input::get('event'))->get();
             foreach ($user as $key => $value) {
                 if ($value->user->deptid != Auth::user()->deptid) {
                     unset($user[$key]);
                 }
             }
             $this->data['staffs'] = $user;
             return view('pages.viewmark.yes', $this->data);
         }
     }
 }
Ejemplo n.º 2
0
 public function yes($id, $userid)
 {
     if (Request::isMethod('get')) {
         //cek event aktif, anaknya bukan, udah pernah ngisi belum, kadept bukan
         if (Auth::user()->positionid != 1) {
             $user = User::find($userid);
             // dd($user->deptid);
             if ($user->deptid != Auth::user()->deptid) {
                 return redirect('/');
             }
             $data = Event::where('enabled', 1)->find($id);
             if (!$data) {
                 return redirect('/');
             }
             if (!$data->enabled) {
                 return redirect('/');
             }
             $cek = Flag::where('eventid', $id)->where('from', '!=', $userid)->where('to', $userid)->first();
             if ($cek != null) {
                 return redirect('/');
             }
             $this->data['event'] = $data;
             $this->data['questions'] = Pivot::where('eventid', $id)->get();
             return view('pages.submit.yes', $this->data);
         } else {
             return redirect('/');
         }
     } else {
         $input = Input::get('score');
         $data = Event::where('enabled', 1)->find($id);
         if (!$data) {
             return redirect('/');
         }
         if (!$data->enabled) {
             return redirect('/');
         }
         // dd($input);
         //set ke mark
         foreach ($input as $key => $value) {
             $mark = new Mark();
             $mark->userid = $userid;
             $mark->questionid = $key;
             $mark->string = $value;
             $mark->save();
         }
         //set ke score
         $score = Score::where('eventid', $id)->where('userid', $userid)->first();
         if ($score) {
             foreach ($input as $key => $value) {
                 $question = Question::find($key);
                 if ($question->type == 1) {
                     $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first();
                     $score->score += $value * $pivot->score / 100;
                     $score->save();
                 }
             }
         } else {
             $score = new Score();
             $score->eventid = $id;
             $score->userid = $userid;
             $score->score = 0;
             foreach ($input as $key => $value) {
                 $question = Question::find($key);
                 // dd($input);
                 if ($question->type == 1) {
                     $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first();
                     $score->score += $value * $pivot->score / 100;
                     $score->save();
                 }
             }
         }
         //set ke flag
         $flag = new Flag();
         $flag->from = Auth::id();
         $flag->to = $userid;
         $flag->eventid = $id;
         $flag->save();
         return redirect('submit/' . $id);
     }
 }
Ejemplo n.º 3
0
 public function leaderboard($event_id)
 {
     $event = Event::where('event_name', $event_id)->first();
     if ($event == null) {
         return "event null";
         return redirect(redirect_home);
     }
     if (OpController::is_live($event_id) == 1) {
         return View::make('waiting_area', ['event' => $event, 'action' => 'waiting']);
     }
     if (OpController::is_live($event_id) == 3) {
         return View::make('winners', ['event' => $event, 'action' => 'event_end']);
     }
     $performers = Score::where('event_id', $event->id)->orderBy('level', 'desc')->orderBy('updated_at')->take(10)->get()->toArray();
     $leaders = [];
     foreach ($performers as $someone) {
         $user = User::where('id', $someone['user_id'])->first();
         array_push($leaders, ['user' => $user, 'score' => $someone]);
     }
     // dd($leaders);
     return View::make('leaderboard', ['leaders' => $leaders, 'event' => $event, 'action' => 'leaderboard', 'rank' => OpController::rank($event_id)]);
 }
 public function unregister($id)
 {
     Score::where('event_id', $id)->where('player_id', Auth::user()->id)->delete();
     return redirect('/');
 }
Ejemplo n.º 5
0
 /**
  * Show player page by id.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     if (is_numeric($id)) {
         $this->tpl['player'] = Player::find($id)->first();
     } else {
         $this->tpl['player'] = Player::where('nick', '=', $id)->first();
     }
     if ($this->tpl['player'] === NULL) {
         $this->tpl['title'] = 'Not found';
         $this->tpl['error']['message'] = 'User not found';
         $this->tpl['error']['description'] = 'Sorry, but your user is not found.';
         return \Response::view('errors.404', $this->tpl);
     }
     $scores = Score::where('player_id', '=', $this->tpl['player']->id)->with('game')->get();
     $games = [];
     if ($scores !== NULL) {
         foreach ($scores as $score) {
             if (!isset($games[$score->game_id])) {
                 $games[$score->game_id] = Game::find($score->game_id);
             }
         }
     }
     $this->tpl['games'] = $games;
     return view('player.show', $this->tpl);
 }
 public function uploadResult(Request $request)
 {
     $data = $request->all();
     $questionResult = $data['question'];
     $result = explode(',', $questionResult);
     for ($i = 0; $i < count($result); $i++) {
         $saveResult = explode('-', $result[$i]);
         Result::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0], 'answer' => $saveResult[1], 'second' => $saveResult[2]]);
         if ($saveResult[3] == '1') {
             $FavoriteRecord = Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->first();
             if ($FavoriteRecord == null || $FavoriteRecord == 'null') {
                 Favorite::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0]]);
             }
         } else {
             if ($saveResult[3] == '0') {
                 Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->delete();
             }
         }
     }
     $UserRecord = UserRecord::where('user_id', $data['user_id'])->get();
     $StageRecord = $UserRecord->where('stages_id', $data['stages_id'])->first();
     $CrementRecord = UserRecord::where('user_id', $data['user_id'])->where('stages_id', $data['stages_id'])->max('stage_score');
     $Crement = $data['score'] - $CrementRecord;
     $User = User::where('id', $data['user_id'])->first();
     if (count($UserRecord) == 0 || $StageRecord == 'null' || $StageRecord == null) {
         $User->increment('score', $data['score']);
     } else {
         if ($Crement > 0) {
             $User->increment('score', $Crement);
         }
     }
     $UserSrcoreRecord = Score::where('user_id', $data['user_id'])->where('category_id', floor($data['stages_id'] / 100));
     if (count($UserSrcoreRecord->get()) == 0) {
         Score::create(['user_id' => $data['user_id'], 'user_name' => $User['name'], 'category_id' => floor($data['stages_id'] / 100), 'score' => $data['score']]);
     } else {
         if ($Crement > 0) {
             $UserSrcoreRecord->first()->increment('score', $Crement);
         }
     }
     UserRecord::create(['user_id' => $data['user_id'], 'stages_id' => $data['stages_id'], 'accuracy' => $data['accuracy'], 'accuracy_detail' => $data['accuracy_detail'], 'status' => $data['status'], 'status_detail' => $data['status_detail'], 'stage_score' => $data['score']]);
     return response()->json(['RetCode' => '1']);
 }
Ejemplo n.º 7
0
 public function getVisible()
 {
     return Score::where('hide', false)->with(['translations'])->get();
 }
Ejemplo n.º 8
0
 public function fetch_ques($event_id, $level)
 {
     // dd($event_id, $level);
     $user = Auth::user();
     $event = Event::where('event_name', $event_id)->first();
     $user_level = Score::where('user_id', $user->id)->where('event_id', $event->id)->first()['level'];
     if ($event->type == 1) {
         $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first();
         if ($user_level == $level - 1) {
             return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)];
         }
     }
     if ($event->type == 2) {
         $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first();
         if ($user_level >= $level - 1) {
             return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)];
         }
     }
     if ($event->type == 3) {
         $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first();
         return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)];
     }
     return ['status' => 0];
 }