public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (!Yii::$app->user->can('admin')) {
         if ($model->user_id != Yii::$app->user->id) {
             $this->redirect(['index']);
         }
     }
     if (!Yii::$app->user->can('admin')) {
         if ($model->status == 1) {
             $this->redirect(['index']);
         }
     }
     $months = Month::find()->all();
     $years = Year::find()->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d', strtotime($model->date));
         if (!Monitoring2::find()->where(['date' => $model->date, 'user_id' => Yii::$app->user->id])->one()) {
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years]);
 }
 public function putActual()
 {
     $user = User::fromToken();
     $year = Year::find(Request::input('year_id'));
     $year->config_certificado_estudio_id = Request::input('config_certificado_estudio_id');
     $year->save();
     return 'Cambiado';
 }
 /**
  * Updates an existing Monitoring1 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);
     $months = Month::find()->all();
     $years = Year::find()->all();
     $model->user_id = Yii::$app->user->id;
     //      добавление даты  http://www.yiiframework.com/doc-2.0/guide-output-formatting.html
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years]);
     }
 }
Esempio n. 4
0
 public static function de_un_periodo($periodo_id)
 {
     $periodo = Periodo::find($periodo_id);
     $year = Year::find($periodo->year_id);
     return $year;
 }
 /**
  * Updates an existing Monitoring1 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);
     $modelsStr = $model->mon1str;
     if (!Yii::$app->user->can('admin')) {
         if ($model->user_id != Yii::$app->user->id) {
             $this->redirect(['index']);
         }
     }
     if (!Yii::$app->user->can('admin')) {
         if ($model->status == 1) {
             $this->redirect(['index']);
         }
     }
     $months = Month::find()->all();
     $years = Year::find()->all();
     //        $model->user_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d', strtotime($model->date));
         if (!Monitoring1::find()->where(['date' => $model->date, 'user_id' => Yii::$app->user->id])->one()) {
             if ($model->save()) {
                 $oldIDs = ArrayHelper::map($modelsStr, 'id', 'id');
                 $modelsStr = Model::createMultiple(Mon1str::classname(), $modelsStr);
                 Model::loadMultiple($modelsStr, Yii::$app->request->post());
                 $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsStr, 'id', 'id')));
                 // ajax validation
                 if (Yii::$app->request->isAjax) {
                     Yii::$app->response->format = Response::FORMAT_JSON;
                     return ArrayHelper::merge(ActiveForm::validateMultiple($modelsStr), ActiveForm::validate($model));
                 }
                 // validate all models
                 $valid = $model->validate();
                 $valid = Model::validateMultiple($modelsStr) && $valid;
                 if ($valid) {
                     $transaction = \Yii::$app->db->beginTransaction();
                     try {
                         if ($flag = $model->save(false)) {
                             if (!empty($deletedIDs)) {
                                 Mon1str::deleteAll(['id' => $deletedIDs]);
                             }
                             foreach ($modelsStr as $modelStr) {
                                 $modelStr->monitoring1_id = $model->id;
                                 if (!($flag = $modelStr->save(false))) {
                                     $transaction->rollBack();
                                     break;
                                 }
                             }
                         }
                         if ($flag) {
                             $transaction->commit();
                             return $this->redirect(['view', 'id' => $model->id]);
                         }
                     } catch (Exception $e) {
                         $transaction->rollBack();
                     }
                 }
             }
         }
     }
     return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years, 'modelsStr' => empty($modelsStr) ? [new Mon1str()] : $modelsStr]);
 }