public function run() { $voting = null; if (is_numeric(HU::post('id_voting'))) { $voting = Voting::model()->onlyActive()->with('answer')->findByPk(HU::post('id_voting')); } if ($voting == null) { //echo CHtml::encode($this->controller->widget('vote.widgets.VoteWidget', null, true)); return; } if (Yii::app()->vote->check($voting->id_voting)) { $answers = $_POST['VotingAnswer']['name']; $cr = new CDbCriteria(); $cr->addColumnCondition(array('id_voting' => $voting->id_voting)); if (is_array($answers)) { $cr->addInCondition('id_voting_answer', $answers); } else { if (is_numeric($answers)) { $cr->addColumnCondition(array('id_voting_answer' => $answers)); } } VotingAnswer::model()->updateCounters(array('count' => 1), $cr); VisitSite::saveCurrentVisit(Voting::ID_OBJECT, $voting->id_voting); Yii::app()->user->setState('vote_' . $voting->id_voting, time()); // перегружаем голосовалку, чтоб обновились показатели счетчиков $voting = Voting::model()->onlyActive()->with('answer')->findByPk($voting->id_voting); } $voteCount = $voting->getSumVote(); echo CHtml::encode($this->controller->renderPartial("vote.widgets.views.statistic", array('voting' => $voting, 'voteCount' => $voteCount)), null, true); }
protected function setConn() { try { self::$conn = new PDO("mysql:host=" . DBHOST . "; dbname=" . DBNAME, DBUSER, DBPASS); self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$conn->exec('SET CHARACTER SET utf8'); } catch (PDOException $e) { $this->eror = 'Unable to connect to MySQL: ' . $e->getMessage(); } }
public function getStart() { // Needs logged in user with voting privileges if (!(Auth::check() && Auth::user()->canStartVoting())) { return Redirect::to('/'); } $current = Voting::current()->get(); if (count($current) == 0) { if (Song::requests()->count() > 0) { $voting = new Voting(); $voting->created_by = Auth::user()->id; $voting->save(); } else { Session::flash('error', 'Geen nummers om over te stemmen! D:'); } } return Redirect::to('/vote'); }
public function scopeInVote($query) { $current = Voting::current(); if ($current->count() > 0) { $current = $current->first(); // $previous = Voting::where('ended', '<', $current->created_at); $query = $query->whereVoted(false)->where('created_at', '<=', $current->created_at); /*if ($previous->count() > 0) { $previous = $previous->first(); $query = $query->where('created_at', '>', $previous->ended); }*/ return $query->orderBy('created_at', 'desc'); } return $query; }
public function run() { $voting = null; if ($this->inModule) { if ($this->controller->id == 'voting') { return; } // находясь в разделе не показываем виджет $voting = Voting::model()->inModule()->onlyActive()->with('answer')->find(); } else { if ($this->idVoting == null) { return; } $voting = Voting::model()->onlyActive()->with('answer')->findByPk($this->idVoting); } if ($voting == null) { return; } if (Yii::app()->vote->check($voting->id_voting)) { $this->render('index', array('view' => 'view', 'voting' => $voting, 'voteCount' => 0)); } else { $this->render('index', array('view' => 'statistic', 'voteCount' => $voting->getSumVote(), 'voting' => $voting)); } }
/** * Get all the Votes for the object with the given itemid * * @param string $itemid * @return Voting or Error */ function getVotes($itemid) { $n = new Voting($itemid); return $n->load(); }
if ($nrrows > 0) { for ($i = 0; $i < $nrrows; $i++) { $row = explode('|', $rows[$i]); if ($row[0] == $this->tdy) { $re['all'][] = $rows[$i]; if ($row[1] == $this->voter) { $re[$this->tdy][] = $row[2]; } } } } } return $re; } } $obVot = new Voting(); if (isset($_POST['elm']) && isset($_POST['vote'])) { $_POST['elm'] = array_map('strip_tags', $_POST['elm']); $_POST['elm'] = array_map('trim', $_POST['elm']); if (!empty($_POST['vote'])) { $_POST['vote'] = intval($_POST['vote']); } echo $obVot->getVoting($_POST['elm'], $_POST['vote']); } ///////////////////// Антимат function removeBadWords($text) { global $badwords, $cons; $mat = count($badwords); for ($i = 0; $i < $mat; $i++) { $text = preg_replace("/" . $badwords[$i] . "/si", $cons, $text);
public function actionIndex($idVoting = null) { $voting = Voting::model()->onlyActive($order = 'name')->findAll(); $this->render('/index', array('voting' => $voting, 'idVotingCurrent' => $idVoting)); }
function isVoteRunning() { $vote = Voting::where('created_at', '<', 'date(\'now\')')->whereNull('ended')->first(); Debugbar::log($vote); return !is_null($vote); }
if (isset($add_text) and is_array($add_text)) { reset($add_text); while (list($key, $val) = each($add_text)) { ${$key} = $val; $tpl->register($tplt, $key); } } $tpl->parse_loop($tplt, 'system_message'); $tpl->register($tplt, 'txt_system_message'); @eval($conf_var); exit; } /***************************************************** ** Initialize form class *****************************************************/ $vot = new Voting(); /***************************************************** ** Display e-mail field *****************************************************/ if ($check_email == 'yes') { $display_email = true; } /***************************************************** ** Display or hide results link *****************************************************/ if (isset($_GET['result']) and $_GET['result'] == 'true') { $display_results = 'true'; $display_link = 'true'; } else { $display_results = ''; }
function postEndVoting() { $search = Voting::current(); if ($search->count() > 0) { $voting = $search->first(); $voting->ended = date("Y-m-d H:i:s"); $voting->save(); return Response::json(true); } return Response::json(false); }