public function doPoll() { if (!($pollId = \Input::get('poll_id', FALSE))) { return FALSE; } $rules = array('poll_id' => 'required', 'answer' => 'required'); $validator = \Validator::make(\Input::all(), $rules); if (!$validator->fails()) { $poll = Poll::findOrFail($pollId); for ($i = 1; $i <= 3; $i++) { if (\Input::get('answer') == $poll->{'answer' . $i}) { $poll->{'answer' . $i . '_count'}++; $poll->save(); break; } } if (\Request::ajax()) { die(1); } } return \Redirect::to(\Input::get('return')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function getDelete($id) { if (Session::get('user_level') < Config::get('cms.deletePolls')) { return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning'); } try { $poll = Poll::findOrFail($id); $poll->delete(); return Redirect::to(_l(URL::action('PollController@getIndex')))->with('message', Lang::get('admin.PollDeleted'))->with('notif', 'success'); } catch (Exception $e) { return Redirect::to(_l(URL::action('PollController@getIndex')))->with('message', Lang::get('admin.noSuchPoll'))->with('notif', 'danger'); } }
public function getPollResults($id) { try { $this->googleAnalytics('/polls/poll-results/' . $id); $poll = Poll::findOrFail($id); $poll_options = PollOption::where('poll_id', '=', $id)->orderBy('vote_count', 'asc')->get(); foreach ($poll_options as $key => $option) { $poll_options[$key]->title = __($option->title); } $total_votes = PollOPtion::where('poll_id', '=', $id)->sum('vote_count'); $response = array("status" => 'success', "poll" => $poll, "poll_options" => $poll_options, "total_votes" => $total_votes, "totalvotes" => "Укупно " . $total_votes . " гласова"); return Response::json($response); } catch (Exception $e) { return Response::json(array("status" => "success", "text" => __("Десила се грешка"))); } }