예제 #1
0
 /**
  * Updates an existing Banner model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $resourceModel = new Resource();
         $model = $resourceModel->uploadImg($model, 'img');
         $model->update_time = Common::getTime();
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('update', ['model' => $model]);
 }
예제 #2
0
 /**
  * [actionUploadHeadPic 上传头像]
  * @return [type] [description]
  */
 public function actionUploadHeadPic()
 {
     $data = Yii::$app->request->post();
     $id = $data['User']['id'];
     $model = $this->findModel($id);
     $model->setScenario('profile');
     $resourceModel = new Resource();
     $model = $resourceModel->uploadImg($model, 'head_picture');
     if ($model) {
         if ($model->save()) {
             $res = ['initialPreview' => '<p>' . Yii::t('app', 'Upload success!') . '</p>'];
             echo json_encode($res);
         }
     }
 }
예제 #3
0
 /**
  * Updates an existing Task model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model = $model->validateAttr($model);
         if (empty($model->errors)) {
             $resourceModel = new Resource();
             $model = $resourceModel->uploadImg($model, 'image');
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     if ($model->is_timing == $model::IS_NOT_TIMING) {
         $model->complete_time = '00:00';
     }
     if ($model->task_type == $model::TYPE_CHOICE) {
         $optionArr = json_decode($model->option_json, true);
         // var_dump($optionArr);die;
         foreach ($optionArr as $k => $v) {
             $index = 'option_' . $k;
             $model->{$index} = $v;
         }
         $model->answer_choice = json_decode($model->answer_json, true);
         return $this->render('update-choice', ['model' => $model]);
     }
     if ($model->task_type == $model::TYPE_SHORT_ANSWER || $model->task_type == $model::TYPE_CALCULATION) {
         return $this->render('update-short-calculation', ['model' => $model]);
     }
 }
예제 #4
0
 public function actionUpload()
 {
     $model = new Course();
     $data = Yii::$app->request->post();
     $id = $data['Course']['id'];
     $model = $model::findModel($id);
     $resourceModel = new Resource();
     $model = $resourceModel->uploadImg($model, 'icon');
     if ($model) {
         if ($model->save()) {
             $res = ['initialPreview' => '<p>' . Yii::t('app', 'Upload success!') . '</p>'];
             echo json_encode($res);
         }
     }
 }