本文整理汇总了PHP中Poll::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::model方法的具体用法?PHP Poll::model怎么用?PHP Poll::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::model方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Запускаем отрисовку виджета
*
* @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));
}
示例2: loadModel
public function loadModel($id)
{
if (($model = Poll::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例3: run
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));
}
示例4: init
public function init()
{
if (Yii::app()->hasModule('poll')) {
$this->_poll = Poll::model()->rand()->active()->find();
$this->title = $this->_poll->title;
parent::init();
}
}
示例5: afterUninstall
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();
}
示例6: init
/**
* 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();
}
示例7: 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();
}
示例8: actionView
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);
}
}
示例9: actionResult
public function actionResult()
{
if (isset($_GET['id'])) {
$poll = Poll::model()->findByPk($_GET['id']);
echo "<div class='poll-results'>";
foreach ($poll->getChoice($poll->id) as $choice) {
echo CHtml::openTag("div", array("class" => "result"));
echo CHtml::openTag("div", array("class" => "label"));
echo $choice->name;
echo CHtml::closeTag("div");
echo CHtml::openTag("div", array("class" => "bar"));
echo "<div class='fill' style='width: " . $choice->getVote($choice->id) . "%;'></div>";
echo CHtml::closeTag("div");
echo CHtml::openTag("div", array("class" => "totals"));
echo "<span class='percent'>" . $choice->getVote($choice->id) . "%</span>";
echo CHtml::closeTag("div");
echo CHtml::closeTag("div");
}
echo "</div>";
}
}
示例10: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Poll::model()->with('choices', 'votes')->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例11: actionSave
public function actionSave($id)
{
// Получаем куки для опроса
/*
define('COOKIE_NAME', 'poll_genplanmos_ru');
$isCookie = isset(Yii::app()->request->cookies[COOKIE_NAME]->value);
$pollCookie = $isCookie ?
Yii::app()->request->cookies[COOKIE_NAME] :
new CHttpCookie(COOKIE_NAME, '');
$pollCookieValue = $isCookie? CJSON::decode($pollCookie->value) : array();
*
*/
// Авторизован ли пользователь
if (Yii::app()->user->isAuthenticated() === false) {
$this->redirect(Yii::app()->user->loginUrl);
}
if (($user = Yii::app()->user->getProfile()) === null) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
Yii::app()->user->logout();
$this->redirect((array) '/user/account/login');
}
$poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active')))->findByPK((int) $id);
if (!$poll) {
throw new CHttpException(404, Yii::t('PollModule.poll', 'Страница не найдена'));
}
// Поиск результата
$result = Result::model()->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $user->id, ':poll_id' => $poll->id));
if ($result !== null) {
throw new CHttpException(403, Yii::t('PollModule.poll', 'Вы уже проходили данный опрос'));
}
$result = new Result();
$result->user_id = $user->id;
$result->poll_id = $poll->id;
// Обработка результата
if (($data = Yii::app()->getRequest()->getPost('question')) !== null) {
// Формирование списка ответов
$answers = array();
foreach ($poll->questions as $question) {
$formValue = isset($data[$question->id]) ? $data[$question->id] : null;
switch ($question->type) {
case Question::TYPE_VARIANT:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = $formValue !== null ? (int) $formValue : $formValue;
$answers[] = $answer;
break;
case Question::TYPE_MULTIPLE:
// Просматриваем полученные ответы
if (!isset($formValue) || !is_array($formValue)) {
break;
}
foreach ($formValue as $value) {
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = (int) $value;
$answers[] = $answer;
}
break;
default:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->value = $formValue !== null ? $formValue : '';
$answers[] = $answer;
break;
}
$result->answers = $answers;
}
if ($result->validate()) {
$result->save();
Yii::app()->ajax->success(array('html' => $this->widget('application.modules.poll.widgets.PollWidget', array('model_id' => $poll->id), true)));
} else {
Yii::app()->ajax->failure(array('message' => '', 'errors' => $result->getErrors()));
}
}
}
示例12: loadModel
public function loadModel($id)
{
$model = Poll::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404);
}
return $model;
}
示例13: getPollList
public function getPollList()
{
$models = Poll::model()->findAll();
return CHtml::listData($models, 'id', 'title');
}
示例14: getPollList
public function getPollList()
{
return CHtml::listData(Poll::model()->findAll(array('select' => 'id, title')), 'id', 'title');
}