/** * @return \yii\db\ActiveQuery */ public function deleteFromFavorite($id) { AdFavorite::findOne(['user_id' => Yii::$app->user->id, 'ad_id' => $id])->delete(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchFavorites($params) { $query = AdMain::find()->joinWith('adCategory')->joinWith('adFavorites')->where(['temp' => 0])->andWhere([AdFavorite::tableName() . '.user_id' => Yii::$app->user->id])->orderBy(['updated_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
public function actionDeleteFromFavorites() { $id = Yii::$app->request->post('id'); $modelAdFavorite = new AdFavorite(); $modelAdFavorite->deleteFromFavorite($id); Yii::$app->session->setFlash('info', Yii::t('app', 'This ad is removed from your favorites.')); return $this->renderAjax('@common/widgets/AdWidget/views/_icon-favorite-empty', ['id' => Yii::$app->request->post('id'), 'icon' => Yii::$app->request->post('icon')]); }
/** * @return \yii\db\ActiveQuery */ public function getFavorite($id) { $modelAdFavorite = AdFavorite::findOne(['user_id' => Yii::$app->user->id, 'ad_id' => $id]); return $modelAdFavorite ? true : false; }