Esempio n. 1
0
 /**
  * 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 = Listing::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     // load categories
     $criteria = new CDbCriteria();
     $criteria->condition = 'listing_id=:listing_id';
     $criteria->select = 'category_id';
     $criteria->params = array(':listing_id' => $id);
     $listingCategories = ListingCategory::model()->findAll($criteria);
     $categories = array();
     foreach ($listingCategories as $category) {
         $categories[] = $category->category_id;
     }
     $model->p_categories = $categories;
     // load locations
     $criteria = new CDbCriteria();
     $criteria->condition = 'listing_id=:listing_id';
     $criteria->select = 'location_id';
     $criteria->params = array(':listing_id' => $id);
     $listingLocations = ListingLocation::model()->findAll($criteria);
     $locations = array();
     foreach ($listingLocations as $location) {
         $locations[] = $location->location_id;
     }
     $model->p_locations = $locations;
     return $model;
 }
Esempio n. 2
0
 function beforeDelete()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'listing_id=:listing_id';
     $criteria->params = array(':listing_id' => $this->listing_id);
     ListingCategory::model()->deleteAll($criteria);
     ListingLocation::model()->deleteAll($criteria);
     Coupon::model()->deleteAll($criteria);
     // delete logo file
     if ($this->logo != '') {
         $imageFile = Yii::app()->user->getFullPathToImages(Yii::app()->params['listingLogo']) . $this->logo;
         @unlink($imageFile);
     }
     return parent::beforeDelete();
 }
Esempio n. 3
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;
 }