/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Projects::find(); $query->where(['id_user' => Yii::$app->user->identity->id]); $query->orderBy("date_post DESC"); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'date_post' => $this->date_post, 'date_update' => $this->date_update, 'id_user' => $this->id_user]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Updates an existing Campaigns 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); $projects = Projects::all_users_projects_one(Yii::$app->user->identity->id, $model->id_project); // проекты пользователя $spheres = Spheres::all_spheres(); // список сфер деятельности $time = Yii::$app->request->get(); if (!empty($time['analytics'])) { $time_end = $time['analytics'] / 1000; $time_end = $time_end + 10 * 24 * 3600; $time_end = date('Y-m-d', $time_end); } else { $time_begin = $model->date_begin; $time_begin = date('Y-m-d', $time_begin); $time_end = $model->date_end; $time_end = date('Y-m-d', $time_end); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('flashupdate', constant('FLASH_UPDATE')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'projects' => $projects, 'spheres' => $spheres, 'time_begin' => $time_begin, 'time_end' => $time_end]); } }
public function getProjects() { return $this->hasOne(Projects::className(), ['id' => 'id_project']); }
public static function all_users_projects_one($user_id, $id) { $model = Projects::find()->where(['id_user' => $user_id, 'id' => $id])->all(); return static::find()->where(['id_user' => $user_id, 'id' => $id])->all(); }
/** * Finds the Projects model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Projects the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Projects::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }