/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ContactMoment::find(); $dataProvider = new ActiveDataProvider(['query' => $query->joinWith(['customer', 'creator'])]); $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, 'moment' => $this->moment, 'updater_id' => $this->updater_id, 'datetime_added' => $this->datetime_added, 'datetime_updated' => $this->datetime_updated, 'deleted' => $this->deleted]); $query->andFilterWhere(['like', 'contact_moment.comment', $this->comment])->andFilterWhere(['like', 'user.username', $this->creator_id])->andFilterWhere(['like', 'customer.name', $this->customer_id]); return $dataProvider; }
/** * Finds the ContactMoment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ContactMoment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ContactMoment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getContactMoment() { return $this->hasOne(ContactMoment::className(), ['id' => 'contact_moment_id']); }
public function getContactMoments() { return $this->hasMany(ContactMoment::className(), ['customer_id' => 'customer_id']); }