function render() { $pollObj = new Poll(); // $current = $pollObj->load_current($_GET['gid']); $this->prev_polls = $pollObj->load_prev_polls(isset($_GET) && isset($_GET['gid']) ? $_GET['gid'] : null); if ($this->prev_polls) { foreach ($this->prev_polls as $poll) { $votes = $pollObj->load_vote($poll->poll_id); $poll->total_votes = count($votes); $options = array(); foreach (unserialize($poll->options) as $option => $s) { $options[$option]['title'] = $s; $option_votes = $pollObj->load_vote_option($poll->poll_id, $s); // echo "<pre>".print_r($option_votes,1)."</pre>"; $options[$option]['count'] = $option_votes[2]->counter; $options[$option]['percent'] = $poll->total_votes != 0 ? round($option_votes[2]->counter / $poll->total_votes * 100, 1) : 0; } $poll->options = $options; } $this->inner_HTML = $this->generate_inner_html(); $content = parent::render(); return $content; } else { $this->do_skip = TRUE; return 'skip'; } }
function render() { global $login_uid; $obj = new Poll(); $prev_poll = $obj->load_prevous_polls($_GET['gid']); $cnt = count($prev_poll); for ($i = 0; $i < $cnt; $i++) { $total_votes[$prev_poll[$i]->poll_id] = count($obj->load_vote($prev_poll[$i]->poll_id)); $prev_options[$i] = unserialize($prev_poll[$i]->options); $num_option = count($prev_options[$i]); for ($j = 1; $j <= $num_option; $j++) { if ($prev_options[$i]['option' . $j] != '') { $vote[] = $obj->load_vote_option($prev_poll[$i]->poll_id, $prev_options[$i]['option' . $j]); } } } $percentage = array(); for ($i = 0; $i < count($vote); $i++) { $j = $vote[$i][0]; if ($total_votes[$j] != 0) { $percentage[$j][] = round($vote[$i][2]->counter / $total_votes[$j] * 100, 1); } } $this->current_poll = $obj->load_current($_GET['gid']); $this->per_prev_poll = $percentage; $this->prev_poll = $prev_poll; $this->prev_options = $prev_options; $this->inner_HTML = $this->generate_inner_html(); $content = parent::render(); return $content; }
function delete($id) { if ($id) { $poll = new Poll($id); $poll->delete(); set_notify('success', lang('delete_data_complete')); } redirect('polls/admin/polls'); }
function mod_poll($poll_id) { require_once BASE_DIR . '/modules/poll/class.poll.php'; require_once BASE_DIR . '/modules/poll/funcs/func.rewrite.php'; $poll = new Poll(); $tpl_dir = BASE_DIR . '/modules/poll/templates/'; $lang_file = BASE_DIR . '/modules/poll/lang/' . $_SESSION['user_language'] . '.txt'; $poll->pollShow($tpl_dir, $lang_file, stripslashes($poll_id)); }
function pollView() { $vote = new Poll(); $total = $vote->totalVote(); $this->viewData(); // var_dump($percent);die; F3::set("total", $total); F3::set('template', 'poll_detail'); echo Template::serve("template/layout.htm"); }
public function getAllPolls() { $rows = $this->db->get('Polls')->result(); $list = array(); foreach ($rows as $row) { $poll = new Poll(); $poll->load($row); $list[] = $poll; } return json_encode($list); }
private function startPoll($sessionId, $topic) { $session = $this->getSession($sessionId); // Start new poll $poll = new Poll(); $poll->setTopic($topic); $poll->setSession($session); // Update session $session->setLastAction(new DateTime()); $session->setCurrentPoll($poll); // Save changes $this->saveAll([$session, $poll]); return $poll; }
/** * Creates a new PollEditor object. * * @param integer $pollID * @param integer $messageID * @param string $messageType */ public function __construct($pollID = 0, $messageID = 0, $messageType = 'post', $canStartPublicPoll = true) { $this->canStartPublicPoll = $pollID == 0 ? $canStartPublicPoll : false; $this->data['pollID'] = $pollID; $this->data['messageID'] = $messageID; $this->data['messageType'] = $messageType; $this->data['timeout'] = 0; $this->data['choiceCount'] = 1; $this->data['votesNotChangeable'] = 0; $this->data['sortByResult'] = 0; $this->data['isPublic'] = 0; if ($messageID != 0 || $pollID != 0) { // get poll $sql = "SELECT\t*\n\t\t\t\tFROM \twcf" . WCF_N . "_poll\n\t\t\t\tWHERE\t" . ($messageID != 0 ? "\n\t\t\t\t\tmessageID = " . $messageID . "\n\t\t\t\t\tAND messageType = '" . escapeString($messageType) . "'\t\t\t\t\t\n\t\t\t\t\tAND packageID = " . PACKAGE_ID : "pollID = " . $pollID . "\n\t\t\t\t\tAND packageID = " . PACKAGE_ID); $row = WCF::getDB()->getFirstRow($sql); if (isset($row['pollID'])) { parent::__construct(null, $row); // get poll options $sql = "SELECT\t\t*\n\t\t\t\t\tFROM \t\twcf" . WCF_N . "_poll_option\n\t\t\t\t\tWHERE \t\tpollID = " . $this->pollID . "\n\t\t\t\t\tORDER BY \tshowOrder"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $pollOption = new PollOption($row, $this); $this->pollOptionsArray[] = $pollOption->pollOption; $this->addOption($pollOption); } } } $this->assign(); }
public function loadModel($id) { if (($model = Poll::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgOut, $wgUser; $p = new Poll(); $pollPage = $p->getRandomPollURL( $wgUser->getName() ); if( $pollPage == 'error' ) { $wgOut->setPageTitle( wfMsg( 'poll-no-more-title' ) ); $wgOut->addWikiMsg( 'poll-no-more-message' ); } else { $pollTitle = Title::newFromText( $pollPage ); $wgOut->redirect( $pollTitle->getFullURL() ); } return $pollPage; }
public function run() { $this->htmlOptions['style'] = 'width: ' . $this->width . 'px; height: ' . $this->height . 'px;'; $this->htmlOptions['class'] = "poll"; $poll = Poll::model()->findByPK($this->poll_id); $this->render('index', array('poll' => $poll)); }
/** * Запускаем отрисовку виджета * * @return void */ public function run() { // Авторизован ли пользователь if (Yii::app()->user->isAuthenticated() === false) { return; } if (($user = Yii::app()->user->getProfile()) === null) { return; } $poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active'), 'questions.variants' => array('scopes' => 'active')))->findByPK((int) $this->model_id); if ($poll === null) { return; } // Подгружаем результаты пользователя $userId = $user->id; if (Yii::app()->user->isSuperUser() && Yii::app()->user->getState('adminUserId') !== null) { // Для администратора показываем результаты опроса пользователя в случае подмены $viewedUser = User::model()->findByPK((int) Yii::app()->user->getState('adminUserId')); if ($viewedUser) { $userId = $viewedUser->id; } } $result = Result::model()->with('answers')->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $userId, ':poll_id' => $poll->id)); $this->render($this->view, array('model' => $poll, 'result' => $result)); }
/** * Singleton Pattern * * Auto Create Object Instance. * */ public static function getInstance() { if (null === self::$_objInstance) { self::$_objInstance = new Poll(); } return self::$_objInstance; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown trying to respond to a poll while not logged in. throw new ClientException(_m('You must be logged in to respond to a poll.'), 403); } if ($this->isPost()) { $this->checkSessionToken(); } $id = $this->trimmed('id'); $this->poll = Poll::getKV('id', $id); if (empty($this->poll)) { // TRANS: Client exception thrown trying to respond to a non-existing poll. throw new ClientException(_m('Invalid or missing poll.'), 404); } $selection = intval($this->trimmed('pollselection')); if ($selection < 1 || $selection > count($this->poll->getOptions())) { // TRANS: Client exception thrown responding to a poll with an invalid answer. throw new ClientException(_m('Invalid poll selection.')); } $this->selection = $selection; return true; }
private function handleConfigPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('tree_id')) { throw new Exception('Node ontbreekt.'); } if (!$request->exists('tag')) { throw new Exception('Tag ontbreekt.'); } $tree_id = intval($request->getValue('tree_id')); $tag = $request->getValue('tag'); $key = array('tree_id' => $tree_id, 'tag' => $tag); if ($this->exists($key)) { $this->update($key, $values); } else { $this->insert($values); } viewManager::getInstance()->setType(ViewManager::TREE_OVERVIEW); $this->plugin->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleConfigGet(false); } }
/** * Display the specified resource. * GET /frontend/publiccontact/{id} * * @param int $id * @return Response */ public function show($id) { try { $contact = Contact::findOrFail($id); $articles = News::inCategories(Config::get('settings.homepage'))->where('published', '=', 2)->where('post_type', '=', 1)->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->distinct('permalink')->groupBy('news.id')->orderBy('news.created_at', 'desc')->take(10)->get(); $featured = News::where('published', '=', 2)->where('featured', '=', 1)->where('post_type', '=', 1)->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->orderBy('created_at', 'desc')->take(3)->get(); $results = News::inCategories(Config::get('settings.results'))->distinct('permalink')->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->where('published', '=', 2)->where('post_type', '=', 1)->groupBy('permalink')->orderBy('news.created_at', 'desc')->take(10)->get(); $featuredImage = News::inCategories(array(25))->where('published', '=', 2)->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->where('post_type', '=', 1)->distinct('permalink')->groupBy('news.id')->orderBy('news.created_at', 'desc')->take(3)->get(); $didYouKnow = News::inCategories(array(30))->where('published', '=', 2)->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->where('post_type', '=', 1)->distinct('permalink')->groupBy('news.id')->orderBy('news.created_at', 'desc')->take(3)->get(); $magazine = News::inCategories(Config::get('settings.magazine'))->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->where('published', '=', 2)->where('post_type', '=', 1)->distinct('permalink')->groupBy('news.id')->orderBy('news.created_at', 'desc')->take(4)->get(); $ourComment = News::inCategories(array(17))->where('published', '=', 2)->where('news.created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->where('post_type', '=', 1)->distinct('permalink')->groupBy('news.id')->orderBy('news.created_at', 'desc')->take(4)->get(); $feed = getFeed('http://bazaznanja.puskice.org/feed/qa.rss', 4); $poll = null; $poll = Poll::where('published', '=', '1')->where('end_date', '>', date("Y-m-d H:i:s", strtotime('now')))->where('created_at', '<', date("Y-m-d H:i:s", strtotime('now')))->first(); if (isset($poll->id)) { $poll->pollOptions; } View::share('title', $contact->title . " " . $contact->first_name . " " . $contact->last_name . " | Пушкице | Тачка спајања студената ФОН-а"); $ogimage = Puskice::firstContactImage($contact); $meta = "\t<meta property='og:image' content='" . $ogimage . "'/>\n\t\t\t\t\t\t<meta property='og:title' content='" . __($contact->title . " " . $contact->first_name . " " . $contact->last_name . " | Пушкице | Тачка спајања студената ФОН-а") . "'/>\n\t\t\t\t\t\t<meta property='fb:app_id' content='355697367892039'/>\n\t\t\t\t\t\t<meta property='og:site_name' content='" . __("Пушкице - ФОН Андерграунд") . "'/>\n\t\t\t\t\t\t<meta property='og:type' content='article'/>\n\t\t\t\t\t\t<meta property='og:url' content='" . _l(Request::root() . "/ljudi/" . $contact->id) . "'/>\n\t\t\t\t\t\t<meta property='og:description' content='" . __($contact->description) . "' />\n\t\t\t\t\t\t<meta name='twitter:card' content='summary_large_image'>\n\t\t\t\t\t\t<meta name='twitter:site' content='" . __("Пушкице - ФОН Андерграунд") . "'>\n\t\t\t\t\t\t<meta name='twitter:creator' content='@puskice'>\n\t\t\t\t\t\t<meta name='twitter:domain' content='puskice.org'>\n\t\t\t\t\t\t<meta name='twitter:app:name:iphone' content='" . __("Пушкице") . "'>\n\t\t\t\t\t\t<meta name='twitter:app:name:ipad' content='" . __("Пушкице") . "'>\n\t\t\t\t\t\t<meta name='twitter:title' content='" . __($contact->title . " " . $contact->first_name . " " . $contact->last_name . " | Пушкице") . "'>\n\t\t\t\t\t\t<meta name='twitter:description' content='" . __($contact->description) . "'>\n\t\t\t\t\t\t<meta name='twitter:image' content='" . $ogimage . "'>"; $data = array('articles' => $articles, 'featured' => $featured, 'results' => $results, 'ourComment' => $ourComment, 'magazine' => $magazine, 'featuredImage' => $featuredImage, 'didYouKnow' => $didYouKnow, 'feed' => $feed, 'poll' => $poll, 'meta' => $meta, 'contact' => $contact); $this->setLayout($data); $this->layout->center = View::make('frontend.content.contact', $data); } catch (Exception $e) { App::abort(404); } }
/** * If there is a poll available within range, take the last one and return that poll. * @return mixed:boolean|String False if none found. String of HTML if found. */ public function PollForm() { $poll = Poll::get()->filter(array('Startdate:LessThan' => date('Y-m-d'), 'Enddate:GreaterThan' => date('Y-m-d'))); if ($poll->count()) { return PollForm::create(Controller::curr(), 'PollForm', $poll->last()); } return false; }
public function init() { if (Yii::app()->hasModule('poll')) { $this->_poll = Poll::model()->rand()->active()->find(); $this->title = $this->_poll->title; parent::init(); } }
/** * Get all polls and return them as array * @return array */ public function getPolls() { $arrPolls = array(); $objPolls = $this->Database->execute("SELECT id, title FROM tl_poll" . (\Poll::checkMultilingual() ? " WHERE lid=0" : "") . " ORDER BY title"); while ($objPolls->next()) { $arrPolls[$objPolls->id] = $objPolls->title; } return $arrPolls; }
/** * Generate the module */ protected function compile() { $intPoll = $this->poll; // Try to find the current poll if ($this->poll_current) { $time = time(); $objCurrentPoll = $this->Database->prepare("SELECT id FROM tl_poll WHERE (showStart='' OR showStart<?) AND (showStop='' OR showStop>?)" . (!BE_USER_LOGGED_IN ? " AND published=1" : "") . " ORDER BY showStart DESC, activeStart DESC")->limit(1)->execute($time, $time); if ($objCurrentPoll->numRows) { $intPoll = $objCurrentPoll->id; } } // Return if there is no poll if (!$intPoll) { $this->Template->poll = ''; return; } $objPoll = new \Poll($intPoll); $this->Template->poll = $objPoll->generate(); }
/** * Initializes the portlet. */ public function init() { $assets = Yii::app()->assetManager->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../assets'); $clientScript = Yii::app()->clientScript; $clientScript->registerCssFile($assets . '/poll.css'); $this->_poll = $this->poll_id == 0 ? Poll::model()->latest()->find() : Poll::model()->findByPk($this->poll_id); if ($this->_poll) { $this->title = $this->_poll->title; } parent::init(); }
/** * Initializes the portlet. */ public function init() { // Set the poll module (also kicks in the CSS via the module init) $this->_module = Yii::app()->getModule('poll'); $this->attachBehavior('pollBehavior', 'poll.behaviors.PollBehavior'); $this->_poll = $this->poll_id == 0 ? Poll::model()->with('choices', 'votes', 'totalVotes')->latest()->find() : Poll::model()->with('choices', 'votes', 'totalVotes')->findByPk($this->poll_id); if ($this->_poll) { $this->title = $this->_poll->title; } parent::init(); }
public function afterUninstall() { Yii::app()->settings->clear($this->id); $db = Yii::app()->db; $tablesArray = array(PollChoice::model()->tableName(), PollVote::model()->tableName(), Poll::model()->tableName()); foreach ($tablesArray as $table) { $db->createCommand()->truncateTable($table); $db->createCommand()->dropTable($table); } return parent::afterUninstall(); }
public function display_thread() { $info = $this->thread()->get_threadInfo(); if (isset($_GET['action'])) { $poll = new Poll($info); switch ($_GET['action']) { case 'editpoll': $poll->render_poll_form(true); break; case 'deletepoll': $poll->delete_poll(); break; case 'newpoll': $poll->render_poll_form(); break; case 'edit': $this->render_edit_form(); break; case 'reply': $this->render_reply_form(); break; default: redirect(clean_request('', array('action'), false)); } } else { $response = self::check_download_request(); if ($response == true) { redirect(clean_request("", array("getfile"), false)); } // +1 threadviews $this->increment_thread_views($info['thread']['thread_id']); // +1 see who is viewing thread $this->thread()->set_thread_visitor(); if ($info['thread']['forum_users'] == true) { $info['thread_users'] = $this->get_participated_users($info); } render_thread($info); } }
static function getByIds($ids = array()) { $ids = addslashes(join(',', $ids)); if (array_key_exists($ids, self::$instancesByIds)) { return self::$instancesByIds[$ids]; } self::$instancesByFilter[$ids] = array(); $rs = dbAll("select * from poll where id in ({$ids})"); foreach ($rs as $r) { self::$instancesByIds[$ids][] = Poll::getInstance($r['id'], $r); } return self::$instancesByIds[$ids]; }
public static function show($id) { self::check_logged_in(); $user = User::findByPK($id); $curruser = self::get_user_logged_in(); if (!($curruser->id == $user->id) && !$curruser->admin) { Redirect::to('/user/' . $curruser->id, array('warning' => 'Pääsy kielletty ilman ylläpito-oikeutta!')); } $polls = Poll::findByUser($id); $nonpolls = Poll::findbyUserNeg($id); $objects = array('user' => $user, 'polls' => $polls, 'nonpolls' => $nonpolls); View::make('user/show.html', $objects); }
/** * @see Page::readData() */ public function readData() { parent::readData(); $this->polls = new Polls($this->pollID, $this->canVotePoll); $this->poll = $this->polls->getPoll($this->pollID); if ($this->poll->isPublic) { // get sorted options foreach ($this->poll->getSortedPollOptions() as $pollOption) { $this->votes[$pollOption->pollOptionID] = array('pollOption' => $pollOption, 'users' => array(), 'guests' => 0); } // get poll votes $sql = "SELECT \t\tpoll_option_vote.*,\n\t\t\t\t\t\toption_value.*, user_table.*\n\t\t\t\tFROM \t\twcf" . WCF_N . "_poll_option_vote poll_option_vote\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\t\tON\t\t(user_table.userID = poll_option_vote.userID)\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\tWHERE \t\tpoll_option_vote.pollID = " . $this->pollID . "\n\t\t\t\tORDER BY \tuser_table.username"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (isset($this->votes[$row['pollOptionID']])) { if ($row['userID']) { $this->votes[$row['pollOptionID']]['users'][] = new UserProfile(null, $row); } else { $this->votes[$row['pollOptionID']]['guests']++; } } } } }
function getNotice() { $this->id = $this->trimmed('id'); $this->poll = Poll::staticGet('id', $this->id); if (empty($this->poll)) { // TRANS: Client exception thrown trying to view a non-existing poll. throw new ClientException(_m('No such poll.'), 404); } $notice = $this->poll->getNotice(); if (empty($notice)) { // Did we used to have it, and it got deleted? // TRANS: Client exception thrown trying to view a non-existing poll notice. throw new ClientException(_m('No such poll notice.'), 404); } return $notice; }
function render() { $this->gid = isset($_GET) && isset($_GET['gid']) ? $_GET['gid'] : 0; $this->flag = 0; $obj = new Poll(); $current = $obj->load_current($this->gid); $prev_poll = $obj->load_prev_polls($this->gid); $this->cnt_prev = count($prev_poll); if ($current) { $user_vate = $obj->load_vote($current[0]->poll_id, PA::$login_uid); $total_vote = $obj->load_vote($current[0]->poll_id); $this->total_vote_count = count($total_vote); $this->topic = $obj->load_poll($current[0]->poll_id, $this->gid); $this->options = unserialize($this->topic[0]->options); $num_option = count($this->options); $cnt = count($total_vote); $this->previous_vote_detected = false; if ($cnt > 0) { for ($i = 0; $i < $cnt; $i++) { if ($total_vote[$i]->user_id == PA::$login_uid || @$_COOKIE['vote'] == $current[0]->poll_id || isset($_GET) && isset($_GET['show_poll_results']) && $_GET['show_poll_results'] == 'true') { $this->flag = 1; if ($total_vote[$i]->user_id == PA::$login_uid || @$_COOKIE['vote'] == $current[0]->poll_id) { $this->previous_vote_detected = true; } for ($j = 1; $j <= $num_option; $j++) { if ($this->options['option' . $j] != '') { $vote[] = $obj->load_vote_option($current[0]->poll_id, $this->options['option' . $j]); } } break; } else { $this->flag = 0; } } } if (!empty($vote)) { for ($i = 0; $i < count($vote); $i++) { $this->option_precent[] = round($vote[$i][2]->counter / $this->total_vote_count * 100, 1); $this->option_vote_count[] = $vote[$i][2]->counter; } } $this->inner_HTML = $this->generate_inner_html(); $content = parent::render(); return $content; } else { $this->do_skip = TRUE; return 'skip'; } }
public function actionView($id) { Yii::app()->clientScript->scriptMap = array('jquery.js' => false); $model = Poll::model()->findByPk($id); if ($model) { $fn = new CPollHelper($model); $params = array('model' => $model); if (isset($_POST['PortletPollVote_choice_id'])) { foreach ($_POST['PortletPollVote_choice_id'] as $ids) { $userVote = new PollVote(); $userVote->choice_id = $ids; $userVote->poll_id = $model->id; if ($userVote->validate()) { $userVote->save(false, false); } else { die('err'); } } } $userVote = $fn->loadVote(); if (Yii::app()->settings->get('poll', 'is_force') && $model->userCanVote()) { if (Yii::app()->request->isAjaxRequest) { $this->widget('ext.uniform.UniformWidget', array('theme' => 'default')); $userVote->addError('choise_id', 'Тыкни ты уже кудато!!'); $view = 'poll.widgets.random.views.vote'; } else { $view = 'vote'; } // Convert choices to form options list $choices = array(); foreach ($model->choices as $choice) { $choices[$choice->id] = Html::encode($choice->name); } $params['choices'] = $choices; } else { if (Yii::app()->request->isAjaxRequest) { $view = 'poll.widgets.random.views.view'; } else { $view = 'view'; } $userChoice = $fn->loadChoice($userVote); $params += array('userVote' => $userVote, 'userChoice' => $userChoice); } $this->render($view, $params, false, true); } }