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


PHP Contest::model方法代码示例

本文整理汇总了PHP中Contest::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Contest::model方法的具体用法?PHP Contest::model怎么用?PHP Contest::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contest的用法示例。


在下文中一共展示了Contest::model方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionShow

 public function actionShow($id)
 {
     $model = Contest::model()->findByPk((int) $id);
     if (is_null($model)) {
         throw new CHttpException(404, Yii::t('contest', 'Страница не найдена!'));
     }
     $image = new Image();
     if (Yii::app()->request->isPostRequest && isset($_POST['Image'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $image = $image->create($_POST['Image']);
             if (!$image->hasErrors()) {
                 if ($model->addImage($image)) {
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('contest', 'Фотография добавлена!'));
                 }
                 $transaction->commit();
                 $this->redirect(array('/contest/contest/show/', 'id' => $model->id));
             }
             throw new CDbException(Yii::t('contest', 'При добавлении изображения произошла ошибка!'));
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('contest', $e->getMessage()));
         }
     }
     $dataProvider = new CActiveDataProvider('ImageToContest', array('criteria' => array('condition' => 'contest_id = :contest_id', 'params' => array(':contest_id' => $model->id), 'limit' => self::CONTEST_PER_PAGE, 'order' => 't.creation_date DESC', 'with' => 'image'), 'pagination' => array('pageSize' => self::CONTEST_PER_PAGE)));
     $this->render('show', array('image' => $image, 'dataProvider' => $dataProvider, 'model' => $model));
 }
开发者ID:RSol,项目名称:yupe,代码行数:27,代码来源:ContestController.php

示例2: actionStats

 public function actionStats($id)
 {
     if (!($model = Contest::model()->with(array('fields'))->findByPk($id))) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $this->render('stats', array('model' => $model));
 }
开发者ID:kostya1017,项目名称:our,代码行数:7,代码来源:AdminresultsController.php

示例3: 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 = Contest::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:RSol,项目名称:yupe,代码行数:13,代码来源:DefaultController.php

示例4: actionDetail

 public function actionDetail($n, $confirmation = 0)
 {
     if (Yii::app()->user->getState('siteVersion') == 'mobile') {
         Yii::app()->clientScript->registerCssFile('/css/mobile/blocs.css');
         $this->layout = '//mobileLayouts/column1';
     }
     if (!($contest = Contest::model()->with(array('fields' => array('order' => 'fields.rank ASC'), 'fields.multi' => array('order' => 'multi.rank ASC')))->find('i18nContest.l_title_url=:n', array('n' => $n)))) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $currentDate = date('Y-m-d H:i:s');
     $contestMultilang = Contest::model()->multilang()->find('i18nContest.l_title_url=:n', array('n' => $n));
     Yii::app()->languageManager->translatedGetVars['n'] = array();
     foreach (array_keys(Yii::app()->languageManager->languages) as $language) {
         Yii::app()->languageManager->translatedGetVars['n'][$language] = $contestMultilang->{'title_url_' . $language};
     }
     // In case detail page is accessed directly and contest is inactive.
     if ($contest->status == "inactive") {
         $this->redirect($this->createUrl('index'));
     }
     if ($confirmation) {
         $this->render('confirmation', array('contest' => $contest));
     } elseif ($contest->end_date !== null && $contest->end_date < $currentDate || $contest->status == "archived") {
         $this->render('conclusion', array('contest' => $contest));
     } else {
         $entry = new EntryForm();
         $validators = $entry->getValidatorList();
         $required = 'verify_code, ';
         $files = '';
         $length = '';
         $email = '';
         $entry->verify_code = null;
         $entry->attributeLabels['verify_code'] = Yii::t('contestModule.common', 'Code de sécurité');
         $validators->add(CValidator::createValidator('captcha', $this, 'verify_code', array('message' => Yii::t('contestModule.common', 'Le code saisi est invalide. Veuillez entrer le code à nouveau.'), 'allowEmpty' => !CCaptcha::checkRequirements(), 'captchaAction' => '/site/captcha')));
         foreach ($contest->fields as $field) {
             $entry->{$field->id} = null;
             $entry->attributeLabels[$field->id] = CHtml::encode($field->title);
             if ($field->required) {
                 $required .= $field->id . ', ';
             }
             $length .= $field->id . ', ';
             if ($field->type == 'email') {
                 $email .= $field->id . ', ';
             }
             if ($field->type == 'file') {
                 $files = $field->id . ', ';
                 $behaviors = array('class' => 'application.models.behaviors.UploadingBehavior.ModelUploadingBehavior', 'attribute' => $field->id, 'dir' => 'files/_user/contest_entries', 'tempDir' => 'files/_user/contest_entries/_temp', 'cacheTime' => 10 * 24 * 60 * 60, 'uploadcare' => null, 'allowDelete' => false);
                 $entry->{$field->id . 'Handler'} = $entry->attachBehavior($field->id . 'Handler', $behaviors);
                 $entry->behaviors = array($behaviors);
             }
         }
         if ($required != '') {
             $validators->add(CValidator::createValidator('required', $this, substr($required, 0, -2)));
         }
         if ($length != '') {
             $validators->add(CValidator::createValidator('length', $this, substr($length, 0, -2), array('max' => 1000)));
         }
         if ($email != '') {
             $validators->add(CValidator::createValidator('email', $this, substr($email, 0, -2)));
         }
         if ($files != '') {
             $validators->add(CValidator::createValidator('file', $this, substr($files, 0, -2), array('allowEmpty' => true)));
         }
         if (isset($_POST['EntryForm'])) {
             foreach ($_POST['EntryForm'] as $id => $attribute) {
                 if (is_array($attribute)) {
                     $entry->{$id} = serialize($attribute);
                 } else {
                     $entry->{$id} = $attribute;
                 }
             }
             if ($entry->validate()) {
                 $entryModel = new ContestEntry();
                 $entryModel->contest_id = $contest->id;
                 $entryModel->ip = $_SERVER['REMOTE_ADDR'];
                 $entryModel->save();
                 foreach ($contest->fields as $field) {
                     if ($field->type == 'checkbox') {
                         $entry->{$field->id} = unserialize($entry->{$field->id});
                     }
                     if (is_array($entry->{$field->id})) {
                         foreach ($entry->{$field->id} as $entryValue) {
                             $model = new ContestEntryItem();
                             $model->contest_entry_id = $entryModel->id;
                             $model->contest_field_id = $field->id;
                             $model->content = $entryValue;
                             $model->save();
                         }
                     } else {
                         $model = new ContestEntryItem();
                         $model->contest_entry_id = $entryModel->id;
                         $model->contest_field_id = $field->id;
                         $model->content = $entry->{$field->id};
                         $model->save();
                     }
                 }
                 if ($contest->send_notification_email == 1) {
                     $message = $this->renderPartial('_notificationEmail', array('entry' => $entryModel, 'contest' => $contest), true);
                     Helper::sendMail($this->module->notificationEmail, 'Nouvelle participation à "' . CHtml::encode($contest->title) . '"', $message);
                 }
                 $this->redirect(array('detail', 'n' => $n, 'confirmation' => 1));
//.........这里部分代码省略.........
开发者ID:kostya1017,项目名称:our,代码行数:101,代码来源:DefaultController.php


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