Example #1
0
 protected function saveCategoriesToListing($model)
 {
     foreach ($_POST['Listing']['p_categories'] as $categoryId) {
         $listingCategory = new ListingCategory();
         $listingCategory->listing_id = $model->listing_id;
         $listingCategory->category_id = $categoryId;
         if (!$listingCategory->save()) {
             return false;
         }
     }
     return true;
 }
Example #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();
 }
Example #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;
 }