public static function deleteByID($className, $id, $foreignKeyName) { $inst = ActiveRecordModel::getInstanceById($className, $id, ActiveRecordModel::LOAD_DATA); $inst->getOwner()->load(); $inst->deleteImageFiles(); // check if main image is being deleted $owner = $inst->getOwner(); $owner->load(array(get_class($inst))); if ($owner->defaultImage->get()->getID() == $id) { // set next image (by position) as the main image $f = new ARSelectFilter(); $cond = new EqualsCond(new ARFieldHandle(get_class($inst), $foreignKeyName), $owner->getID()); $cond->addAND(new NotEqualsCond(new ARFieldHandle(get_class($inst), 'ID'), $inst->getID())); $f->setCondition($cond); $f->setOrder(new ARFieldHandle(get_class($inst), 'position')); $f->setLimit(1); $newDefaultImage = ActiveRecordModel::getRecordSet(get_class($inst), $f); if ($newDefaultImage->size() > 0) { $owner->defaultImage->set($newDefaultImage->get(0)); $owner->save(); } } return parent::deleteByID($className, $id); }
/** * Removes a product from a database * * @param int $recordID * @return bool * @throws Exception */ public static function deleteByID($recordID) { ActiveRecordModel::beginTransaction(); try { $product = Product::getInstanceByID($recordID, Product::LOAD_DATA); $filter = $product->getCountUpdateFilter(true); if ($product->category->get()) { $product->updateCategoryCounters($filter, $product->category->get()); } foreach ($product->getAdditionalCategories() as $category) { $product->updateCategoryCounters($filter, $category); } parent::deleteByID(__CLASS__, $recordID); ActiveRecordModel::commit(); return true; } catch (Exception $e) { ActiveRecordModel::rollback(); throw $e; } }
/** * Delete filter group from database by id * * @param integer $id * @return boolean */ public static function deletebyID($id) { return parent::deleteByID(__CLASS__, $id); }
/** * Removes an option choice from database * * @param int $recordID * @return bool * @throws Exception */ public static function deleteByID($recordID) { return parent::deleteByID(__CLASS__, $recordID); }
/** * Delete Filter from database */ public static function deleteByID($id) { parent::deleteByID(__CLASS__, (int) $id); }