Beispiel #1
0
 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));
 }
 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));
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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));
             }
             foreach ($contest->fields as $field) {
                 if ($field->type == 'checkbox') {
                     $entry->{$field->id} = unserialize($entry->{$field->id});
                 }
             }
         }
         $this->render('detail', array('contest' => $contest, 'currentDate' => $currentDate, 'entry' => $entry));
     }
 }