/** * 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 = PremiumAd::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } // load categories $criteria = new CDbCriteria(); $criteria->condition = 'premiumad_id=:premiumad_id'; $criteria->select = 'category_id'; $criteria->params = array(':premiumad_id' => $id); $adCategories = PremiumAdCategory::model()->findAll($criteria); $categories = array(); foreach ($adCategories as $category) { $categories[] = $category->category_id; } $model->p_categories = $categories; // load locations $criteria = new CDbCriteria(); $criteria->condition = 'premiumad_id=:premiumad_id'; $criteria->select = 'location_id'; $criteria->params = array(':premiumad_id' => $id); $adLocations = PremiumAdLocation::model()->findAll($criteria); $locations = array(); foreach ($adLocations as $location) { $locations[] = $location->location_id; } $model->p_locations = $locations; // load listings $criteria = new CDbCriteria(); $criteria->condition = 'premiumad_id=:premiumad_id'; $criteria->select = 'listing_id'; $criteria->params = array(':premiumad_id' => $id); $adListings = PremiumAdListing::model()->findAll($criteria); $listings = array(); foreach ($adListings as $listing) { $listings[] = $listing->listing_id; } $model->p_listings = $listings; return $model; }
public function verifyDelete() { $locationId = $this->location_id; // check if it has some subcategories $locs = $this->findByAttributes(array('parent_location_id' => $locationId)); if ($locs) { throw new CHttpException(400, 'You cannot delete location that contains some sublocations!'); } $listings = ListingLocation::model()->findByAttributes(array('location_id' => $locationId)); if ($listings) { throw new CHttpException(400, 'You cannot delete location that contains some listings!'); } $pads = PremiumAdLocation::model()->findByAttributes(array('location_id' => $locationId)); if ($pads) { throw new CHttpException(400, 'You cannot delete location that contains some premium ads!'); } return true; }