/** * 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]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Mon1str::find()->joinWith('monitoring1.user.profile.region'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['region'] = ['asc' => [Region::tableName() . '.name' => SORT_ASC], 'desc' => [Region::tableName() . '.name' => SORT_DESC]]; $dataProvider->sort->attributes['month'] = ['asc' => [Month::tableName() . '.month' => SORT_ASC], 'desc' => [Month::tableName() . '.month' => SORT_DESC]]; $dataProvider->sort->attributes['year'] = ['asc' => [Year::tableName() . '.year' => SORT_ASC], 'desc' => [Year::tableName() . '.year' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // $query->andFilterWhere([Monitoring1::tableName() . '.date' => $this->date, Region::tableName() . '.id' => $this->region]); // $query->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getMonth() { return $this->hasOne(Month::className(), ['id' => 'month_id']); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $r = Month::find($id); return response()->json($r); }
public function actionGetMonthByYear() { $id = Yii::$app->request->post('id'); $monthsExist = Monitoring2::find()->select('month_id')->where(['year_id' => $id])->andWhere(['user_id' => Yii::$app->user->id])->column(); $months = Month::find()->where(['NOT IN', 'id', $monthsExist])->all(); $arrayMonth = ArrayHelper::map($months, 'id', 'month'); $options = '<option value="">Оберіть місяць</option>'; foreach ($arrayMonth as $key => $value) { $options .= '<option value=' . $key . '>' . $value . '</option>'; } return $options; }