protected function saveCategoriesToPremiumAd($model) { foreach ($_POST['PremiumAd']['p_categories'] as $categoryId) { $adCategory = new PremiumAdCategory(); $adCategory->premiumad_id = $model->premiumad_id; $adCategory->category_id = $categoryId; if (!$adCategory->save()) { return false; } } return true; }
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; }