当前位置: 首页>>代码示例>>PHP>>正文


PHP Poll::model方法代码示例

本文整理汇总了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));
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:30,代码来源:PollWidget.php

示例2: loadModel

 public function loadModel($id)
 {
     if (($model = Poll::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:7,代码来源:PollBackendController.php

示例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));
 }
开发者ID:bahdall,项目名称:karbella_event,代码行数:7,代码来源:PollWidget.php

示例4: init

 public function init()
 {
     if (Yii::app()->hasModule('poll')) {
         $this->_poll = Poll::model()->rand()->active()->find();
         $this->title = $this->_poll->title;
         parent::init();
     }
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:8,代码来源:BasePollWidget.php

示例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();
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:11,代码来源:PollModule.php

示例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();
 }
开发者ID:josemanuel3dx,项目名称:SEMMIO,代码行数:14,代码来源:EPoll.php

示例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();
 }
开发者ID:phamvanvung1993,项目名称:yii-poll,代码行数:14,代码来源:EPoll.php

示例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);
     }
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:46,代码来源:DefaultController.php

示例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>";
     }
 }
开发者ID:bahdall,项目名称:karbella_event,代码行数:21,代码来源:PollController.php

示例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;
 }
开发者ID:josemanuel3dx,项目名称:SEMMIO,代码行数:13,代码来源:PollController.php

示例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()));
         }
     }
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:77,代码来源:PollController.php

示例12: loadModel

 public function loadModel($id)
 {
     $model = Poll::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404);
     }
     return $model;
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:8,代码来源:DefaultController.php

示例13: getPollList

 public function getPollList()
 {
     $models = Poll::model()->findAll();
     return CHtml::listData($models, 'id', 'title');
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:5,代码来源:Block.php

示例14: getPollList

 public function getPollList()
 {
     return CHtml::listData(Poll::model()->findAll(array('select' => 'id, title')), 'id', 'title');
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:4,代码来源:Question.php


注:本文中的Poll::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。