public function get_menu_content() { global $LANG; $poll_config = PollConfig::load(); $config_cookie_name = $poll_config->get_cookie_name(); $polls = PollMiniMenuCache::load()->get_polls(); //Chargement de la langue du module. load_module_lang('poll'); $rand = array_rand($polls); $poll_mini = $polls[$rand]; //Sondage aléatoire. $tpl = new FileTemplate('poll/poll_mini.tpl'); #####################Résultats###################### //Si le cookie existe, on redirige vers les resulats, sinon on prend en compte le vote (vérification par ip plus tard). $array_cookie = array(); if (AppContext::get_request()->has_cookieparameter($config_cookie_name)) { $array_cookie = explode('/', AppContext::get_request()->get_cookie($config_cookie_name)); } if (in_array($poll_mini['id'], $array_cookie)) { $tpl->put_all(array('L_VOTE' => $poll_mini['total'] > 1 ? $LANG['poll_vote_s'] : $LANG['poll_vote'])); $tpl->assign_block_vars('result', array('QUESTION' => $poll_mini['question'], 'VOTES' => $poll_mini['total'])); foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('result.answers', array('ANSWERS' => $answer, 'WIDTH' => NumberHelper::round($width, 0), 'PERCENT' => $width)); } } else { #####################Questions###################### $tpl->put_all(array('L_MINI_POLL' => $LANG['mini_poll'], 'L_VOTE' => $LANG['poll_vote'], 'L_POLL_RESULT' => $LANG['poll_result'], 'U_POLL_RESULT' => url('.php?id=' . $poll_mini['id'] . '&r=1', '-' . $poll_mini['id'] . '-1.php'))); $tpl->assign_block_vars('question', array('ID' => url('.php?id=' . $poll_mini['id'], '-' . $poll_mini['id'] . '.php'), 'QUESTION' => $poll_mini['question'])); $z = 0; if ($poll_mini['type'] == '1') { if (is_array($poll_mini['votes'])) { // FIXME should always be an array, needs to patch cache generation foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('question.radio', array('NAME' => $z, 'ANSWERS' => $answer)); $z++; } } } elseif ($poll_mini['type'] == '0') { foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('question.checkbox', array('NAME' => $z, 'ANSWERS' => $answer)); $z++; } } } return $tpl->render(); }
/** * {@inheritdoc} */ public function synchronize() { $this->polls = array(); $result = PersistenceContext::get_querier()->select("SELECT id, question, votes, answers, type\n\t\tFROM " . PollSetup::$poll_table . "\n\t\tWHERE archive = 0 AND visible = 1 AND id IN :ids_list", array('ids_list' => PollConfig::load()->get_displayed_in_mini_module_list())); while ($row = $result->fetch()) { $row['question'] = stripslashes($row['question']); $row['answers'] = explode('|', $row['answers']); $row['votes'] = explode('|', $row['votes']); $number_votes = array_sum($row['votes']) ? array_sum($row['votes']) : 1; $array_votes = array_combine($row['answers'], $row['votes']); foreach ($array_votes as $answer => $nbrvote) { $array_votes[$answer] = NumberHelper::round($nbrvote * 100 / $number_votes, 1); } $row['votes'] = $array_votes; $row['total'] = $number_votes; $this->polls[$row['id']] = $row; } $result->dispose(); }
* ------------------- * begin : November 28, 2007 * copyright : (C) 2007 Viarre r�gis * email : crowkait@phpboost.com * * ################################################### * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ if (defined('PHPBOOST') !== true) { exit; } load_module_lang('poll'); //Chargement de la langue du module. define('TITLE', $LANG['poll']); $poll_config = PollConfig::load();
private function get_authorizations($bit) { return AppContext::get_current_user()->check_auth(PollConfig::load()->get_authorizations(), $bit); }