/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $id_wp = 0) { if ($id_wp == 0) { $query = StoryWorkplace::find(); } else { $query = StoryWorkplace::find()->where(['id_wp' => $id_wp]); } $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, 'id_wp' => $this->id_wp, 'id_employee' => $this->id_employee, 'date_up' => $this->date_up, 'event' => $this->event]); return $dataProvider; }
/** * Deletes an existing WpOwners model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $workplace_id * @param integer $employee_id * @return mixed */ public function actionDelete($workplace_id, $employee_id, $id_wp = 0) { $wp_owner = $this->findModel($workplace_id, $employee_id); if ($wp_owner->delete()) { $story = new StoryWorkplace(); $story->id_wp = $workplace_id; $story->id_employee = $employee_id; $story->event = 0; $story->save(); } if ($id_wp == 0) { return $this->redirect(['index']); } else { return $this->redirect(['workplaces/view', 'id' => $id_wp]); } }
/** * Finds the StoryWorkplace model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return StoryWorkplace the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = StoryWorkplace::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }