/**
  * 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;
 }
Beispiel #2
0
 public function verifyDelete()
 {
     $categoryId = $this->category_id;
     // check if it has some subcategories
     $categs = $this->findByAttributes(array('parent_category_id' => $categoryId));
     if ($categs) {
         throw new CHttpException(400, 'You cannot delete category that contains some subcategories!');
     }
     $listings = ListingCategory::model()->findByAttributes(array('category_id' => $categoryId));
     if ($listings) {
         throw new CHttpException(400, 'You cannot delete category that contains some listings!');
     }
     $pads = PremiumAdCategory::model()->findByAttributes(array('category_id' => $categoryId));
     if ($pads) {
         throw new CHttpException(400, 'You cannot delete category that contains some premium ads!');
     }
     return true;
 }