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>';
         }
     }
 }
Beispiel #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, $orgId)
 {
     $poll = new \App\Poll();
     $poll->organization_id = $orgId;
     $poll->fill($request->input('Poll', []));
     $poll->closed_by = date("Y-m-d H:i:s", strtotime($poll->closed_by));
     if ($poll->isValid()) {
         $poll->save();
         return redirect()->route('poll.index', ['orgId' => $poll->organization_id]);
     } else {
         return redirect()->route('poll.create')->withErrors($poll->getErrors())->withInput();
     }
 }
 private function composePolls()
 {
     view()->composer('layout', function ($view) {
         $polls = Poll::latest()->skip(0)->take(1)->get();
         $view->with('polls', $polls);
     });
 }
 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 function candidateAvg($candidate)
 {
     $sum = \App\Poll::where('state_id', $this->id)->sum($candidate);
     $parts = \App\Poll::where('state_id', $this->id)->count();
     if ($parts == 0) {
         $parts = 1;
     }
     return number_format($sum / $parts, 2);
 }
Beispiel #6
0
 protected static function boot()
 {
     Poll::creating(function ($poll) {
         if (empty($poll->slug)) {
             $poll->slug = $poll->makeSlugFromTitle($poll->title);
         }
         return true;
     });
 }
Beispiel #7
0
 public function pollStatus($poll)
 {
     if ($poll->status > 0) {
         $poll->update(['status' => '0']);
         return 'deactivated';
     } else {
         Poll::where('status', '=', '1')->update(['status' => '0']);
         $poll->update(['status' => '1']);
         return 'activated';
     }
 }
Beispiel #8
0
 public function outgoingVote(Request $request, $id)
 {
     $organization = Organization::findOrFail($id);
     $poll = Poll::orderBy('created_at', 'desc')->first();
     $message = "Here's today's choices for lunch: ";
     $message .= $poll->restaurants->implode('name', ', ');
     $message .= ". Make sure to <" . route('poll.view', [$poll->id]) . "|vote for your response>!";
     $body = json_encode(['text' => $message]);
     $client = new \GuzzleHttp\Client();
     $res = $client->post($organization->incoming_slack_link, ['body' => $body]);
     return redirect()->route('organization.view', [$organization->id]);
 }
Beispiel #9
0
 protected function tearDown()
 {
     if (is_null($this->lastPoll)) {
         $poll = Poll::first();
         if (!is_null($poll)) {
             $poll->delete();
         }
     } else {
         Poll::where('pid', '>', $this->lastPoll)->delete();
     }
     Event::where('eid', $this->event->eid)->delete();
     User::where('uid', $this->user->uid)->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();
 }
Beispiel #11
0
 public function run()
 {
     Artisan::call('migrate:refresh');
     $user = \App\User::create(['email' => '*****@*****.**', 'password' => '$2y$10$zhRDGljo5k5jn6oifVCA7.4GzB6OKmV1QkJfvErtcheR0m5jMLK9S', 'firstName' => 'ftesting1', 'lastName' => 'ltesting1']);
     $restaurant = \App\Restaurant::create(['name' => 'Burger King']);
     $organization = \App\Organization::create(['name' => 'Testing1']);
     $poll = \App\Poll::create(['closed_at' => '2017-05-18 03:00:00', 'closed_by' => '2017-05-18 04:00:00', 'organization_id' => 1]);
     $organization->restaurants()->save($restaurant);
     $poll->restaurants()->save($restaurant);
     $role = \App\Role::create(['user_id' => 1, 'organization_id' => 1, 'role' => 'Tester']);
     $organization_order = \App\OrganizationOrder::create(['organization_restaurant_id' => 1, 'due_by' => '2017-05-18 04:00:00', 'closed_at' => '2017-05-18 03:00:00']);
     $user_order = \App\UserOrder::create(['user_id' => 1, 'restaurant_id' => 1, 'default' => 1, 'order' => 'Test Burger']);
     $polloption = \App\PollRestaurant::find(1);
     $polloption->users()->save($user);
 }
 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 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);
 }
 public function poll($slug)
 {
     $poll = Poll::whereSlug($slug)->firstOrFail();
     return view('admin.poll', compact('poll'));
 }
 public function result($slug)
 {
     $poll = Poll::whereSlug($slug)->firstOrFail();
     return view('poll.result', compact('poll'));
 }
Beispiel #16
0
 private function pollPreview(Poll $poll)
 {
     $parameters = $poll->parameters()->get();
     $total_votes = $parameters->sum('num_vote');
     if ($total_votes == 0) {
         $total_votes = 1;
     }
     return view('partials.pollPreview', compact('poll', 'parameters', 'total_votes'))->render();
 }
 private function composePoll()
 {
     view()->composer('_shared._poll', function ($view) {
         $view->with('poll', \App\Poll::with('options')->orderByRaw('RAND()')->where('active', 1)->first());
     });
 }
 /**
  * Show the application dashboard.
  *
  * @return Response
  */
 public function index()
 {
     $polls = Poll::where('owner_id', '=', Auth::id())->get();
     return view('home')->with('polls', $polls);
 }
Beispiel #19
0
 public function adminChange(User $user, Poll $poll)
 {
     if ($poll->active == 0) {
         //the poll is already disabled
         $poll->update(['active' => 1]);
         Flash::success(trans('admin/messages.pollActivate'));
     } elseif ($poll->active == 1) {
         //the poll is already enabled
         $poll->update(['active' => 0]);
         Flash::success(trans('admin/messages.pollBan'));
     }
     return redirect()->back();
 }
Beispiel #20
0
 public function active($id, Poll $polls)
 {
     $poll = $polls->findOrFail($id);
     return trans('Poll #' . $id . ' is ' . $polls->pollStatus($poll) . ' now');
 }
 /**
  * show vote
  * @param  int $id [description]
  * @return Response
  */
 public function showvote($id)
 {
     $results = array();
     $poll = Poll::find($id);
     $results += array('poll' => $poll);
     $user_id = Auth::user()->id;
     $employee_id = Auth::user()->employee()->first()->id;
     // Check amount poll between start date and end date
     $dateCurrent = Carbon::now();
     $onePlusDate = Carbon::now()->addDay();
     $startDate = Carbon::createFromFormat('Y-m-d H:i:s', $dateCurrent->format('Y-m-d') . ' ' . '00:00:00');
     $endDate = Carbon::createFromFormat('Y-m-d H:i:s', $onePlusDate->format('Y-m-d') . ' ' . '00:00:00');
     $countAnswerInDay = DB::table('poll_answers')->join('poll_user_answers', 'poll_user_answers.answer_id', '=', 'poll_answers.id')->where('poll_answers.poll_id', $id)->whereBetween('poll_user_answers.created_at', [$startDate, $endDate])->count();
     $results += array('countAnswerInDay' => $countAnswerInDay);
     // show result after vote
     $isShowResultAfterVote = $poll->show_results_req_vote;
     $results += array('isShowResultAfterVote' => $isShowResultAfterVote);
     // Check excess time to poll
     $timeDeadline = Carbon::createFromFormat('Y-m-d H:i:s', $poll->end_date);
     $checkExcessDeadline = false;
     $results += array('isShowResultAfterDealine' => $poll->show_results_finish);
     $votechart = array();
     $checkExcessDeadline = $dateCurrent >= $timeDeadline;
     $results += array('checkExcessDeadline' => $checkExcessDeadline);
     // check to dealine and is show result
     if ($checkExcessDeadline || $isShowResultAfterVote) {
         // if excess time, we can caculate answer percentage poll and show graph.
         $votechart = DB::table('poll_user_answers')->select(DB::raw('count(*) as value, answer as label'))->join('poll_answers', 'poll_answers.id', '=', 'poll_user_answers.answer_id')->where('poll_answers.poll_id', $id)->groupBy('poll_user_answers.answer_id')->get();
         $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
         foreach ($votechart as $key => $value) {
             $color = '#' . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)];
             $highlight = '#' . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)];
             $votechart[$key]->color = $color;
             $votechart[$key]->highlight = $highlight;
         }
     }
     $results += array('checkExcessDeadline' => $checkExcessDeadline, 'votechart' => $votechart);
     // caculate count vote and check is show vote number ?
     $countVote = 0;
     $showVoteNumber = $poll->show_vote_number;
     if ($showVoteNumber) {
         $countVoteDb = DB::table('poll_answers')->select(DB::raw('count(*) as value'))->where('poll_id', $id)->first();
         $countVote = $countVoteDb->value;
     }
     // check have user already voted yet ?
     $checkUserVoted = DB::table('poll_answers')->join('poll_user_answers', 'poll_user_answers.answer_id', '=', 'poll_answers.id')->where('poll_answers.poll_id', $id)->where('poll_user_answers.user_id', $employee_id)->count();
     $results += array('countVote' => $countVote, 'showVoteNumber' => $showVoteNumber, 'checkUserVoted' => $checkUserVoted);
     if ($poll) {
         return view("polls.vote", $results);
     }
     abort(404);
 }
 public function update(Request $request, $id)
 {
     // Ensure that they filled out the form properly
     if ($request->has('title')) {
         // Auth check, to make sure they are still valid
         if (Auth::check()) {
             // Look up the poll being edited
             $poll = Poll::find($id);
             // Ensure that this poll exists, and belongs to this user
             if ($poll && $poll->owner_id == Auth::id()) {
                 // Pull the formdata
                 $formdata = $request->all();
                 // Save the formdata to the new poll object
                 $poll->title = $formdata['title'];
                 $poll->description = $formdata['description'];
                 $poll->owner_id = Auth::id();
                 // Save the poll object
                 $poll->save();
                 // Redirect the user back to their homepage with a success message
                 return Redirect::to('/home')->with('success', 'Poll updated successfully');
             }
         }
     }
     // Redirect the user back to their homepage with a failure message
     return Redirect::to('/home')->with('error', 'Please fill out all required fields and try again');
 }
Beispiel #23
0
 public function close($id)
 {
     $poll = \App\Poll::findOrFail($id);
     $poll->closed_at = date('Y-m-d H:i:s');
     $poll->save();
     return redirect()->route('poll.index', ['orgId' => $poll->organization_id]);
 }
Beispiel #24
0
 function pollWidget($min)
 {
     global $registry;
     $output = '';
     //$entry = Cache::remember('poll',$min,function() {
     $entry = \App\Poll::select('id', 'title')->where('status', 1)->first();
     //});
     $registry['poll_id'] = $entry->id;
     //$items = Cache::remember('votes',$min,function() {
     //global $registry;
     $items = \App\Poll::select('id', 'title')->where('parent_id', $entry->id)->getvotes()->get();
     //});
     if (count($items) > 0) {
         $registry['cookie'] = Cookie::get('vote');
         $output .= '<div class="cat-list" id="gamokitxva" style="width:550px;">';
         $output .= '<div class="rub-title-left"><a><div><h3>' . trans('all.poll') . '</h3></div></a></div>';
         $output .= '<div id="poll" data-route="' . action('Admin\\PollsController@vote') . '" data-token="' . csrf_token() . '" data-id="' . $entry->id . '">';
         $output .= '<h4>' . $entry->title . '</h4>';
         $output .= '<div class="poll">';
         $output .= '<div class="poll-list">';
         $registry['sum'] = 0;
         $registry['sum'] = $registry['sum'] < 0 ? 0 : -count($items);
         $registry['voted'] = false;
         foreach ($items as $key => $item) {
             foreach ($item->votes as $k => $vote) {
                 if (!empty($registry['cookie']) && $registry['cookie'] == $vote->cookie) {
                     $registry['voted'] = true;
                 }
                 $registry['sum']++;
             }
         }
         foreach ($items as $item) {
             $class1 = $registry['voted'] == false ? 'vote-show' : 'vote-hide';
             $class2 = $registry['voted'] == true ? 'vote-show' : 'vote-hide';
             $output .= '<div class="poll-unv ' . $class1 . '"><input type="radio" id="p_' . $item->id . '" value="' . $item->id . '" name="vote"><label for="p_' . $item->id . '">' . $item->title . '</label></div>';
             $v = count($item->votes) - 1;
             $fak = $registry['sum'] <= 0 ? 0 : round(number_format($v / $registry['sum'] * 100, 2), 2);
             $output .= '<div class="poll-voted ' . $class2 . '">' . $item->title . ' - ' . $fak . '%</div>';
         }
         $output .= '<div class="poll-voted ' . $class2 . '">' . trans('all.sum') . ' - ' . $registry['sum'] . ' ' . trans('all.voice') . '</div>';
         $output .= '</div>';
         $output .= '<div><div class="vote poll-unv ' . $class1 . '"><span></span><a onClick="vote(\'#poll\')">' . trans('all.vote') . '</a></div></div>';
         $output .= '</div></div><div class="fb-like" data-href="' . url() . '/poll/' . $entry->id . '" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div></div>';
     }
     return $output;
 }
 /**
  * Delete a poll
  * @param int $id
  * @return Response
  */
 public function delete($id)
 {
     $poll = Poll::find($id);
     if ($poll) {
         $poll->delete();
         Flash::success('Poll deleted');
     }
     return redirect(route('polls.index'));
 }