Пример #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function deleteFromFavorite($id)
 {
     AdFavorite::findOne(['user_id' => Yii::$app->user->id, 'ad_id' => $id])->delete();
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 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')]);
 }
Пример #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFavorite($id)
 {
     $modelAdFavorite = AdFavorite::findOne(['user_id' => Yii::$app->user->id, 'ad_id' => $id]);
     return $modelAdFavorite ? true : false;
 }