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; }