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 static function saveCurrentVisit($idObject, $idInstance, $type = 1) { $vs = new VisitSite(); $vs->id_object = $idObject; $vs->id_instance = $idInstance; $vs->type_visit = $type; $vs->ip = ip2long(HU::getUserIp()); $vs->date = time(); $vs->save(); }
public function check($idVote) { if ($this->checkByCookie) { $t = Yii::app()->user->getState('vote_' . $idVote); if ($t != null && is_numeric($t) && $t + $this->expiredTimout * 3600 > time()) { return false; } } if ($this->checkByIp) { $ip = HU::getUserIp(); return VisitSite::check(Voting::ID_OBJECT, $idVote, 1, $ip, $this->expiredTimout * 3600, $this->numVoteIp); } return true; }