示例#1
0
 /**
  *
  * @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
 public static function getRecordCount($locale = null)
 {
     $filter = new ARSelectFilter();
     if ($locale) {
         $filter->mergeCondition(eq(f(__CLASS__ . '.locale'), $locale));
     }
     return ActiveRecordModel::getRecordCount(__CLASS__, $filter);
 }
示例#3
0
 public function isValid($value)
 {
     ClassLoader::import('application.model.user.User');
     $filter = new ARSelectFilter();
     $cond = new EqualsCond(new ARFieldHandle('User', 'email'), $value);
     $filter->setCondition($cond);
     return ActiveRecordModel::getRecordCount('User', $filter) == 0;
 }
示例#4
0
 private function fetchData(SearchableModel $searchable, ARSelectFilter $filter)
 {
     $class = $searchable->getClassName();
     $ret = array();
     $ret['records'] = ActiveRecordModel::getRecordSetArray($class, $filter);
     $ret['count'] = ActiveRecordModel::getRecordCount($class, $filter);
     $ret['meta'] = $searchable->toArray();
     return $ret;
 }
示例#5
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);
     }
 }
示例#6
0
 public function export()
 {
     @set_time_limit(0);
     $count = ActiveRecordModel::getRecordCount($this->getClassName(), $this->getListFilter(), $this->getReferencedData());
     $bufferCnt = ceil($count / self::EXPORT_BUFFER_ROW_COUNT);
     // init file download
     header('Content-Disposition: attachment; filename="' . $this->getCSVFileName() . '"');
     header('Content-Type: text/csv');
     $out = fopen('php://output', 'w');
     // header row
     $columns = $this->getExportColumns();
     unset($columns['hiddenType']);
     fputcsv($out, $columns);
     // data
     for ($bufferIndex = 1; $bufferIndex <= $bufferCnt; $bufferIndex++) {
         foreach ($this->lists(true, $columns, $bufferIndex) as $row) {
             fputcsv($out, $row);
         }
     }
     exit;
 }
示例#7
0
 private function fetchData(SearchableModel $searchable, ARSelectFilter $filter)
 {
     $class = $searchable->getClassName();
     $ret = array();
     $ret['records'] = ActiveRecordModel::getRecordSetArray($class, $filter, true);
     $ret['count'] = ActiveRecordModel::getRecordCount($class, $filter);
     // calculate form and to
     $ret['from'] = $filter->getOffset();
     $ret['to'] = $filter->getLimit() + $ret['from'];
     $diff = $ret['to'] - $ret['from'];
     $c = count($ret['records']);
     if ($diff != $c) {
         $ret['to'] = $ret['from'] + $c;
     }
     $ret['from']++;
     $ret['meta'] = $searchable->toArray();
     if (method_exists($this, 'toArray_' . $searchable->getClassName())) {
         call_user_func_array(array($this, 'toArray_' . $searchable->getClassName()), array(&$ret['records']));
     }
     return $ret;
 }
示例#8
0
文件: User.php 项目: saiber/livecart
 public function countInvoices($filter = null)
 {
     $filter = $filter ? $filter : new ARSelectFilter();
     $filter->mergeCondition(new AndChainCondition(array(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->getID()), new EqualsCond(new ARFieldHandle('CustomerOrder', 'isRecurring'), 1), new IsNotNullCond(new ARFieldHandle('CustomerOrder', 'parentID')))));
     return ActiveRecordModel::getRecordCount('CustomerOrder', $filter);
 }
示例#9
0
 private function getTabCounts($categoryId)
 {
     ClassLoader::import('application.model.category.*');
     ClassLoader::import('application.model.filter.*');
     ClassLoader::import('application.model.product.*');
     $category = Category::getInstanceByID($categoryId, Category::LOAD_DATA);
     $reviewCond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $category->lft->get());
     $reviewCond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $category->rgt->get()));
     return array('tabProducts' => $category->totalProductCount->get(), 'tabFilters' => $this->getFilterCount($category), 'tabFields' => $this->getSpecFieldCount($category), 'tabImages' => $this->getCategoryImageCount($category), 'tabOptions' => $category->getOptions()->getTotalRecordCount(), 'tabRatingCategories' => ProductRatingType::getCategoryRatingTypes($category)->size(), 'tabReviews' => ActiveRecordModel::getRecordCount('ProductReview', new ARSelectFilter($reviewCond), array('Category', 'Product')), 'tabProductLists' => $category->getRelatedRecordCount('ProductList'));
 }
示例#10
0
 protected function getOrderCount($from, $to)
 {
     $cond = new EqualsOrMoreCond(new ARFieldHandle('CustomerOrder', 'dateCompleted'), getDateFromString($from));
     if ('now' != $to) {
         $cond->addAnd(new EqualsOrLessCond(new ARFieldHandle('CustomerOrder', 'dateCompleted'), getDateFromString($to)));
     }
     $f = new ARSelectFilter($cond);
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), false));
     return ActiveRecordModel::getRecordCount('CustomerOrder', $f);
 }
示例#11
0
 public static function hasRecurringOrder()
 {
     ClassLoader::import('application.model.product.RecurringItem');
     ClassLoader::import('application.model.product.RecurringProductPeriod');
     $filter = new ARSelectFilter();
     $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'isRecurring'), 1));
     return (bool) ActiveRecordModel::getRecordCount(__CLASS__, $filter);
 }
示例#12
0
 public function saveState(State $state)
 {
     // make sure that such state doesn't exist already
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('State', 'countryID'), $state->countryID->get()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('State', 'code'), $state->code->get()));
     if (!ActiveRecordModel::getRecordCount('State', $f)) {
         return $state->save();
     }
 }
示例#13
0
 public static function isCouponCodes()
 {
     $c = new NotEqualsCond(new ARFieldHandle(__CLASS__, 'couponCode'), '');
     $c->addAND(new EqualsCond(new ARFieldHandle(__CLASS__, 'isEnabled'), 1));
     return ActiveRecordModel::getRecordCount(__CLASS__, new ARSelectFilter($c));
 }
示例#14
0
 public function removeUnchangedDataFromSnapshot($timestamp)
 {
     if (!$timestamp) {
         return;
     }
     // changes in category selection, needs full update
     if (ActiveRecordModel::getRecordCount('ClonedStoreCategory', select(gte(f('ClonedStoreCategory.lastModifiedTime'), $timestamp)))) {
         return;
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
     foreach ($this->tables as $table) {
         ActiveRecordModel::executeUpdate('DELETE FROM ' . $this->importDatabase . '.' . $table . ' WHERE lastModifiedTime<"' . $timestamp . '"');
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=1');
 }
示例#15
0
 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;
     }
 }
示例#16
0
 public function getCategoryProductCount()
 {
     $filter = $this->productFilter->getSelectFilter();
     $filter->joinTable('Category', 'Product', 'ID', 'categoryID');
     return ActiveRecordModel::getRecordCount('Product', $filter);
 }
示例#17
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
include '../application/Initialize.php';
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;
                    }