Example #1
0
 /**
  * @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'));
 }
 private function updateConditionRecordCount($increase = true)
 {
     BusinessRuleController::clearCache();
     $update = new ARUpdateFilter();
     $update->addModifier('recordCount', new ARExpressionHandle('recordCount' . ($increase ? '+' : '-') . '1'));
     $this->condition->get()->updateRecord($update);
     $this->condition->get()->reload();
 }
Example #3
0
 protected function update()
 {
     self::beginTransaction();
     $ratingDiff = $this->rating->get() - $this->rating->getInitialValue();
     $f = new ARUpdateFilter();
     $f->addModifier('ratingSum', new ARExpressionHandle('ratingSum+(' . $ratingDiff . ')'));
     $f->addModifier('rating', new ARExpressionHandle('ratingSum/ratingCount'));
     $this->updateRatings($f);
     parent::update();
     self::commit();
 }
 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');
 }
Example #5
0
 /**
  * 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'));
 }
Example #6
0
 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);
     }
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 public function process()
 {
     if (ActiveRecordModel::getApplication()->getConfig()->get('CLONE_STORE_TYPE') == 'CLONE_STORE_MASTER') {
         return;
     }
     if (!ClonedStoreUpdater::isTableSynced(get_class($this->object))) {
         return;
     }
     $protectedFields = array();
     foreach ($this->object->getSchema()->getFieldList() as $fieldName => $field) {
         $val = $this->object->getFieldValue($fieldName);
         $isModified = $this->object->getField($fieldName)->isModified();
         if ($isModified && $val) {
             if (is_array($val)) {
                 // empty serialized array
                 if (!array_filter($val)) {
                     continue;
                 }
                 $initial = $this->object->getField($fieldName)->getInitialValue();
                 if (is_array($initial)) {
                     foreach ($val as $key => $value) {
                         $val[$key] = strip_tags($value);
                     }
                     foreach ($initial as $key => $value) {
                         $initial[$key] = strip_tags($value);
                     }
                     if (!array_diff($val, $initial)) {
                         continue;
                     }
                 }
             }
             $protectedFields[] = $fieldName;
         }
     }
     if ('SpecificationStringValue' == get_class($this->object) && $this->object->value->isModified()) {
         $protectedFields[] = 'value';
     }
     if (!$protectedFields) {
         return;
     }
     $f = new ARUpdateFilter();
     foreach ($protectedFields as $key => $field) {
         $f->addModifier('protectedFields' . str_repeat(' ', $key), new ARExpressionHandle('IF(LOCATE("|' . $field . '|", protectedFields) > 0, protectedFields, CONCAT(COALESCE(protectedFields, ""), "|' . $field . '|"))'));
     }
     $this->object->updateFilter = $f;
 }
Example #9
0
 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);
     }
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 private function updateProductCounter($increase = true)
 {
     $update = new ARUpdateFilter();
     $update->addModifier('reviewCount', new ARExpressionHandle('reviewCount ' . ($increase ? '+' : '-') . ' 1'));
     $this->product->get()->updateRecord($update);
 }
Example #12
0
 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;
 }
Example #13
0
 /**
  * @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;
 }
Example #14
0
 public function getNextCurrency()
 {
     if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'currency_types ORDER BY sort_order ASC'))) {
         return null;
     }
     if (!($currency = ActiveRecordModel::getInstanceByIDIfExists('Currency', $data['currency_iso_3'], false))) {
         $currency = Currency::getNewInstance($data['currency_iso_3']);
         $currency->rate->set($data['currency_value']);
     }
     $currency->isEnabled->set(true);
     if ($this->getConfigValue('CONF_DEFAULT_CURRENCY') == $data['CID']) {
         $f = new ARUpdateFilter();
         $f->addModifier('Currency.isDefault', 0);
         ActiveRecordModel::updateRecordSet('Currency', $f);
         $currency->isDefault->set(true);
     }
     return $currency;
 }
Example #15
0
 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;
 }
Example #16
0
 public function disableRecords(ARSelectFilter $filter)
 {
     if ($disable = $this->getDisableFieldHandle()) {
         $update = new ARUpdateFilter($filter->getCondition());
         $update->addModifier($disable->toString(), 0);
         ActiveRecordModel::updateRecordSet($this->className, $update, $this->getReferencedData());
     }
 }
Example #17
0
 public function updateRecord(ARUpdateFilter $filter)
 {
     $filter->mergeCondition($this->getRecordIDCondition());
     $updateQuery = "UPDATE " . $this->schema->getName() . $filter->createString();
     $res = $this->executeUpdate($updateQuery);
     $this->reload();
     return $res;
 }
Example #18
0
 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);
 }
Example #19
0
File: User.php Project: saiber/www
 public function invalidateSessionCache()
 {
     if ($this->isAnonymous()) {
         return;
     }
     $f = new ARUpdateFilter(eq(f('SessionData.userID'), $this->getID()));
     $f->addModifier('cacheUpdated', 0);
     self::updateRecordSet('SessionData', $f);
 }
Example #20
0
 /**
  *
  * @todo fix potential bug: when using $this->load() in method, it might
  * overwrite the data that was set during runtime
  */
 protected function update()
 {
     ActiveRecordModel::beginTransaction();
     try {
         parent::update();
         $activeProductCount = $this->activeProductCount->get();
         if ($this->isEnabled->isModified()) {
             if ($this->isEnabled()) {
                 $activeProductCountUpdateStr = "activeProductCount + " . $activeProductCount;
             } else {
                 $activeProductCountUpdateStr = "activeProductCount - " . $activeProductCount;
             }
             $pathNodes = $this->getPathNodeSet(true);
             foreach ($pathNodes as $node) {
                 if ($node->getID() != $this->getID()) {
                     $f = new ARUpdateFilter();
                     $f->addModifier('activeProductCount', new ARExpressionHandle($activeProductCountUpdateStr));
                     $node->updateRecord($f);
                 }
             }
         }
         ActiveRecordModel::commit();
     } catch (Exception $e) {
         ActiveRecordModel::rollback();
         throw $e;
     }
 }
Example #21
0
 public function setSingleAddress()
 {
     $f = new ARUpdateFilter(new EqualsCond(new ARFieldHandle('OrderedItem', 'customerOrderID'), $this->order->getID()));
     $f->addModifier('OrderedItem.shipmentID', new ARExpressionHandle('NULL'));
     ActiveRecordModel::updateRecordSet('OrderedItem', $f);
     $this->order->isMultiAddress->set(false);
     $this->order->loadAll();
     $this->order->mergeItems();
     $this->order->resetShipments();
     SessionOrder::save($this->order);
     $this->order->deleteRelatedRecordSet('Shipment');
     return new ActionRedirectResponse('order', 'index');
 }
Example #22
0
 /**
  * Sets default language.
  * @role status
  * @return ActionRedirectResponse
  */
 public function setDefault()
 {
     try {
         $r = ActiveRecord::getInstanceByID('Language', $this->request->get('id'), true);
     } catch (ARNotFoundException $e) {
         return new RawResponse(0);
     }
     ActiveRecord::beginTransaction();
     $update = new ARUpdateFilter();
     $update->addModifier('isDefault', 0);
     ActiveRecord::updateRecordSet('Language', $update);
     $r->setAsDefault(true);
     $r->save();
     ActiveRecord::commit();
     return new ActionRedirectResponse('backend.language', 'index');
 }