public function fetchElement($name, $value, &$node, $control_name) { require_once dirname(__DIR__) . DS . 'models' . DS . 'poll.php'; $options = \Components\Poll\Models\Poll::all()->whereEquals('published', 1)->rows()->raw(); array_unshift($options, \Html::select('option', '0', '- ' . \Lang::txt('Select Poll') . ' -', 'id', 'title')); return \Html::select('genericlist', $options, $control_name . '[' . $name . ']', 'class="inputbox"', 'id', 'title', $value, $control_name . $name); }
/** * Display a list of polls * * @return void */ public function displayTask() { $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.filter_state', 'filter_state', '', 'word'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '', 'string'), 'order' => Request::getState($this->_option . '.' . $this->_controller . '.filter_order', 'filter_order', 'm.id', 'cmd'), 'order_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.filter_order_Dir', 'filter_order_Dir', '', 'word')); $polls = Poll::all()->including(['options', function ($option) { $option->select('id')->select('poll_id')->where('text', '<>', ''); }])->including(['dates', function ($date) { $date->select('id')->select('poll_id'); }]); if ($filters['search']) { if (strpos($filters['search'], '"') !== false) { $filters['search'] = str_replace(array('=', '<'), '', $filters['search']); } $filters['search'] = strtolower($filters['search']); $polls->whereLike('title', strtolower((string) $filters['search'])); } if ($filters['state']) { if ($filters['state'] == 'P') { $polls->whereEquals('state', 1); } else { if ($filters['state'] == 'U') { $polls->whereEquals('state', 0); } } } $rows = $polls->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows(); $filters['states'] = \Html::grid('states', $filters['state']); $this->view->set('filters', $filters)->set('rows', $rows)->display(); }
/** * Display a list of polls * * @return void */ public function displayTask() { $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.filter_state', 'filter_state', '', 'word'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '', 'string'), 'order' => Request::getState($this->_option . '.' . $this->_controller . '.filter_order', 'filter_order', 'm.id', 'cmd'), 'order_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.filter_order_Dir', 'filter_order_Dir', '', 'word')); if (strpos($filters['search'], '"') !== false) { $filters['search'] = str_replace(array('=', '<'), '', $filters['search']); } $filters['search'] = strtolower($filters['search']); $polls = Poll::all()->select('#__polls.*')->select('COUNT(#__poll_data.id) AS numoptions')->join('#__poll_data', '#__poll_data.pollid', '#__polls.id')->where('#__poll_data.text', '<>', ''); if ($filters['search']) { $polls->whereLike('title', strtolower((string) $filters['search'])); } if ($filters['state']) { if ($filters['state'] == 'P') { $polls->whereEquals('published', 1); } else { if ($filters['state'] == 'U') { $polls->whereEquals('published', 0); } } } $rows = $polls->ordered('filter_order', 'filter_order_Dir')->paginated(); $filters['states'] = \Html::grid('states', $filters['state']); $this->view->set('filters', $filters)->set('rows', $rows)->display(); }
/** * Method to show the search view * * @return void */ public function resultsTask() { $poll_id = Request::getInt('id', 0); $poll = Poll::oneOrFail($poll_id); // if id value is passed and poll not published then exit if ($poll->get('id') && $poll->get('state') != 1) { App::abort(403, Lang::txt('JGLOBAL_AUTH_ACCESS_DENIED')); } // Adds parameter handling $params = App::get('menu.params'); // Set page title information $menus = App::get('menu'); $menu = $menus->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new \Hubzero\Config\Registry($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $poll->title); } } else { $params->set('page_title', $poll->title); } Document::setTitle($params->get('page_title')); //Set pathway information Pathway::append(Lang::txt('COM_POLL'), Route::url('index.php?option=' . $this->_option)); Pathway::append($poll->get('title'), Route::url('index.php?option=' . $this->_option . '&id=' . $poll->get('id') . ':' . $poll->get('alias'))); $params->def('show_page_title', 1); $params->def('page_title', $poll->get('title')); $first_vote = ''; $last_vote = ''; $votes = array(); // Check if there is a poll corresponding to id and if poll is published if ($poll->get('id')) { $dates = $poll->dates()->select('MIN(date)', 'mindate')->select('MAX(date)', 'maxdate')->row(); if ($dates->get('mindate')) { $first_vote = \Date::of($dates->get('mindate'))->toLocal(Lang::txt('DATE_FORMAT_LC2')); $last_vote = \Date::of($dates->get('maxdate'))->toLocal(Lang::txt('DATE_FORMAT_LC2')); } $votes = $poll->options()->where('text', '!=', '')->order('hits', 'desc')->rows()->raw(); $votes = array_values($votes); } // list of polls for dropdown selection $ps = Poll::all()->whereEquals('state', 1)->rows()->raw(); $pList = array(); foreach ($ps as $k => $p) { $pList[$k] = $p; $pList[$k]->set('url', Route::url('index.php?option=com_poll&id=' . $p->get('id') . ':' . $p->get('alias'))); } array_unshift($pList, Html::select('option', '', Lang::txt('COM_POLL_SELECT_POLL'), 'url', 'title')); // dropdown output $lists = array('polls' => Html::select('genericlist', $pList, 'id', 'class="inputbox" size="1" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"', 'url', 'title', Route::url('index.php?option=com_poll&id=' . $poll->get('id') . ':' . $poll->get('alias')))); $graphwidth = 200; $barheight = 4; $maxcolors = 5; $barcolor = 0; $tabcnt = 0; $colorx = 0; $maxval = isset($votes[0]) ? $votes[0]->hits : 0; $sumval = $poll->voters; //isset($votes[0]) ? $votes[0]->voters : 0; $k = 0; for ($i = 0; $i < count($votes); $i++) { $vote =& $votes[$i]; if ($maxval > 0 && $sumval > 0) { $vote->width = ceil($vote->hits * $graphwidth / $maxval); $vote->percent = round(100 * $vote->hits / $sumval, 1); } else { $vote->width = 0; $vote->percent = 0; } $vote->class = ''; if ($barcolor == 0) { if ($colorx < $maxcolors) { $colorx = ++$colorx; } else { $colorx = 1; } $vote->class = 'polls_color_' . $colorx; } else { $vote->class = 'polls_color_' . $barcolor; } $vote->barheight = $barheight; $vote->odd = $k; $vote->count = $i; $k = 1 - $k; } $this->view->set('first_vote', $first_vote)->set('last_vote', $last_vote)->set('lists', $lists)->set('params', $params)->set('poll', $poll)->set('votes', $votes)->display(); }