/** * @role update */ public function move() { $page = StaticPage::getInstanceById((int) $this->request->get('id'), StaticPage::LOAD_DATA); // update parent if ($this->request->get('parent')) { $parent = StaticPage::getInstanceById((int) $this->request->get('parent'), StaticPage::LOAD_DATA); } else { $parent = null; } $page->parent->set($parent); $page->save(); // update order $f = new ARUpdateFilter(); if ($parent) { $f->setCondition(eq(f('StaticPage.parentID'), $parent->getID())); } else { $f->setCondition(new IsNullCond(f('StaticPage.parentID'))); } $f->addModifier('StaticPage.position', new ARExpressionHandle('position+2')); if ($this->request->get('previous')) { $previous = StaticPage::getInstanceById((int) $this->request->get('previous'), StaticPage::LOAD_DATA); $position = $previous->position->get(); $f->mergeCondition(gt(f('StaticPage.position'), $position)); $page->position->set($position + 1); } else { $previous = null; $page->position->set(1); } ActiveRecordModel::updateRecordSet('StaticPage', $f); $page->save(); return new JSONResponse(array(), 'success', $this->translate('_pages_were_successfully_reordered')); }
/** * Save news entry order * @role sort * @return RawResponse */ public function saveOrder() { $order = array_reverse($this->request->get('typeList_' . $this->request->get('id'))); foreach ($order as $key => $value) { $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle('ProductRatingType', 'ID'), $value)); $update->addModifier('position', $key); ActiveRecord::updateRecordSet('ProductRatingType', $update); } return new RawResponse($this->request->get('draggedId')); }
public function saveOrder() { $order = $this->request->get('relatedCategories_' . $this->request->get('id')); foreach ($order as $key => $value) { $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle('CategoryRelationship', 'ID'), $value)); $update->addModifier('position', $key); ActiveRecord::updateRecordSet('CategoryRelationship', $update); } return new JSONResponse(false, 'success'); }
protected function insert() { $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('SearchLog', 'keywords'), $this->keywords->get())); $f->mergeCondition(new EqualsCond(new ARFieldHandle('SearchLog', 'ip'), $this->ip->get())); if (!ActiveRecordModel::getRecordCount(__CLASS__, $f)) { parent::insert(); $update = new ARUpdateFilter(); $update->addModifier('time', new ARExpressionHandle('NOW()')); $update->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'ID'), $this->getID())); ActiveRecordModel::updateRecordSet(__CLASS__, $update); } }
/** * Save news entry order * @role sort * @return RawResponse */ public function saveOrder() { $order = array_reverse($this->request->get('newsList')); foreach ($order as $key => $value) { $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle('NewsPost', 'ID'), $value)); $update->addModifier('position', $key); ActiveRecord::updateRecordSet('NewsPost', $update); } $resp = new RawResponse(); $resp->setContent($this->request->get('draggedId')); return $resp; }
public function updateCategoryCounters(ARUpdateFilter $catUpdate, Category $category) { if ($catUpdate->isModifierSet()) { $categoryPathNodes = $category->getPathNodeArray(Category::INCLUDE_ROOT_NODE); $catIDs = array(); foreach ($categoryPathNodes as $node) { $catIDs[] = $node['ID']; } $catIDs[] = $category->getID(); $catUpdate->setCondition(new INCond(new ARFieldHandle('Category', 'ID'), $catIDs)); ActiveRecordModel::updateRecordSet('Category', $catUpdate); } }
/** * Save image order * @return RawResponse */ public function saveOrder($order = null) { $ownerId = $this->request->get('ownerId'); if ($order === null) { $varName = array_shift(explode('_', $this->request->get('draggedID'))); $order = array_filter($this->request->get($varName . '_' . $ownerId), array($this, 'filterOrder')); $order = array_values($order); } foreach ($order as $key => $value) { $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle($this->getModelClass(), 'ID'), $value)); $update->addModifier('position', $key); ActiveRecord::updateRecordSet($this->getModelClass(), $update); } // set owners main image if (isset($order[0])) { $owner = ActiveRecordModel::getInstanceByID($this->getOwnerClass(), $ownerId); $owner->defaultImage->set(ActiveRecordModel::getInstanceByID($this->getModelClass(), $order[0])); $owner->save(); } $resp = new RawResponse(); $resp->setContent($this->request->get('draggedId')); return $resp; }
public function sortActions() { $order = $this->request->get('actionContainer_' . $this->request->get('conditionId')); foreach ($order as $key => $value) { $update = new ARUpdateFilter(); $update->setCondition(new EqualsCond(new ARFieldHandle('DiscountAction', 'ID'), $value)); $update->addModifier('position', $key); ActiveRecord::updateRecordSet('DiscountAction', $update); } $resp = new RawResponse(); $resp->setContent($this->request->get('draggedId')); return $resp; }
/** * @role mass */ public function processMass() { $filter = $this->getSelectFilter(); $act = $this->request->get('act'); $field = array_pop(explode('_', $act, 2)); if ('move' == $act) { new ActiveGrid($this->application, $filter, $this->getClassName()); $cat = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); $update = new ARUpdateFilter(); $update->setCondition($filter->getCondition()); $update->addModifier('Product.categoryID', $cat->getID()); $update->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID'); ActiveRecord::beginTransaction(); ActiveRecord::updateRecordSet('Product', $update, Product::LOAD_REFERENCES); Category::recalculateProductsCount(); ActiveRecord::commit(); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_move_succeeded')); } // remove design themes if ('theme' == $act && !$this->request->get('theme')) { ClassLoader::import('application.model.presentation.CategoryPresentation'); ActiveRecord::deleteRecordSet('CategoryPresentation', new ARDeleteFilter($filter->getCondition()), null, array('Product', 'Category')); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_themes_removed')); } $params = array(); if ('manufacturer' == $act) { $params['manufacturer'] = Manufacturer::getInstanceByName($this->request->get('manufacturer')); } else { if ('price' == $act || 'inc_price' == $act) { $params['baseCurrency'] = $this->application->getDefaultCurrencyCode(); $params['price'] = $this->request->get($act); $params['currencies'] = $this->application->getCurrencySet(); $params['inc_price_value'] = $this->request->get('inc_price_value'); $params['inc_quant_price'] = $this->request->get('inc_quant_price'); } else { if ('addRelated' == $act) { $params['relatedProduct'] = Product::getInstanceBySKU($this->request->get('related')); if (!$params['relatedProduct']) { return new JSONResponse(0); } } else { if ($this->request->get('categoryID')) { $params['category'] = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); } else { if ('theme' == $act) { ClassLoader::import('application.model.presentation.CategoryPresentation'); $params['theme'] = $this->request->get('theme'); } else { if ('shippingClass' == $act) { $params['shippingClass'] = $this->request->get('shippingClass'); } else { if ('taxClass' == $act) { $params['taxClass'] = $this->request->get('taxClass'); } } } } } } } $response = parent::processMass($params); if ($this->request->get('categoryID')) { Category::recalculateProductsCount(); } return $response; }
public function cancelFurtherRebills() { return; $id = $this->getID(); $userID = $this->userID->get()->getID(); $update = new ARUpdateFilter(); $update->setCondition(new OrChainCondition(array(new AndChainCondition(array(new EqualsCond(new ARFieldHandle('CustomerOrder', 'ID'), $id), new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userID))), new AndChainCondition(array(new EqualsCond(new ARFieldHandle('CustomerOrder', 'parentID'), $id), new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userID)))))); $update->addModifier('rebillsLeft', '0'); ActiveRecord::updateRecordSet('CustomerOrder', $update); }
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; }