public function actionDelete($id) { if (Yii::app()->user->isGuest) { throw new CHttpException(403, 'You are not authorized.'); } $wishlist = PropertyWishlistApi::getWishlistUserOnProperty($id, Yii::app()->user->id); if ($wishlist) { if ($wishlist->user_id !== Yii::app()->user->id) { throw new CHttpException(403, 'You are not authorized.'); } if (PropertyWishlist::model()->deleteByPk($wishlist->id)) { Yii::app()->user->setFlash('success', 'The property was removed from your wishlist.'); } else { Yii::app()->user->setFlash('error', 'The property could not be removed from your wishlist. Please contact the admin.'); } } else { Yii::app()->user->setFlash('error', 'The property could not be removed from your wishlist. Please contact the admin.'); } $this->redirect('/wishlists'); }
public static function getCriteriaObjectForUser($userId) { $wishlist = PropertyWishlist::model()->findAll('user_id=:userId', array(':userId' => $userId)); $propertyIds = array(); foreach ($wishlist as $property) { $propertyIds[] = $property->property_id; } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $propertyIds); return $criteria; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = PropertyWishlist::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }