public static function deleteById($id) { self::deleteCache(); // make sure the language record exists $inst = ActiveRecord::getInstanceById('Language', $id, true); // make sure it's not the default currency if (true != $inst->isDefault->get()) { ActiveRecord::deleteByID('Language', $id); return true; } else { return false; } }
/** * Sets specification attribute value by mapping product, specification field, and * assigned value to one record (atomic item) * * @param iEavSpecification $specification Specification item value */ public function setAttribute(iEavSpecification $newSpecification) { $specField = $newSpecification->getFieldInstance(); $itemClass = $specField->getSelectValueClass(); if ($this->owner->isExistingRecord() && isset($this->attributes[$newSpecification->getFieldInstance()->getID()]) && ($itemClass == $specField->getSpecificationFieldClass() && $newSpecification->getValue()->isModified())) { // Delete old value ActiveRecord::deleteByID($itemClass, $this->attributes[$specField->getID()]->getID()); // And create new $this->attributes[$specField->getID()] = call_user_func_array(array($itemClass, 'getNewInstance'), array($this->owner, $specField, $newSpecification->getValue()->get())); } else { $this->attributes[$specField->getID()] = $newSpecification; } unset($this->removedAttributes[$specField->getID()]); }
public static function registerLastViewed($item, $instance = null) { $item['position'] = time(); $filter = new ARSelectFilter(); foreach (array('menuID', 'productID', 'userID', 'orderID') as $fieldName) { if (array_key_exists($fieldName, $item)) { $filter->setCondition(eq(f(__CLASS__ . '.' . $fieldName), $item[$fieldName])); break; // should have only one identificator. } } $items = self::getUserToolbarItems(null, $filter); if (count($items) > 0) { // update postion to $item['position'] for first found existing record $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'ID'), $items[0]['ID'])); $update->addModifier('position', $item['position']); ActiveRecord::updateRecordSet(__CLASS__, $update); } else { // create new self::getNewInstance($item)->save(); } $filter = new ARSelectFilter(); $filter->setLimit(999, BackendToolbarItem::LAST_VIEWED_COUNT); $items = self::getUserToolbarItems(array(BackendToolbarItem::TYPE_PRODUCT, BackendToolbarItem::TYPE_USER, BackendToolbarItem::TYPE_ORDER), $filter, 'DESC'); if (count($items) > 0) { foreach ($items as $item) { ActiveRecord::deleteByID(__CLASS__, $item['ID']); } } return true; }