/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if ($this->CanAccess('create')) {
         $model = new QuestionResource();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['QuestionResource'])) {
             $model->attributes = $_POST['QuestionResource'];
             if ($model->CanUpdate() && $model->save()) {
                 // if AJAX request , we should not redirect the browser
                 if (!Yii::app()->request->isAjaxRequest) {
                     $this->redirect(array('view', 'id' => $model->id));
                 } else {
                     // UNCOMMENT THIS IF YOU WANT TO RETURN ID OF THE NEWLY CREATED
                     // OBJECT (USEFUL WHEN CREATING NEW OBJECTS VIA AJAX AND INFO ABOUT
                     // THEN NEWLY CREATED OBJECT MUST BE SENT TO THE BROWSER)
                     // echo CJSON::encode(array('error' => '', 'id' => $model->id));
                     // die();
                 }
             } else {
                 throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.'));
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->render('create', array('model' => $model));
             // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
             // USE THIS LINE AND DELETE THE LINE ABOVE
             // $this->render('create', array('model' => $model, 'ajaxRendering' => false));
         } else {
             throw new CHttpException(400, Yii::t('app', 'Bad request. The request cannot be fulfilled.'));
             // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
             // USE THIS LINE AND DELETE THE LINE ABOVE
             // $this->renderPartial('create', array('model' => $model, 'ajaxRendering' => true));
         }
     } else {
         throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.'));
     }
 }
Example #2
0
 public function FillQuestionResource($QuestionModel, $fileData, $fileName, $path, $file_type, $type, $start_up, $language_code, &$CurrentResources)
 {
     $language = Language::model()->find("short=:short", array(':short' => $language_code));
     if ($language == null) {
         throw new CHttpException(405, Yii::t('app', 'Language code is not exists'));
     }
     $questionResource = QuestionResource::model()->find('question_id=:question_id and language_id=:language_id and path=:path and filename=:filename', array(':question_id' => $QuestionModel->id, ':language_id' => $language->id, ':path' => $path, ':filename' => $fileName));
     if ($questionResource == null) {
         $questionResource = new QuestionResource();
         $questionResource->question_id = $QuestionModel->id;
         $questionResource->language_id = $language->id;
         $questionResource->filename = $fileName;
         $questionResource->path = $path;
     }
     $questionResource->data = $fileData;
     $questionResource->file_type = $file_type;
     $questionResource->type = $type;
     $questionResource->start_up = $start_up;
     if ($questionResource->save()) {
         //Saved OK
         $CurrentResources[$questionResource->id] = true;
     } else {
         throw new CHttpException(405, Yii::t('app', 'Save question resource failed'));
     }
 }