/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Visitors::find(); $query->withRelated(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_create' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } if (!empty($this->email)) { $query->byUserEmail($this->email); } return $dataProvider; }
/** * Визиты * @return array */ public function getVisits() { return $this->hasMany(Visitors::className(), ['cv_id' => 'id']); }
/** * Отмечаем, то юзер просматривал резюме * @param \app\models\cv\Cv $cv */ public function visitCv(\app\models\cv\Cv $cv) { $visit = new Visitors(); $visit->cv_id = $cv->id; $visit->user_id = $this->id; return $visit->save(); }