public function validatePoll(Request $request, $eid) { $data = json_decode($request->getContent()); $pollArray = $data->polloptions; //json list of poll options if (!empty($pollArray)) { $poll = new Poll(); $poll->eid = $eid; $poll->polltype = 'date'; $saveflag = $poll->save(); if ($saveflag) { foreach ($pollArray as $poll_index) { $poll_options = new PollOption(); $poll_options->pid = $poll['pid']; $poll_options->option = $poll_index->option; try { PollOption::savePollOption($poll_options); } catch (Exception $e) { print '<script type="text/javascript">'; print 'alert( There have been issues adding options to your poll please check home page for details)'; print '</script>'; } } } else { print '<script type="text/javascript">'; print 'alert("Unable to save poll to database")'; print '</script>'; } } }
protected function tearDown() { PollResponse::where('pid', $this->pollOption->oid)->delete(); PollOption::where('oid', $this->pollOption->oid)->delete(); Poll::where('pid', $this->poll->pid)->delete(); Event::where('eid', $this->event->eid)->delete(); User::where('uid', $this->user->uid)->delete(); }
public static function deleteEventPolls($eid) { $polls = DB::table('polls')->where('eid', $eid)->get(); foreach ($polls as $poll) { PollOption::deletePollOptions($poll->pid); } return DB::table('polls')->where('eid', $eid)->delete(); }
protected function tearDown() { if (is_null($this->lastPollOption)) { $option = PollOption::first(); if (!is_null($option)) { $option->delete(); } } else { PollOption::where('oid', '>', $this->lastPollOption)->delete(); } Poll::where('pid', $this->poll->pid)->delete(); Event::where('eid', $this->event->eid)->delete(); User::where('uid', $this->user->uid)->delete(); }
public static function getPollOptionsFromEid($eid) { $event = Event::find($eid); //Retrieving Polls for Display $polls = Poll::getEventPolls($eid); $all_poll_options = []; foreach ($polls as $poll) { $options = []; if (null != $poll) { $options = PollOption::getPollOptions($poll->pid); } array_push($all_poll_options, $options); } return $all_poll_options; }
public static function getPollOptions($pid) { return PollOption::all()->where('pid', $pid); }
public function validatePoll($eid) { $input = Request::all(); $dateList = $input['returndatepolls']; $pollArray = array_map('trim', explode(',', $dateList)); if (!empty($pollArray)) { $poll = new Poll(); $poll->eid = $eid; $poll->polltype = 'date'; $saveflag = $poll->save(); if ($saveflag) { foreach ($pollArray as $poll_index) { $poll_options = new PollOption(); $poll_options->pid = $poll['pid']; $poll_options->option = $poll_index; try { PollOption::savePollOption($poll_options); } catch (Exception $e) { print '<script type="text/javascript">'; print 'alert( There have been issues adding options to your poll please check home page for details)'; print '</script>'; return view('events/invite_event'); } } } else { print '<script type="text/javascript">'; print 'alert("Unable to save poll to database")'; print '</script>'; return view('events/create_poll'); } } return view('events/invite_event')->with('eventID', $eid); }
/** * Cast the user's vote. * @param int $id * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function castVote($id, Request $request) { // Get the poll $poll = Poll::find($id); if (!$poll) { return redirect(route('polls.index')); } // Check if already voted if ($poll->voted($this->user)) { Flash::warning('You have already voted for this poll.'); return redirect(route('polls.view', $id)); } // Cast vote $option = PollOption::find($request->get('vote')); if (!$option) { return redirect(route('polls.view', $id)); } $option->votes()->create(['user_id' => $this->user->id]); Flash::success('Vote cast'); return redirect(route('polls.view', $id)); }