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 question(Request $request, $id) { if ($request->isMethod('get')) { $this->data['items'] = Pivot::where('eventid', $id)->where('deleted_at', null)->get(); $this->data['questions'] = Question::get(); return view('pages.event.question', $this->data); } else { // dd($request->all()); $data = $request->all(); $event = Event::find($id); if ($event) { if (array_key_exists('delete', $data)) { foreach ($data['delete'] as $key => $value) { $item = Pivot::find($value); $item->delete(); } } if (array_key_exists('pivot', $data)) { foreach ($data['pivot'] as $key => $value) { $item = new Pivot(); $item->eventid = $id; $item->questionid = $value; $item->save(); } } } return redirect('event/detail/' . $id); } }
public function destroy($id) { $pivot = Pivot::find($id); $pivot->delete(); return redirect('pivot'); }