/** * Display a listing of the resource. * * @return Response */ public function index() { $this->data['items'] = Event::where('enabled', 1)->first(); $cek = Flag::where('eventid', $this->data['items']->id)->where('from', Auth::id())->where('to', Auth::id())->first(); if ($cek != null) { $this->data['items'] = null; // dd($cek); } return view('pages.dept.dashboard', $this->data); }
/** * Run the database seeds. * * @return void */ public function run() { $flags = array('Starbucks' => array('alternatives' => array(array('title' => 'Tim Hortons', 'data' => array('savings_percent' => 40, 'message' => 'Tim Horton\'s costs much less than Starbucks.')), array('title' => 'Make Coffee At Home', 'data' => array('savings_percent' => 60, 'message' => 'Save a ton of money by making your own coffee.'))), 'keywords' => array('starbucks')), 'Loblaws' => array('alternatives' => array(array('title' => 'Metro', 'data' => array('savings_percent' => 30, 'message' => 'Big savings by shopping at Metro vs other stores.'))), 'keywords' => array('sobeys', 'loblaw', 'zehrs')), 'Casino' => array('alternatives' => array(array('title' => 'Don\'t Gamble', 'data' => array('savings_percent' => 100, 'message' => 'Instead of losing money by gambling, we can instantly use that to cover debts.'))), 'keywords' => array('casino'))); foreach ($flags as $key => $flag) { $new_flag = Flag::create(['title' => $key]); foreach ($flag['alternatives'] as $alternative) { $new_alternative = Alternative::create(['title' => $alternative['title']]); $new_flag->alternatives()->attach($new_alternative->id, ['savings_percent' => $alternative['data']['savings_percent'], 'message' => $alternative['data']['message']]); } foreach ($flag['keywords'] as $keyword) { $new_flag->keywords()->attach(Keyword::where('name', $keyword)->first()->id); } } }
public function retrieve_new($user_id) { $flags = Flag::all(); for ($i = 0; $i < count($flags); $i++) { $flags[$i]->alternatives = $flags[$i]->alternatives; $flags[$i]->monthly_spend = $this->get_flag_amount($flags[$i]); $flags[$i]->flag_exists = $this->user_flag_exists($user_id, $flags[$i]->id, $flags[$i]->alternatives); $flags[$i]->ignored = $this->is_ignored($flags[$i]); for ($x = 0; $x < count($flags[$i]->alternatives); $x++) { $flags[$i]->alternatives[$x]->savings_dollar = $this->get_flag_amount($flags[$i]) * ($flags[$i]->alternatives[$x]->pivot->savings_percent / 100); $flags[$i]->alternatives[$x]->savings_percent = $flags[$i]->alternatives[$x]->pivot->savings_percent; $flags[$i]->alternatives[$x]->message = $flags[$i]->alternatives[$x]->pivot->message; } } $new_flags = array(); for ($i = 0; $i < count($flags); $i++) { if (!$flags[$i]->flag_exists && $flags[$i]->ignored == 0) { $new_flags[] = $flags[$i]; } } return response()->json(['response' => 'success', 'flags' => $new_flags]); }
public function store(SubmitFlagRequest $request) { $startd = DB::table('Games')->select('start')->first(); $endd = DB::table('Games')->select('stop')->first(); if ($startd->start > Carbon::now()) { return view("pages.countdown"); } elseif ($endd->stop < Carbon::now()) { return view('pages.closed'); } $request = $request->all(); $flags = Flag::where('flag', $request['flag'])->first(); if (!empty($flags)) { $previously = Submitted_flag::select('user_id')->where('text', $request['flag'])->where('user_id', Auth::user()->id)->get(); $previously = $previously->toArray(); var_dump($previously); if (empty($previously)) { $flags = $flags->toArray(); $submission['created_at'] = Carbon::now()->toDateTimeString(); $submission['updated_at'] = Carbon::now()->toDateTimeString(); $submission['user_id'] = Auth::user()->id; $submission['challenge_id'] = $flags['challenge_id']; //to do yo $submission['text'] = $request['flag']; Submitted_flag::create($submission); return redirect('flags/submit')->with('message', 'Correct!'); } $message = 'You have previously submitted this flag!'; return redirect('flags/submit')->with('message', $message); } $filename = "../storage/failed.csv"; $content = Auth::user()->name . "," . $request['flag'] . "\n\r"; $bytesWritten = File::append($filename, $content); if ($bytesWritten === false) { die("Couldn't write to the file."); } return redirect('flags/submit')->with('message', 'Incorrect, sorry try again!'); }
public function store(SubmitFlagRequest $request) { $request = $request->all(); $flags = Flag::where('flag', $request['flag'])->first(); if (!empty($flags)) { $previously = Submitted_flag::select('user_id')->where('text', $request['flag'])->where('user_id', Auth::user()->id)->get(); $previously = $previously->toArray(); var_dump($previously); if (empty($previously)) { $flags = $flags->toArray(); $submission['created_at'] = Carbon::now()->toDateTimeString(); $submission['updated_at'] = Carbon::now()->toDateTimeString(); $submission['user_id'] = Auth::user()->id; $submission['challenge_id'] = $flags['challenge_id']; //to do yo $submission['text'] = $request['flag']; Submitted_flag::create($submission); return redirect('flags/submit')->with('message', 'Correct!'); } $message = 'You have previously submitted this flag!'; return redirect('flags/submit')->with('message', $message); } return redirect('flags/submit')->with('message', 'Incorrect, sorry try again!'); }
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); } }
public function stopElection() { $flag = Flag::find(1); if ($flag->run_election == false) { return view('dashboard.home')->with('message', 'Election has already ended')->with("flag", $flag); } else { $flag->run_election = false; $flag->end_election = true; $flag->save(); return view('dashboard.home')->with('message', 'Election ended')->with("flag", $flag); } }
/** * Run the database seeds. * * @return void */ public function run() { Flag::create(['run_election' => false]); Flag::create(['end_election' => false]); }
public function home() { $flag = Flag::get()->first(); return view('dashboard.home')->with('flag', $flag); }