コード例 #1
0
ファイル: Manufacturer.php プロジェクト: saiber/livecart
 /**
  *
  * @return array('manufacturers'=> array of manufacturers, 'counts'=> manufacturer product count, 'count'=> count of manufacturers)
  */
 public static function getActiveProductManufacturers($context)
 {
     $context = $context + array('startingWith' => null, 'currentPage' => 1);
     extract($context);
     // creates $startingWith and $currentPage
     $config = ActiveRecordModel::getApplication()->getConfig();
     $listStyle = $config->get('MANUFACTURER_PAGE_LIST_STYLE');
     $perPage = $config->get('MANUFACTURER_PAGE_PER_PAGE');
     // get filter to select manufacturers of active products only
     $f = new ARSelectFilter();
     $ids = $counts = $letters = array();
     $sql = !self::getApplication()->getConfig()->get('MANUFACTURER_PAGE_DISPLAY_ACTIVE') ? 'SELECT DISTINCT(ID) as manufacturerID, 1 AS cnt FROM Manufacturer ' . $f->createString() . ' GROUP BY manufacturerID' : 'SELECT DISTINCT(manufacturerID), COUNT(*) AS cnt FROM Product ' . $f->createString() . ' GROUP BY manufacturerID';
     foreach (ActiveRecordModel::getDataBySQL($sql) as $row) {
         $ids[] = $row['manufacturerID'];
         $counts[$row['manufacturerID']] = $row['cnt'];
     }
     $f = new ARSelectFilter(new InCond(new ARFieldHandle('Manufacturer', 'ID'), $ids));
     $f->addField('UPPER(LEFT(TRIM(Manufacturer.name),1))', '', 'FirstLetter');
     $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
     if ($startingWith) {
         $f->mergeCondition(new LikeCond(new ARFieldHandle('Manufacturer', 'name'), $startingWith . '%'));
     }
     $f->setOrder(new ARFieldHandle('Manufacturer', 'name'));
     if ($perPage > 0) {
         $offsetStart = ($currentPage - 1) * $perPage + 1;
         $offsetEnd = $currentPage * $perPage;
         $f->setLimit($perPage, $offsetStart - 1);
     }
     $manufacturers = ActiveRecordModel::getRecordSetArray(__CLASS__, $f);
     foreach ($manufacturers as $item) {
         $letters[$item['FirstLetter']] = $item['FirstLetter'];
     }
     return array('manufacturers' => $manufacturers, 'counts' => $counts, 'count' => ActiveRecordModel::getRecordCount(__CLASS__, $f));
 }
コード例 #2
0
ファイル: StaticPageController.php プロジェクト: saiber/www
 /**
  * Reorder pages
  *
  * @role sort
  */
 public function reorder()
 {
     $inst = StaticPage::getInstanceById($this->request->get('id'), StaticPage::LOAD_DATA);
     $f = new ARSelectFilter();
     $handle = new ARFieldHandle('StaticPage', 'position');
     if ('down' == $this->request->get('order')) {
         $f->setCondition(new MoreThanCond($handle, $inst->position->get()));
         $f->setOrder($handle, 'ASC');
     } else {
         $f->setCondition(new LessThanCond($handle, $inst->position->get()));
         $f->setOrder($handle, 'DESC');
     }
     $f->setLimit(1);
     $s = ActiveRecordModel::getRecordSet('StaticPage', $f);
     if ($s->size()) {
         $pos = $inst->position->get();
         $replace = $s->get(0);
         $inst->position->set($replace->position->get());
         $replace->position->set($pos);
         $inst->save();
         $replace->save();
         return new JSONResponse(array('id' => $inst->getID(), 'order' => $this->request->get('order')), 'success');
     } else {
         return new JSONResponse(false, 'failure', $this->translate('_could_not_reorder_pages'));
     }
 }
コード例 #3
0
ファイル: ProductRatingType.php プロジェクト: saiber/www
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle(__CLASS__, 'categoryID'), $this->getCategory()->getID()));
     $f->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(get_class($this), $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 1;
     $this->position->set($position);
     return parent::insert();
 }
コード例 #4
0
ファイル: Manufacturer.php プロジェクト: saiber/www
 public static function getInstanceByName($name)
 {
     $filter = new ARSelectFilter();
     $filter->setCondition(new EqualsCond(new ARFieldHandle('Manufacturer', 'name'), $name));
     $filter->setLimit(1);
     $set = ActiveRecordModel::getRecordSet('Manufacturer', $filter);
     if ($set->size() > 0) {
         return $set->get(0);
     } else {
         return self::getNewInstance($name);
     }
 }
コード例 #5
0
ファイル: SessionOrder.php プロジェクト: saiber/livecart
 /**
  * Get CustomerOrder instance from session
  *
  * @return CustomerOrder
  */
 public static function getOrder()
 {
     if (self::$instance) {
         return self::$instance;
     }
     $session = new Session();
     $id = $session->get('CustomerOrder');
     if ($id) {
         try {
             $instance = CustomerOrder::getInstanceById($id, true);
             if (!$instance->getOrderedItems()) {
                 $instance->loadItems();
             }
             $instance->isSyncedToSession = true;
         } catch (ARNotFoundException $e) {
             unset($instance);
         }
     }
     if (!isset($instance)) {
         $userId = SessionUser::getUser()->getID();
         // get the last unfinalized order by this user
         if ($userId > 0) {
             $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userId));
             $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
             $f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
             $f->setLimit(1);
             $orders = ActiveRecordModel::getRecordSet('CustomerOrder', $f);
             if ($orders->size()) {
                 $instance = $orders->get(0);
             }
         }
     }
     if (!isset($instance)) {
         $instance = CustomerOrder::getNewInstance(User::getNewInstance(0));
         $instance->user->set(NULL);
     }
     if (!$instance->user->get() && SessionUser::getUser()->getID() > 0) {
         $instance->setUser(SessionUser::getUser());
         $instance->save();
     }
     if ($instance->isFinalized->get()) {
         $session->unsetValue('CustomerOrder');
         return self::getOrder();
     }
     // fixes issue when trying to add OrderedItem to unsaved(without ID) CustomerOrder.
     // ~ but i don't know if returning unsaved CustomerOrder is expected behaviour.
     if ($instance->isExistingRecord() == false) {
         $instance->save(true);
     }
     self::setOrder($instance);
     return $instance;
 }
コード例 #6
0
ファイル: IndexController.php プロジェクト: saiber/www
 public function index()
 {
     ClassLoader::import('application.controller.CategoryController');
     $this->request->set('id', Category::ROOT_ID);
     $this->request->set('cathandle', '-');
     $response = parent::index();
     // load site news
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     $f->setLimit($this->config->get('NUM_NEWS_INDEX') + 1);
     $news = ActiveRecordModel::getRecordSetArray('NewsPost', $f);
     $response->set('news', $news);
     $response->set('isNewsArchive', count($news) > $this->config->get('NUM_NEWS_INDEX'));
     return $response;
 }
コード例 #7
0
ファイル: ProductParametersGroup.php プロジェクト: saiber/www
 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);
 }
コード例 #8
0
ファイル: MemoryUsageTest.php プロジェクト: saiber/www
 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";
 }
コード例 #9
0
 public function autoComplete()
 {
     $f = new ARSelectFilter();
     $f->setLimit(20);
     $resp = array();
     $field = $this->request->get('field');
     if ('specField_' == substr($field, 0, 10)) {
         list($foo, $id) = explode('_', $field);
         $handle = new ARFieldHandle('EavStringValue', 'value');
         $locale = $this->locale->getLocaleCode();
         $searchHandle = MultilingualObject::getLangSearchHandle($handle, $locale);
         $f->setCondition(new EqualsCond(new ARFieldHandle('EavStringValue', 'fieldID'), $id));
         $f->mergeCondition(new LikeCond($handle, '%:"' . $this->request->get($field) . '%'));
         $f->mergeCondition(new LikeCond($searchHandle, $this->request->get($field) . '%'));
         $f->setOrder($searchHandle, 'ASC');
         $results = ActiveRecordModel::getRecordSet('EavStringValue', $f);
         foreach ($results as $value) {
             $resp[$value->getValueByLang('value', $locale, MultilingualObject::NO_DEFAULT_VALUE)] = true;
         }
         $resp = array_keys($resp);
     }
     return new AutoCompleteResponse($resp);
 }
コード例 #10
0
ファイル: ProductController.php プロジェクト: saiber/www
 private function isPurchaseRequiredToRate(Product $product)
 {
     if ($this->config->get('REQUIRE_PURCHASE_TO_RATE')) {
         if ($this->user->isAnonymous()) {
             return true;
         }
         if (is_null($this->isPurchaseRequiredToRate)) {
             ClassLoader::import('application.model.order.CustomerOrder');
             $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()));
             $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderedItem', 'productID'), $product->getID()));
             $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1));
             $f->setLimit(1);
             $this->isPurchaseRequiredToRate = ActiveRecordModel::getRecordCount('OrderedItem', $f, array('CustomerOrder')) < 1;
         }
         return $this->isPurchaseRequiredToRate;
     }
 }
コード例 #11
0
ファイル: ProductController.php プロジェクト: saiber/www
 public function autoComplete()
 {
     $f = new ARSelectFilter();
     $f->setLimit(20);
     $resp = array();
     $field = $this->request->get('field');
     if (in_array($field, array('sku', 'URL', 'keywords'))) {
         $c = new LikeCond(new ARFieldHandle('Product', $field), $this->request->get($field) . '%');
         $f->setCondition($c);
         $f->setOrder(new ARFieldHandle('Product', $field), 'ASC');
         $query = new ARSelectQueryBuilder();
         $query->setFilter($f);
         $query->includeTable('Product');
         $query->addField('DISTINCT(Product.' . $field . ')');
         $results = ActiveRecordModel::getDataBySQL($query->createString());
         foreach ($results as $value) {
             $resp[] = $value[$field];
         }
     } else {
         if ('name' == $field) {
             $c = new LikeCond(new ARFieldHandle('Product', $field), '%:"' . $this->request->get($field) . '%');
             $f->setCondition($c);
             $locale = $this->locale->getLocaleCode();
             $langCond = new LikeCond(Product::getLangSearchHandle(new ARFieldHandle('Product', 'name'), $locale), $this->request->get($field) . '%');
             $c->addAND($langCond);
             $f->setOrder(Product::getLangSearchHandle(new ARFieldHandle('Product', 'name'), $locale), 'ASC');
             $results = ActiveRecordModel::getRecordSet('Product', $f);
             foreach ($results as $value) {
                 $resp[$value->getValueByLang('name', $locale, Product::NO_DEFAULT_VALUE)] = true;
             }
             $resp = array_keys($resp);
         } else {
             if ('specField_' == substr($field, 0, 10)) {
                 list($foo, $id) = explode('_', $field);
                 $handle = new ARFieldHandle('SpecificationStringValue', 'value');
                 $locale = $this->locale->getLocaleCode();
                 $searchHandle = MultiLingualObject::getLangSearchHandle($handle, $locale);
                 $f->setCondition(new EqualsCond(new ARFieldHandle('SpecificationStringValue', 'specFieldID'), $id));
                 $f->mergeCondition(new LikeCond($handle, '%:"' . $this->request->get($field) . '%'));
                 $f->mergeCondition(new LikeCond($searchHandle, $this->request->get($field) . '%'));
                 $f->setOrder($searchHandle, 'ASC');
                 $results = ActiveRecordModel::getRecordSet('SpecificationStringValue', $f);
                 foreach ($results as $value) {
                     $resp[$value->getValueByLang('value', $locale, Product::NO_DEFAULT_VALUE)] = true;
                 }
                 $resp = array_keys($resp);
             }
         }
     }
     return new AutoCompleteResponse($resp);
 }
コード例 #12
0
ファイル: EavValueCommon.php プロジェクト: saiber/livecart
 protected function insert()
 {
     // get current max position
     if (!$this->position->get()) {
         $filter = new ARSelectFilter();
         $cond = new EqualsCond(new ARFieldHandle(get_class($this), $this->getFieldIDColumnName()), $this->getField()->get()->getID());
         $filter->setCondition($cond);
         $filter->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
         $filter->setLimit(1);
         $res = ActiveRecordModel::getRecordSet(get_class($this), $filter);
         if ($res->size() > 0) {
             $item = $res->get(0);
             $pos = $item->position->get() + 1;
         } else {
             $pos = 0;
         }
         $this->position->set($pos);
     }
     return parent::insert();
 }
コード例 #13
0
ファイル: UserController.php プロジェクト: GregerA/livecart
 private function mergeOrder()
 {
     // load the last un-finalized order by this user
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()));
     $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'dateCreated'), 'DESC');
     $f->setLimit(1);
     $s = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
     if (!$this->order->user->get() || $this->order->user->get()->getID() == $this->user->getID()) {
         if ($s->size()) {
             $order = $s->get(0);
             if ($this->order->getID() != $order->getID()) {
                 $sessionOrder = SessionOrder::getOrder();
                 $order->loadItems();
                 $order->merge($sessionOrder);
                 $order->save();
                 SessionOrder::setOrder($order);
                 $this->order->delete();
             }
         } else {
             if ($this->order->getID()) {
                 $this->order->setUser($this->user);
                 SessionOrder::save($this->order);
             }
         }
     }
 }
コード例 #14
0
ファイル: SitemapController.php プロジェクト: saiber/www
 private function getPage($class, $page, ARSelectFilter $f, $fields)
 {
     $f->setLimit(self::MAX_URLS, $page * self::MAX_URLS);
     $query = new ARSelectQueryBuilder();
     $query->setFilter($f);
     $query->includeTable($class);
     foreach ($fields as $field) {
         $query->addField($field);
     }
     return ActiveRecord::fetchDataFromDB($query);
 }
コード例 #15
0
ファイル: State.php プロジェクト: saiber/livecart
 /**
  * Provides an additional verification that state belongs to the particular country
  *
  * @return ActiveRecord
  */
 public static function getStateByIDAndCountry($stateID, $countryID)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('State', 'ID'), $stateID));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('State', 'countryID'), $countryID));
     $f->setLimit(1);
     $states = ActiveRecordModel::getRecordSet('State', $f);
     if ($states) {
         return $states->get(0);
     } else {
         return null;
     }
 }
コード例 #16
0
ファイル: Product.php プロジェクト: saiber/livecart
 public function getDefaultRecurringProductPeriod()
 {
     $filter = new ARSelectFilter();
     $filter->setLimit(1);
     $rs = RecurringProductPeriod::getRecordSetByProduct($this, $filter);
     if ($rs->size() == 0) {
         return null;
     }
     return $rs->shift();
 }
コード例 #17
0
ファイル: ObjectImage.php プロジェクト: saiber/www
 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();
 }
コード例 #18
0
ファイル: DataImport.php プロジェクト: saiber/livecart
 protected function importAttributes(ActiveRecordModel $instance, $record, $fields, $attrIdentifier = 'eavField')
 {
     if (isset($fields[$attrIdentifier])) {
         $impReq = new Request();
         $fieldClass = ucfirst($attrIdentifier);
         $valueClass = 'eavField' == $attrIdentifier ? 'EavValue' : $fieldClass . 'Value';
         foreach ($fields[$attrIdentifier] as $specFieldID => $csvIndex) {
             if (empty($record[$csvIndex])) {
                 continue;
             }
             $attr = ActiveRecordModel::getInstanceByID($fieldClass, $specFieldID, ActiveRecord::LOAD_DATA);
             if ($attr->isSimpleNumbers()) {
                 $impReq->set($attr->getFormFieldName(), (double) $record[$csvIndex]);
             } else {
                 if ($attr->isSelector()) {
                     if ($attr->isMultiValue->get()) {
                         $values = explode(',', $record[$csvIndex]);
                     } else {
                         $values = array($record[$csvIndex]);
                     }
                     foreach ($values as $fieldValue) {
                         $fieldValue = trim($fieldValue);
                         $f = new ARSelectFilter(new LikeCond(MultilingualObject::getLangSearchHandle(new ARFieldHandle($valueClass, 'value'), $this->application->getDefaultLanguageCode()), $fieldValue . '%'));
                         $f->setLimit(1);
                         if (!($value = $attr->getRelatedRecordSet($valueClass, $f)->shift())) {
                             $value = call_user_func_array(array($valueClass, 'getNewInstance'), array($attr));
                             if ($attr->type->get() == EavFieldCommon::TYPE_NUMBERS_SELECTOR) {
                                 $value->value->set($fieldValue);
                             } else {
                                 $value->setValueByLang('value', $this->application->getDefaultLanguageCode(), $fieldValue);
                             }
                             $value->save();
                         }
                         if (!$attr->isMultiValue->get()) {
                             $impReq->set($attr->getFormFieldName(), $value->getID());
                         } else {
                             $impReq->set($value->getFormFieldName(), true);
                         }
                     }
                 } else {
                     $impReq->set($attr->getFormFieldName(), $record[$csvIndex]);
                 }
             }
         }
         $instance->loadRequestData($impReq);
         $instance->save();
     }
 }
コード例 #19
0
ファイル: LiveCartImporter.php プロジェクト: saiber/livecart
 private function getIdOffsets()
 {
     $file = $this->getOffsetsFile();
     if (!file_exists($file)) {
         $offsets = array();
         $types = $this->getRecordTypes();
         unset($types[array_search('Language', $types)]);
         unset($types[array_search('ProductRelationship', $types)]);
         foreach ($types as $type) {
             $f = new ARSelectFilter();
             $f->setOrder(new ARFieldHandle($type, 'ID'), 'DESC');
             $f->setLimit(1);
             $record = array_shift(ActiveRecordModel::getRecordSetArray($type, $f));
             if (!$record) {
                 $record['ID'] = 0;
             }
             $offsets[$type] = $record['ID'];
             try {
                 ActiveRecordModel::executeUpdate('ALTER TABLE ' . $type . ' AUTO_INCREMENT = ' . ($offsets[$type] + 1));
             } catch (Exception $e) {
                 // we don't care much if it didn't work (won't work with MySQL <5.0.3)
             }
         }
         file_put_contents($file, '<?php return ' . var_export($offsets, true) . '; ?>');
     }
     return include $file;
 }
コード例 #20
0
ClassLoader::import('application.LiveCart');
$application = new LiveCart();
define('BUFFER', 50);
ClassLoader::import('application.model.product.Product');
$languages = $application->getLanguageArray();
$default = $application->getDefaultLanguageCode();
if (!$languages) {
    die('No additional languages enabled');
}
$count = ActiveRecordModel::getRecordCount('Product', new ARSelectFilter());
$parts = ceil($count / BUFFER);
$fields = array('name', 'shortDescription', 'longDescription');
ActiveRecordModel::beginTransaction();
for ($k = 0; $k < $parts; $k++) {
    $filter = new ARSelectFilter();
    $filter->setLimit(BUFFER, BUFFER * $k);
    $filter->setOrder(new ARFieldHandle('Product', 'ID'));
    $products = ActiveRecordModel::getRecordSet('Product', $filter);
    foreach ($products as $product) {
        foreach ($fields as $field) {
            if (!$product->getValueByLang($field, $default)) {
                foreach ($languages as $lang) {
                    if ($value = $product->getValueByLang($field, $lang)) {
                        $product->setValueByLang($field, $default, $value);
                        break;
                    }
                }
            }
        }
        $product->save();
    }
コード例 #21
0
ファイル: ProductBundle.php プロジェクト: saiber/www
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter(self::getFilter($this->product->get())->getCondition());
     $f->setOrder(new ARFieldHandle(__CLASS__, "position"), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(__CLASS__, $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 0;
     $this->position->set($position);
     return parent::insert();
 }
コード例 #22
0
ファイル: ApiReader.php プロジェクト: saiber/www
 public function getARSelectFilter($ormClassName)
 {
     $list = $this->getValidSearchFields($ormClassName);
     $arsf = new ARSelectFilter();
     $filterKeys = array_keys($list);
     foreach (array('//filter/', '//list/') as $xpathPrefix) {
         foreach ($filterKeys as $key) {
             $data = $this->xml->xpath($xpathPrefix . $key);
             while (count($data) > 0) {
                 $value = (string) array_shift($data);
                 $arsf->mergeCondition(new $list[$key][self::AR_CONDITION]($list[$key][self::AR_FIELD_HANDLE], $this->sanitizeFilterField($key, $value)));
             }
         }
     }
     $limit = $this->getActionAtribute('limit', 999999999999999999);
     // mysql does not have offset, should use limit <offset>, <some large number>
     if ($limit > -1) {
         $arsf->setLimit($limit, (int) $this->getActionAtribute('offset', 0));
     }
     return $arsf;
 }
コード例 #23
0
ファイル: StaticPage.php プロジェクト: saiber/livecart
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray('StaticPage', $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 1;
     $this->position->set($position);
     return parent::insert();
 }
コード例 #24
0
ファイル: User.php プロジェクト: saiber/livecart
 public function hasPendingInvoices()
 {
     $filter = new ARSelectFilter();
     $filter->setCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), 0));
     $filter->setLimit(1);
     return (bool) $this->countInvoices($filter);
 }
コード例 #25
0
ファイル: FrontendController.php プロジェクト: saiber/www
 public function latestNewsBlock()
 {
     $this->application->logStat('Starting latestNewsBlock');
     ClassLoader::import('application.model.sitenews.NewsPost');
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     $f->setLimit($this->config->get('NUM_NEWS_INDEX') + 1);
     $this->application->logStat('Before fetching news from DB');
     $news = array();
     $news = ActiveRecordModel::getRecordSetArray('NewsPost', $f);
     $this->application->logStat('Fetched news from DB');
     $response = new BlockResponse('news', $news);
     $response->set('isNewsArchive', count($news) > $this->config->get('NUM_NEWS_INDEX'));
     $this->application->logStat('Finished latestNewsBlock');
     return $response;
 }
コード例 #26
0
ファイル: ProductImport.php プロジェクト: GregerA/livecart
 private function getVariationTypeByIndex(Product $product, $index)
 {
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('ProductVariationType', 'position'));
     $f->setLimit(1, $index - 1);
     if ($product->getID()) {
         $types = $product->getRelatedRecordSet('ProductVariationType', $f);
     }
     if (isset($types) && $types->size()) {
         return $types->get(0);
     } else {
         $type = ProductVariationType::getNewInstance($product);
     }
     return $type;
 }
コード例 #27
0
ファイル: Product.php プロジェクト: saiber/www
 /**
  * Get product instance by SKU
  *
  * @param mixed $sku
  * @param bool $loadReferencedRecords
  *
  * @return Product
  */
 public static function getInstanceBySKU($sku, $loadReferencedRecords = false)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('Product', 'sku'), $sku));
     $f->setLimit(1);
     $set = self::getRecordSet($f, $loadReferencedRecords);
     if (!$set->size()) {
         return false;
     } else {
         return $set->get(0);
     }
 }
コード例 #28
0
ファイル: ActiveTreeNode.php プロジェクト: saiber/www
 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;
 }
コード例 #29
0
ファイル: ActiveGrid.php プロジェクト: saiber/livecart
 public function __construct(LiveCart $application, ARSelectFilter $filter, $modelClass = false, $columnTypes = array())
 {
     $this->application = $application;
     $this->modelClass = $modelClass;
     $this->filter = $filter;
     $this->columnTypes = $columnTypes;
     $request = $this->application->getRequest();
     // set recordset boundaries (limits)
     $filter->setLimit($request->get('page_size', 10), $request->get('offset', 0));
     // set order
     if ($request->isValueSet('sort_col')) {
         $handle = $this->getFieldHandle($request->get('sort_col'), self::SORT_HANDLE);
         if ($handle) {
             $filter->setOrder($handle, $request->get('sort_dir'));
         }
     }
     // apply filters
     $filters = $request->get('filters');
     if (!is_array($filters)) {
         $filters = (array) json_decode($request->get('filters'));
     }
     $conds = array();
     if ($filter->getCondition()) {
         $conds[] = $filter->getCondition();
     }
     foreach ($filters as $field => $value) {
         if (!strlen($value)) {
             continue;
         }
         $value = urldecode($value);
         $handle = $this->getFieldHandle($field, self::FILTER_HANDLE);
         if ($handle instanceof EavFieldCommon) {
             continue;
         } else {
             if (!is_array($handle) && !is_null($handle) && !$handle instanceof ARExpressionHandle) {
                 $fieldInst = $this->getFieldInstance($field);
                 if ($fieldInst && ($fieldInst->getDataType() instanceof ARNumeric || $handle->getField()->getDataType() instanceof ARNumeric)) {
                     $value = preg_replace('/[ ]{2,}/', ' ', $value);
                     $constraints = $fieldInst->getDataType() instanceof ARNumeric ? explode(' ', $value) : array($value);
                     foreach ($constraints as $c) {
                         list($operator, $value) = $this->parseOperatorAndValue($c);
                         if (!is_numeric($value) && $fieldInst->getDataType() instanceof ARNumeric) {
                             continue;
                         }
                         $conds[] = new OperatorCond($handle, $value, $operator);
                     }
                 } else {
                     if ($fieldInst && $fieldInst->getDataType() instanceof ARPeriod) {
                         if (substr($value, 0, 10) == 'daterange ') {
                             $value = str_replace('daterange ', '', $value);
                             list($from, $to) = explode('|', $value);
                             $from = trim($from);
                             $to = trim($to);
                             // convert
                             // 2010-9-1 to 2010-09-01 ( +first or last minute of day)
                             // unset dates to 'inf' (meaning ingnore condition)
                             if ($from == '') {
                                 $from = 'inf';
                             } else {
                                 list($y, $m, $d) = explode('-', $from);
                                 $from = $y . '-' . str_pad($m, 2, '0', STR_PAD_LEFT) . '-' . str_pad($d, 2, '0', STR_PAD_LEFT) . ' 00:00:00';
                             }
                             if ($to == '') {
                                 $to = 'inf';
                             } else {
                                 list($y, $m, $d) = explode('-', $to);
                                 $to = $y . '-' . str_pad($m, 2, '0', STR_PAD_LEFT) . '-' . str_pad($d, 2, '0', STR_PAD_LEFT) . ' 23:59:59';
                             }
                         } else {
                             list($from, $to) = explode(' | ', $value);
                         }
                         $cond = null;
                         // from condition
                         if ('inf' != $from) {
                             $cond = new EqualsOrMoreCond($handle, getDateFromString($from));
                         }
                         // to condition
                         if ('now' != $to && 'inf' != $to) {
                             $condTo = new EqualsOrLessCond($handle, getDateFromString($to));
                             if ($cond) {
                                 $cond->addAnd($condTo);
                             } else {
                                 $cond = $condTo;
                             }
                         }
                         if ($cond) {
                             $conds[] = $cond;
                         }
                     } else {
                         $conds[] = new LikeCond($handle, '%' . $value . '%');
                     }
                 }
             } else {
                 if (is_array($handle)) {
                     $cond = null;
                     foreach ($handle as $h) {
                         $c = new LikeCond($h, '%' . $value . '%');
                         if (!$cond) {
                             $cond = $c;
                         } else {
                             $cond->addOR($c);
                         }
                     }
                     $conds[] = $cond;
                 } else {
                     if (array_key_exists($field, $this->columnTypes)) {
                         $type = $this->columnTypes[$field]['type'];
                     } else {
                         $type = null;
                     }
                     $value = preg_replace('/[ ]{2,}/', ' ', $value);
                     switch ($type) {
                         case 'numeric':
                             $constraints = explode(' ', $value);
                             foreach ($constraints as $c) {
                                 list($operator, $value) = $this->parseOperatorAndValue($c);
                                 if (!is_numeric($value)) {
                                     continue;
                                 }
                                 $having[] = new OperatorCond($handle, $value, $operator);
                             }
                             break;
                         default:
                             $having[] = eq(new ARExpressionHandle($field), $value);
                     }
                 }
             }
         }
     }
     // apply IDs to filter
     if ($request->get('selectedIDs') || $request->get('isInverse')) {
         $selectedIDs = json_decode($request->get('selectedIDs'));
         if ($selectedIDs) {
             if ((bool) $request->get('isInverse')) {
                 $idcond = new NotINCond(new ARFieldHandle($modelClass, 'ID'), $selectedIDs);
             } else {
                 $idcond = new INCond(new ARFieldHandle($modelClass, 'ID'), $selectedIDs);
             }
             $conds[] = $idcond;
         } else {
             if (!(bool) $request->get('isInverse')) {
                 $idcond = new EqualsCond(new ARExpressionHandle(1), 2);
                 $conds[] = $idcond;
             }
         }
     }
     if ($conds) {
         $filter->setCondition(new AndChainCondition($conds));
     }
     if (!empty($having)) {
         $filter->setHavingCondition(new AndChainCondition($having));
     }
 }
コード例 #30
0
 private function getSubCatFeaturedProducts()
 {
     $cache = $this->application->getCache();
     $namespace = 'subcategory_featured_' . $this->application->getLocaleCode();
     $id = $this->getCategory()->getID();
     $key = array($namespace, $id);
     if ($products = $cache->get($key)) {
         return $products;
     }
     $count = $this->config->get('FEATURED_COUNT');
     if ('GRID' == $this->getListLayout()) {
         $row = $this->config->get('LAYOUT_GRID_COLUMNS');
         $count = ceil($count / $row) * $row;
     }
     $selFilter = new ARSelectFilter();
     if (!$this->config->get('FEATURED_RANDOM')) {
         $selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isFeatured'), true));
     } else {
         $selFilter->setOrder(new ARExpressionHandle('Product.isFeatured=1'), 'DESC');
     }
     $featuredFilter = new ProductFilter($this->getCategory(), $selFilter);
     $featuredFilter->includeSubcategories();
     $selFilter->setOrder(new ARExpressionHandle('RAND()'));
     $selFilter->setLimit($count);
     $ids = ActiveRecord::getRecordSetFields('Product', $featuredFilter->getSelectFilter(), array('Product.ID'), array('Category', 'Manufacturer'));
     $rand = array();
     foreach ($ids as $id) {
         $rand[] = $id['ID'];
     }
     $featuredFilter = new ProductFilter(Category::getRootNode(), select(in('Product.ID', $rand)));
     $featuredFilter->includeSubcategories();
     $cache->set($key, $this->getProductsArray($featuredFilter), time() + 1800);
     return $cache->get($key);
 }