public function setNextPosition() { $className = get_class($this); if (!is_integer(self::$nextPosition)) { $filter = new ARSelectFilter(); $filter->setCondition(new EqualsCond(new ARFieldHandle($className, 'productID'), $this->product->get()->getID())); $filter->setOrder(new ARFieldHandle($className, 'position'), ARSelectFilter::ORDER_DESC); $filter->setLimit(1); self::$nextPosition = 0; foreach (ActiveRecord::getRecordSet($className, $filter) as $relatedProductGroup) { self::$nextPosition = $relatedProductGroup->position->get(); } } $this->position->set(++self::$nextPosition); }
public function testInstanceMemoryUsage() { $f = new ARSelectFilter(); $f->setLimit(1000); ActiveRecord::getRecordSetArray('DiscountCondition', $f); $arrayMem = memory_get_usage(); $array = ActiveRecord::getRecordSetArray('DiscountCondition', $f); $arrayMem = memory_get_usage() - $arrayMem; echo count($arrayMem) . "\n"; echo $arrayMem . "\n"; $arraySet = memory_get_usage(); $array = ActiveRecord::getRecordSet('DiscountCondition', $f); $arraySet = memory_get_usage() - $arraySet; echo $arraySet . "\n"; }
public function testSerializeSpeed() { for ($k = 1; $k <= 10; $k++) { $record = ActiveRecord::getNewInstance('SerializedModel'); $record->setID($k); $record->name->set('some name ' . $k); $record->save(); } ActiveRecord::clearPool(); // fetch from database $fetchTime = microtime(true); $set = ActiveRecord::getRecordSet('SerializedModel', new ARSelectFilter()); $fetchTime = microtime(true) - $fetchTime; $serialized = serialize($set); ActiveRecord::clearPool(); // unserialize $serTime = microtime(true); $set = unserialize($serialized); $serTime = microtime(true) - $serTime; $this->assertTrue($serTime < $fetchTime); }
protected function insert() { // check currency symbol if (!$this->pricePrefix->get() && !$this->priceSuffix->get()) { $prefixes = (include ClassLoader::getRealPath('installdata.currency.signs') . '.php'); if (isset($prefixes[$this->getID()])) { $signs = $prefixes[$this->getID()]; $this->pricePrefix->set($signs[0]); if (isset($signs[1])) { $this->priceSuffix->set($signs[1]); } } } // check if default currency exists if (!ActiveRecord::getRecordSet('Currency', select(eq('Currency.isDefault', 1)))->getTotalRecordCount()) { $this->isDefault->set(true); $this->isEnabled->set(true); } $this->setLastPosition(); return parent::insert(); }
/** * Returns a set of category images * * @return ARSet */ public function getCategoryImagesSet() { ClassLoader::import('application.model.category.CategoryImage'); return ActiveRecord::getRecordSet('CategoryImage', $this->getCategoryImagesFilter()); }
private function getCurrencySet() { $filter = new ARSelectFilter(); $filter->setCondition(new NotEqualsCond(new ARFieldHandle("Currency", "isDefault"), 1)); $filter->setOrder(new ARFieldHandle("Currency", "isEnabled"), 'DESC'); $filter->setOrder(new ARFieldHandle("Currency", "position"), 'ASC'); return ActiveRecord::getRecordSet('Currency', $filter); }
protected function loadData() { $this->data = ActiveRecord::getRecordSet($this->table, $this->filter, $this->referencedRecords)->getData(); }
/** * Loads currency data from database */ private function loadCurrencyData() { $useCache = true; $cache = Currency::getCacheFile(); if (file_exists($cache) && $useCache) { $this->currencies = (include $cache); } else { $filter = new ArSelectFilter(); $filter->setCondition(new EqualsCond(new ArFieldHandle('Currency', 'isEnabled'), 1)); $filter->setOrder(new ArFieldHandle('Currency', 'position'), 'ASC'); $currencies = ActiveRecord::getRecordSet('Currency', $filter); $this->currencies = array(); foreach ($currencies as $currency) { $this->currencies[$currency->getID()] = $currency; } if ($useCache) { file_put_contents($cache, '<?php return unserialize(' . var_export(serialize($this->currencies), true) . '); ?>'); } } foreach ($this->currencies as $currency) { if ($currency->isDefault()) { $this->defaultCurrency = $currency; } } }
/** * Removes node from a category * * @role !category.remove */ public function remove() { try { $categoryID = $this->request->get("id"); $confirmed = $this->request->get("confirmed"); $category = Category::getInstanceByID($categoryID, true); if ($category->getActiveProductCount()) { if (!$confirmed) { return new JSONResponse(array('confirmMessage' => $this->translate('_confirm_remove_category_with_products'), 'url' => $this->application->getRouter()->createUrl(array('controller' => 'backend.category', 'action' => 'remove', 'id' => $categoryID, 'query' => array('confirmed' => 1)))), 'confirm'); } // merge categoryID with child category IDs $categoryIDs = array_merge(Category::getRecordSet($category->getBranchFilter())->getRecordIDs(), array($categoryID)); // all products under category that has additional categories $products = ActiveRecord::getRecordSet('Product', select(new AndChainCondition(array(IN(f('Product.categoryID'), $categoryIDs), new RegexpCond(f('Product.categoryIntervalCache'), '[0-9]+\\-[0-9]+\\,[0-9]+\\-[0-9]+'))))); // move to aditional category, that is not in categoryIDs foreach ($products as $product) { $chunks = explode(',', $product->categoryIntervalCache->get()); while ($pair = array_shift($chunks)) { $sequence = explode('-', $pair); if (!is_array($sequence) || count($sequence) != 2 || !is_numeric($sequence[0]) || !is_numeric($sequence[1])) { continue; } $categorySet = Category::getRecordSet(select(new AndChainCondition(array(eq(f('Category.lft'), $sequence[0]), eq(f('Category.rgt'), $sequence[1]))))); if ($categorySet->size() != 1) { continue; } $categoryToMove = $categorySet->shift(); if (in_array($categoryToMove->getID(), $categoryIDs)) { // child category also will be removed. cant move here continue; } $product->categoryID->set($categoryToMove); $product->save(); break; // product moved, don't care about other aditional categories. } } } // and delete category. $category->delete(); Category::recalculateProductsCount(); return new JSONResponse(false, 'success', $this->translate('_category_was_successfully_removed')); } catch (Exception $e) { return new JSONResponse(false, 'failure', $this->translate('_could_not_remove_category')); } }
protected function insert($foreignKeyName) { $className = get_class($this); // get current max image position $filter = new ARSelectFilter(); $filter->setCondition(new EqualsCond(new ARFieldHandle($className, $foreignKeyName), $this->getOwner()->getID())); $filter->setOrder(new ARFieldHandle($className, 'position'), 'DESC'); $filter->setLimit(1); $maxPosSet = ActiveRecord::getRecordSet($className, $filter); if ($maxPosSet->size() > 0) { $maxPos = $maxPosSet->get(0)->position->get() + 1; } else { $maxPos = 0; } $this->position->set($maxPos); return parent::insert(); }
public function status() { $status = array(); foreach (ActiveRecord::getRecordSet('ClonedStore', select()) as $store) { $f = new NetworkFetch('http://' . $store->domain->get() . '/storeSync/status'); $f->fetch(); $status[$store->getID()] = file_get_contents($f->getTmpFile()) == 'true'; } $status['ready'] = count($status) == count(array_filter($status)); return new JSONResponse($status); }
public function getFirstChild($loadReferencedRecords = false) { if (!$this->isLoaded()) { $this->load(); } $className = get_class($this); $filter = new ARSelectFilter(); $filter->setCondition(new EqualsCond(new ARFieldHandle($className, self::PARENT_NODE_FIELD_NAME), $this->getField(self::PARENT_NODE_FIELD_NAME)->get()->getID())); $filter->setOrder(new ArFieldHandle($className, self::LEFT_NODE_FIELD_NAME)); $filter->setLimit(1); $recordSet = ActiveRecord::getRecordSet($className, $filter, $loadReferencedRecords); foreach ($recordSet as $record) { return $record; } return null; }
private function getLanguages($active = 0) { $filter = new ARSelectFilter(); $filter->setOrder(new ARFieldHandle("Language", "position"), ARSelectFilter::ORDER_ASC); if ($active > 0) { $filter->setCondition(new EqualsCond(new ARFieldHandle("Language", "isEnabled"), $active == 1 ? 1 : 0)); } return ActiveRecord::getRecordSet("Language", $filter); }
private function importAdditionalCategories(CsvImportProfile $profile, Product $product, $extraCategories) { $product->deleteRelatedRecordSet('ProductCategory'); $instances = array(); if (is_array($extraCategories)) { foreach ($extraCategories as $names) { $instances[] = $this->getCategoryByPath($profile, $names); } } else { if ($extraCategories instanceof Condition) { $instances = ActiveRecord::getRecordSet('Category', select($extraCategories)); } } foreach ($instances as $cat) { ProductCategory::getNewInstance($product, $cat)->save(); } }