Exemplo n.º 1
0
 /**
  * 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'));
     }
 }
Exemplo n.º 2
0
 public static function getOrderFiles(ARSelectFilter $f)
 {
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), 0));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), true));
     //$f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'type'), Product::TYPE_DOWNLOADABLE));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
     $downloadable = ActiveRecordModel::getRecordSet('OrderedItem', $f, array('Product', 'CustomerOrder'));
     $fileArray = array();
     foreach ($downloadable as &$item) {
         $files = $item->getProduct()->getFiles();
         $itemFiles = array();
         foreach ($files as $file) {
             if ($item->isDownloadable($file)) {
                 $itemFiles[] = $file->toArray();
             }
         }
         if (!$itemFiles) {
             continue;
         }
         $array = $item->toArray();
         $array['Product']['Files'] = ProductFileGroup::mergeGroupsWithFields($item->getProduct()->getFileGroups()->toArray(), $itemFiles);
         foreach ($array['Product']['Files'] as $key => $file) {
             if (!isset($file['ID'])) {
                 unset($array['Product']['Files'][$key]);
             }
         }
         $fileArray[] = $array;
     }
     return $fileArray;
 }
Exemplo n.º 3
0
 public function syncAll($select = null)
 {
     $this->errors = array();
     $this->flush(__LINE__);
     // find deleted records
     $file = $this->getIDFile();
     $previousIDs = file_exists($file) ? include $file : array();
     $deleted = $this->getDeletedRecordIDs($previousIDs);
     $this->flush(__LINE__);
     // get previous timestamp
     $file = $this->getTimestampFile();
     $timestamp = null;
     //$timestamp = file_exists($file) ? include $file : null;
     $this->flush(__LINE__);
     // get files
     $files = $this->getFileList();
     $this->flush(__LINE__);
     // update each store
     $select = !empty($select) ? $select : select();
     foreach (ActiveRecordModel::getRecordSet('ClonedStore', $select) as $store) {
         $this->flush(__LINE__);
         $this->updateStore($store, $deleted, $files);
     }
     file_put_contents($this->getIDFile(), '<?php return ' . var_export($this->getRecordIDs(), true) . ';', LOCK_EX);
     file_put_contents($this->getTimestampFile(), '<?php return ' . var_export($this->getTimestamp(), true) . ';', LOCK_EX);
 }
Exemplo n.º 4
0
 public function testAutoReference()
 {
     $child = ActiveRecordModel::getNewInstance('AutoReferenceChild');
     $child->name->set('child');
     $child->save();
     $parent = ActiveRecordModel::getNewInstance('AutoReferenceParent');
     $parent->setID(4);
     $parent->name->set('parent');
     $parent->reference->set($child);
     $parent->save();
     ActiveRecordModel::clearPool();
     // test loading data array
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('AutoReferenceParent', 'ID'), 4));
     $array = array_shift(ActiveRecordModel::getRecordSetArray('AutoReferenceParent', $f));
     $this->assertEqual($array['ID'], 4);
     $this->assertEqual($array['Reference']['name'], 'child');
     ActiveRecordModel::clearPool();
     // test loading instance by ID
     $newParent = ActiveRecordModel::getInstanceByID('AutoReferenceParent', 4, ActiveRecordModel::LOAD_DATA);
     $this->assertEqual($newParent->reference->get()->name->get(), 'child');
     $this->assertNotSame($parent, $newParent);
     $this->assertNotSame($child, $newParent->reference->get());
     // test loading record set
     $newParent = ActiveRecordModel::getRecordSet('AutoReferenceParent', $f)->get(0);
     $this->assertEqual($newParent->reference->get()->name->get(), 'child');
     $this->assertNotSame($parent, $newParent);
     $this->assertNotSame($child, $newParent->reference->get());
 }
Exemplo n.º 5
0
 public function process($loadReferencedRecords = array())
 {
     set_time_limit(0);
     ignore_user_abort(true);
     $this->deleteCancelFile();
     $filter = $this->grid->getFilter();
     $filter->setLimit(0);
     $ids = array();
     foreach (ActiveRecordModel::getFieldValues($this->grid->getModelClass(), $filter, array('ID'), ActiveRecordModel::LOAD_REFERENCES) as $row) {
         $ids[] = $row['ID'];
     }
     $totalCount = count($ids);
     $progress = 0;
     $response = new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->completionMessage);
     ActiveRecord::beginTransaction();
     $chunkSize = count($ids) / self::MASS_ACTION_CHUNK_SIZE > 5 ? self::MASS_ACTION_CHUNK_SIZE : ceil(count($ids) / 5);
     foreach (array_chunk($ids, $chunkSize) as $chunk) {
         $response->flush('|' . base64_encode(json_encode(array('total' => $totalCount, 'progress' => $progress, 'pid' => $this->pid))));
         $this->processSet(ActiveRecordModel::getRecordSet($this->grid->getModelClass(), new ARSelectFilter(new INCond(new ARFieldHandle($this->grid->getModelClass(), 'ID'), $chunk)), $loadReferencedRecords));
         $progress += count($chunk);
     }
     ActiveRecord::commit();
     $response->flush('|');
     return $response;
 }
Exemplo n.º 6
0
 public static function deleteByID($className, $id, $foreignKeyName)
 {
     $inst = ActiveRecordModel::getInstanceById($className, $id, ActiveRecordModel::LOAD_DATA);
     $inst->getOwner()->load();
     $inst->deleteImageFiles();
     // check if main image is being deleted
     $owner = $inst->getOwner();
     $owner->load(array(get_class($inst)));
     if ($owner->defaultImage->get()->getID() == $id) {
         // set next image (by position) as the main image
         $f = new ARSelectFilter();
         $cond = new EqualsCond(new ARFieldHandle(get_class($inst), $foreignKeyName), $owner->getID());
         $cond->addAND(new NotEqualsCond(new ARFieldHandle(get_class($inst), 'ID'), $inst->getID()));
         $f->setCondition($cond);
         $f->setOrder(new ARFieldHandle(get_class($inst), 'position'));
         $f->setLimit(1);
         $newDefaultImage = ActiveRecordModel::getRecordSet(get_class($inst), $f);
         if ($newDefaultImage->size() > 0) {
             $owner->defaultImage->set($newDefaultImage->get(0));
             $owner->save();
         }
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
     ActiveRecordModel::executeUpdate('UPDATE ' . $className . ' SET ' . $foreignKeyName . '=NULL , protectedFields="|' . $foreignKeyName . '|" WHERE ID=' . $id);
     //return parent::deleteByID($className, $id);
 }
Exemplo n.º 7
0
 public function getSpecificationFieldSet($loadReferencedRecords = false)
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle($this->getFieldClass(), 'classID'), EavField::getClassID($this->owner)));
     if ($this->owner->getStringIdentifier()) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('EavField', 'stringIdentifier'), $this->owner->getStringIdentifier()));
     }
     $f->setOrder(new ARFieldHandle($this->getFieldClass(), 'position'));
     return ActiveRecordModel::getRecordSet($this->getFieldClass(), $f, $loadReferencedRecords);
 }
Exemplo n.º 8
0
 public static function getUserAddress($className, $addressID, User $user)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle($className, 'ID'), $addressID));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle($className, 'userID'), $user->getID()));
     $s = ActiveRecordModel::getRecordSet($className, $f, array('UserAddress'));
     if (!$s->size()) {
         throw new ARNotFoundException($className, $addressID);
     }
     return $s->get(0);
 }
Exemplo n.º 9
0
 public static function getThemeByProduct(Product $product)
 {
     $c = eq(__CLASS__ . '.productID', $product->getID());
     $c->addOr(self::getCategoryCondition($product->getCategory()));
     $f = select($c);
     $f->setOrder(new ARExpressionHandle('CategoryPresentation.productID=' . $product->getID()), 'DESC');
     self::setCategoryOrder($product->getCategory(), $f);
     // check if a theme is defined for this product particularly
     $set = ActiveRecordModel::getRecordSet(__CLASS__, $f, array('Category'));
     return self::getInheritedConfig($set);
 }
Exemplo n.º 10
0
 public static function loadOptionsForItemSet(ARSet $orderedItems)
 {
     // load applied product option choices
     $ids = array();
     foreach ($orderedItems as $key => $item) {
         $ids[] = $item->getID();
     }
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('OrderedItemOption', 'orderedItemID'), $ids));
     foreach (ActiveRecordModel::getRecordSet('OrderedItemOption', $f, array('DefaultChoice' => 'ProductOptionChoice', 'Option' => 'ProductOption', 'Choice' => 'ProductOptionChoice')) as $itemOption) {
         $itemOption->orderedItem->get()->loadOption($itemOption);
     }
 }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
 public function view()
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'ID'), $this->request->get('id')));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $s = ActiveRecordModel::getRecordSet('NewsPost', $f);
     if (!$s->size()) {
         throw new ARNotFoundException('NewsPost', $this->request->get('id'));
     }
     $newsPost = $s->get(0)->toArray();
     $this->addIndexBreadCrumb();
     $this->addBreadCrumb($newsPost['title_lang'], '');
     return new ActionResponse('news', $newsPost);
 }
Exemplo n.º 14
0
 public static function getRecordSetArrayByIDs($recordIDs, $loadRecordData = false)
 {
     if (!is_array($recordIDs)) {
         $recordIDs = array($recordIDs);
     }
     $filter = new ARSelectFilter();
     $filter->setCondition(new InCond(new ARFieldHandle(__CLASS__, 'ID'), $recordIDs));
     // ActiveRecordModel::getRecordSetArray() will not get required setup and period prices!
     $rs = ActiveRecordModel::getRecordSet(__CLASS__, $filter);
     $result = array();
     foreach ($rs->toArray() as $item) {
         $result[$item['ID']] = $item;
     }
     return $result;
 }
Exemplo n.º 15
0
 protected function getLastOrders()
 {
     $f = select();
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), false));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'dateCompleted'), 'desc');
     $f->setLimit(10);
     $customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
     $ordersArray = array();
     if ($customerOrders->size() > 0) {
         $i = 0;
         foreach ($customerOrders as $order) {
             $ordersArray[$i] = $order->toArray();
             $ordersArray[$i]['status_name'] = CustomerOrder::getStatusName($ordersArray[$i]['status'] ? $ordersArray[$i]['status'] : CustomerOrder::STATUS_NEW);
             $i++;
         }
         return $ordersArray;
     }
     return array();
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     // get delivery zone
     if (isset($fields['DeliveryZone']['ID'])) {
         try {
             $zone = DeliveryZone::getInstanceByID($record[$fields['DeliveryZone']['ID']], true);
         } catch (ARNotFoundException $e) {
             $zone = DeliveryZone::getDefaultZoneInstance();
         }
     } else {
         $zone = DeliveryZone::getDefaultZoneInstance();
     }
     // get shipping service
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('ShippingService', 'name'), $this->application->getDefaultLanguageCode()), $record[$fields['ShippingService']['name']]));
     if ($zone->isDefault()) {
         $f->mergeCondition(new IsNullCond(f('ShippingService.deliveryZoneID')));
     } else {
         $f->mergeCondition(eq(f('ShippingService.deliveryZoneID'), $zone->getID()));
     }
     $services = ActiveRecordModel::getRecordSet('ShippingService', $f);
     if ($services->get(0)) {
         $service = $services->get(0);
         // temporary
         $service->deleteRelatedRecordSet('ShippingRate');
     } else {
         $service = ShippingService::getNewInstance($zone, '', 0);
         $service->rangeType->set(ShippingService::SUBTOTAL_BASED);
     }
     $this->importInstance($record, $profile, $service);
     $this->setLastImportedRecordName($service->getValueByLang('name'));
     // get rate instance
     $rate = ShippingRate::getNewInstance($service, 0, 1000000);
     $rate->subtotalRangeStart->set(0);
     $rate->subtotalRangeEnd->set(1000000);
     return $rate;
 }
Exemplo n.º 18
0
 public static function findByName($name)
 {
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('TaxClass', 'name'), self::getApplication()->getDefaultLanguageCode()), $name));
     return ActiveRecordModel::getRecordSet('TaxClass', $f)->get(0);
 }
Exemplo n.º 19
0
 public function resizeImages()
 {
     set_time_limit(0);
     $class = $this->getModelClass();
     $f = select();
     $count = ActiveRecord::getRecordCount($class, $f);
     $offset = 0;
     $chunk = 100;
     ob_flush();
     ob_end_clean();
     do {
         $f->setLimit($chunk, $offset);
         $set = ActiveRecordModel::getRecordSet($class, $f);
         foreach ($set as $image) {
             foreach (array($image->getPath('original'), $image->getPath(4)) as $path) {
                 if (file_exists($path)) {
                     $image->setFile($path);
                     echo $image->getID() . '|';
                     flush();
                     break;
                 }
             }
         }
         $offset += $chunk;
         ActiveRecord::clearPool();
     } while ($set->size() > 0);
 }
Exemplo n.º 20
0
 private function apiActionGetOrdersBySelectFilter($ARSelectFilter, $allowEmptyResponse = false)
 {
     set_time_limit(0);
     $ARSelectFilter->setOrder(new ARExpressionHandle('CustomerOrder.ID'), 'DESC');
     $customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $ARSelectFilter, array('User'));
     if ($allowEmptyResponse == false && count($customerOrders) == 0) {
         throw new Exception('Order not found');
     }
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     foreach ($customerOrders as $order) {
         $order->loadAll();
         $transactions = $order->getTransactions();
         $this->fillResponseItem($response->addChild('order'), $order->toArray());
         unset($order);
         ActiveRecord::clearPool();
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 21
0
 /**
  * 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;
     }
 }
Exemplo n.º 22
0
 /**
  * Calculate a delivery rate for a particular shipment
  *
  * @return ShipmentDeliveryRate
  */
 public function getDeliveryRate(Shipment $shipment)
 {
     $hasFreeShipping = false;
     // get applicable rates
     if (self::WEIGHT_BASED == $this->rangeType->get()) {
         $weight = $shipment->getChargeableWeight($this->deliveryZone->get());
         $cond = new EqualsOrLessCond(new ARFieldHandle('ShippingRate', 'weightRangeStart'), $weight * 1.000001);
         $cond->addAND(new EqualsOrMoreCond(new ARFieldHandle('ShippingRate', 'weightRangeEnd'), $weight * 0.99999));
     } else {
         $total = $shipment->getSubTotal(Shipment::WITHOUT_TAXES);
         $cond = new EqualsOrLessCond(new ARFieldHandle('ShippingRate', 'subtotalRangeStart'), $total * 1.000001);
         $cond->addAND(new EqualsOrMoreCond(new ARFieldHandle('ShippingRate', 'subtotalRangeEnd'), $total * 0.99999));
     }
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ShippingRate', 'shippingServiceID'), $this->getID()));
     $f->mergeCondition($cond);
     $rates = ActiveRecordModel::getRecordSet('ShippingRate', $f);
     if (!$rates->size()) {
         return null;
     }
     $itemCount = $shipment->getChargeableItemCount($this->deliveryZone->get());
     $maxRate = 0;
     foreach ($rates as $rate) {
         $charge = $rate->flatCharge->get();
         foreach ($shipment->getItems() as $item) {
             $charge += $rate->getItemCharge($item) * $item->getCount();
         }
         if (self::WEIGHT_BASED == $this->rangeType->get()) {
             $charge += $rate->perKgCharge->get() * $weight;
         } else {
             $charge += $rate->subtotalPercentCharge->get() / 100 * $total;
         }
         if ($charge > $maxRate) {
             $maxRate = $charge;
         }
     }
     return ShipmentDeliveryRate::getNewInstance($this, $maxRate);
 }
Exemplo n.º 23
0
Arquivo: User.php Projeto: saiber/www
 public function getShippingAddressSet($defaultFirst = true)
 {
     return ActiveRecordModel::getRecordSet('ShippingAddress', $this->getShippingAddressFilter($defaultFirst), array('UserAddress'));
 }
Exemplo n.º 24
0
 public function loadAdditionalCategoriesForSet(ARSet $set)
 {
     $map = $set->getIDMap();
     foreach (ActiveRecordModel::getRecordSet('ProductCategory', new ARSelectFilter(new INCond(new ARFieldHandle('ProductCategory', 'productID'), $set->getRecordIDs())), array('Category')) as $additional) {
         $map[$additional->product->get()->getID()]->registerAdditionalCategory($additional->category->get());
     }
 }
Exemplo n.º 25
0
 private function send(NewsletterMessage $newsletter)
 {
     set_time_limit(0);
     $response = new JSONResponse(null);
     $data = $this->getRecipientData($this->request->toArray());
     $total = count($data);
     $subscribers = $users = array();
     foreach ($data as $row) {
         if ($row['userID']) {
             $users[] = $row['userID'];
         } else {
             $subscribers[] = $row['subscriberID'];
         }
     }
     $progress = 0;
     foreach (array('User' => $users, 'NewsletterSubscriber' => $subscribers) as $table => $ids) {
         foreach (array_chunk($ids, self::PROGRESS_FLUSH_INTERVAL) as $chunk) {
             foreach (ActiveRecordModel::getRecordSet($table, new ARSelectFilter(new InCond(new ARFieldHandle($table, 'ID'), $chunk))) as $recipient) {
                 $progress++;
                 $newsletter->send($recipient, $this->application);
                 if ($progress % self::PROGRESS_FLUSH_INTERVAL == 0 || $total == $progress) {
                     $response->flush($this->getJsonResponse(array('progress' => $progress, 'total' => $total)));
                 }
             }
             ActiveRecord::clearPool();
         }
     }
     $newsletter->markAsSent();
     $response->flush($this->getJsonResponse(array('progress' => 0, 'total' => $total)));
     exit;
 }
Exemplo n.º 26
0
 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();
 }
Exemplo n.º 27
0
 /**
  * Load groups to roles associations from database
  *
  * @param Role $role Associate group with this role
  * @param ARSelectFilter $filter
  * @param bool $loadReferencedRecords
  *
  * @return ARSet
  */
 public static function getRecordSet(ARSelectFilter $filter, $loadReferencedRecords = false)
 {
     return parent::getRecordSet(__CLASS__, $filter, $loadReferencedRecords);
 }
Exemplo n.º 28
0
 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);
 }
Exemplo n.º 29
0
 public function downloadOptionFile()
 {
     ClassLoader::import('application.model.product.ProductOptionChoice');
     $f = select(eq('CustomerOrder.userID', $this->user->getID()), eq('OrderedItem.ID', $this->request->get('id')), eq('ProductOptionChoice.optionID', $this->request->get('option')));
     $set = ActiveRecordModel::getRecordSet('OrderedItemOption', $f, array('CustomerOrder', 'OrderedItem', 'ProductOptionChoice'));
     if ($set->size()) {
         return new ObjectFileResponse($set->get(0)->getFile());
     }
 }
Exemplo n.º 30
0
 public function getVariations()
 {
     $f = new ARSelectFilter(new INCOnd(new ARFieldHandle('ProductVariation', 'typeID'), $this->getRecordIDs()));
     $f->setOrder(new ARFieldHandle('ProductVariation', 'position'));
     return ActiveRecordModel::getRecordSet('ProductVariation', $f);
 }