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); }
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)); } }
public function actionIndex($idVoting = null) { $voting = Voting::model()->onlyActive($order = 'name')->findAll(); $this->render('/index', array('voting' => $voting, 'idVotingCurrent' => $idVoting)); }