/** * Displays the form to allow a user to enter their email * * @param Request $request * @return \Illuminate\View\View */ public function getEmail(Request $request) { if (eq($request->segment(1), 'backend')) { return view('backend.auth.forgot_password'); } return view('auth.forgot_password'); }
/** * @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')); }
/** * @param AuthenticateUser $authenticateUser * @param Request $request */ public function __construct(AuthenticateUser $authenticateUser, Request $request) { $this->middleware('guest', ['except' => 'getLogout', 'getActivate']); $this->auth = $authenticateUser; $this->request = $request; $this->backend = eq($request->segment(1), 'backend') ? true : false; }
public function testRunStar() { $result = runStar(function ($q, $r) { return disjPlus(eq($q, 2), eq($q, 3), eq($q, 4)); }); $this->assertEquals('(2 . (3 . (4)))', sprintf('%s', $result)); }
public static function getInstance(OrderedItem $item, ProductFile $file) { $instance = $item->getRelatedRecordSet('OrderedFile', select(eq('OrderedFile.productFileID', $file->getID())))->shift(); if (!$instance) { $instance = self::getNewInstance($item, $file); } return $instance; }
public function testSecondSetT2() { $x = callFresh(function ($q) { return eq($q, 5); }); $result = $x(emptyState()); $this->assertEquals('()', sprintf('%s', cdr($result))); }
public static function getRecordCount($locale = null) { $filter = new ARSelectFilter(); if ($locale) { $filter->mergeCondition(eq(f(__CLASS__ . '.locale'), $locale)); } return ActiveRecordModel::getRecordCount(__CLASS__, $filter); }
private function loadDefaultImage() { if (!isset($this->object['DefaultImage']) && isset($this->object['defaultImageID'])) { $defaultImageArray = ActiveRecordModel::getRecordSetArray('ProductImage', select(eq(f('ProductImage.ID'), $this->object['defaultImageID']))); if (count($defaultImageArray) > 0) { $this->object['DefaultImage'] = array_merge(current($defaultImageArray), array('Product' => ActiveRecord::getArrayData('Product-' . $this->object['ID']))); } } }
protected function getSelectFilter() { if (!$this->selectFilter) { $this->selectFilter = select(eq('CustomerOrder.isFinalized', true), isnotnull('CustomerOrder.invoiceNumber')); $this->selectFilter->setOrder(f('CustomerOrder.dateCompleted'), 'DESC'); $this->selectFilter->setLimit(1); } return $this->selectFilter; }
public function getPastOrders() { if (!is_null($this->pastOrders)) { return $this->pastOrders; } if (!$this->user) { return array(); } $sessionUser = SessionUser::getUser(); if ($this->isSessionCacheUsable()) { $session = new Session(); $sessionHandler = ActiveRecordModel::getApplication()->getSessionHandler(); $pastOrders = $session->get('pastOrders'); if (!$pastOrders || $pastOrders['cacheUpdated'] != $sessionHandler->getCacheUpdateTime()) { unset($pastOrders); } } if (empty($pastOrders)) { $f = select(eq('CustomerOrder.userID', $this->user->getID()), eq('CustomerOrder.isFinalized', true), eq('CustomerOrder.isCancelled', 0), eq('CustomerOrder.isPaid', true)); $f->setOrder(f('OrderedItem.customerOrderID'), 'DESC'); $records = ActiveRecordModel::getRecordSetArray('OrderedItem', $f, array('CustomerOrder', 'Product')); // load variation parent products separately $parentIDs = array(); foreach ($records as $record) { if ($record['Product']['parentID']) { //$parentIDs[$record['Product']['parentID']] = true; } } if ($parentIDs) { $parents = array(); foreach (ActiveRecordModel::getRecordSetArray('Product', select(in('Product.ID', array_keys($parentIDs)))) as $parent) { $parents[$parent['ID']] = $parent; } foreach ($records as &$record) { if ($record['Product']['parentID']) { $record['Product']['Parent'] = $parents[$record['Product']['parentID']]; } } } // split records by orders $orders = array(); foreach ($records as $record) { $orders[$record['customerOrderID']][] = $record; } $pastOrders = array(); foreach ($orders as $order) { $pastOrders[] = new RuleOrderContainer($order); } $pastOrders = array('cacheUpdated' => time(), 'orders' => $pastOrders); } if ($this->isSessionCacheUsable()) { $session->set('pastOrders', $pastOrders); $sessionHandler->updateCacheTimestamp(); } $this->pastOrders = $pastOrders; return $this->pastOrders; }
public static function getInstanceByDateTime($date, $time) { $f = new ARSelectFilter(); $f->setCondition(new AndChainCondition(array(eq(f('EyeExamSchedule.date'), $date), eq(f('EyeExamSchedule.time'), $time), isnull(f('EyeExamSchedule.eyeExamRequestID'))))); $s = self::getRecordSet('EyeExamSchedule', $f); if (!$s->size()) { return null; } return $s->get(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); }
/** * Tests whether the specified comparable object * is in this binary search tree. * * @param object IComparable $obj The object for which to look. * @return boolean True if the specified object * is in this binary search tree; false otherwise. */ public function contains(IComparable $obj) { if ($this->isEmpty()) { return false; } elseif (eq($obj, $this->getKey())) { return true; } elseif (lt($obj, $this->getKey())) { return $this->getLeft()->contains($obj); } else { return $this->getRight()->contains($obj); } }
public function news() { $this->shouldBeEnabledFeed('NEWS_POSTS'); $this->setLayout('empty'); $response = new XMLResponse(); $f = select(eq(f('NewsPost.isEnabled'), true)); $f->setLimit($this->config->get('NUMBER_OF_NEWS_POSTS_TO_INCLUDE')); $f->setOrder(f('NewsPost.position'), ARSelectFilter::ORDER_DESC); $response->set('feed', ActiveRecordModel::getRecordSetArray('NewsPost', $f)); $this->application->getLocale()->translationManager()->loadFile('News'); return $response; }
public function addCategory() { $category = Category::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category')); $relatedCategory = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA); // check if the category is not assigned to this category already $f = select(eq('CategoryRelationship.relatedCategoryID', $relatedCategory->getID())); if ($category->getRelatedRecordSet('CategoryRelationship', $f)->size()) { return new JSONResponse(false, 'failure', $this->translate('_err_already_assigned')); } $relation = CategoryRelationship::getNewInstance($category, $relatedCategory); $relation->save(); $relatedCategory->getPathNodeSet(); return new JSONResponse(array('data' => $relation->toFlatArray())); }
public function get() { $request = $this->application->getRequest(); $products = ActiveRecordModel::getRecordSetArray('Product', select(eq(f('Product.sku'), $request->get('SKU'))), array('Category', 'Manufacturer', 'ProductImage')); if (count($products) == 0) { throw new Exception('Product not found'); } // -- $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $responseProduct = $response->addChild('product'); while ($product = array_shift($products)) { $this->fillResponseItem($responseProduct, $product); } return new SimpleXMLResponse($response); }
public function getSelectFilter($searchTerm) { // create initial index if (0 && !SearchableItem::getRecordCount()) { $app = ActiveRecordModel::getApplication(); $sc = new SearchableConfigurationIndexing($app->getConfig(), $app); $sc->buildIndex(null); } $c = new ARExpressionHandle($this->getWeighedSearchCondition(array('value' => 1), $searchTerm)); $app = ActiveRecordModel::getApplication(); $f = new ARSelectFilter(new MoreThanCond($c, 0)); $f->mergeCondition(new OrChainCondition(array(eq(f('SearchableItem.locale'), $app->getDefaultLanguageCode()), eq(f('SearchableItem.locale'), $app->getLocaleCode()), isnull(f('SearchableItem.locale'))))); $f->setOrder(f('SearchableItem.sort'), 'DESC'); $f->setOrder($c, 'DESC'); return $f; }
/** * Inserts the specified object into this B-tree. * * @param object IComparable $obj The object to insert. */ public function insert(IComparable $obj) { if ($this->isEmpty()) { if ($this->parent === NULL) { $this->attachSubtree(0, new BTree($this->getM())); $this->key[1] = $obj; $this->attachSubtree(1, new BTree($this->getM())); $this->count = 1; } else { $this->parent->insertPair($obj, new BTree($this->getM())); } } else { $index = $this->findIndex($obj); if ($index != 0 && eq($object, $this->key[$index])) { throw new ArgumentError(); } $this->subtree[$index]->insert($obj); } }
/** * @param $request * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse */ public function getEmailResponse($request) { if ($this->data === PasswordBroker::INVALID_USER) { if ($request->ajax()) { return response()->json(['message' => $this->userNotFoundMessage], 404); } else { flash()->error($this->userNotFoundMessage); return redirect()->back()->with('email', $request->get('email')); } } if ($this->data === PasswordBroker::RESET_LINK_SENT) { if ($request->ajax()) { return response()->json(['message' => "Password reset instructions successfully sent to {$request->get('email')}", 'target' => eq($request->segment(1), 'backend') ? route('backend.login') : route('login')]); } else { flash("Password reset instructions successfully sent to {$request->get('email')}"); return eq($request->segment(1), 'backend') ? redirect()->route('backend.login') : redirect()->route('login'); } } }
/** * @role update */ public function upload() { $result = parent::upload(); $request = $this->getRequest(); if ($request->get('setAsMainImage')) { $data = json_decode($result->get('result')); $imageID = $data->ID; $filter = select(eq(f('ProductImage.productID'), $request->get('ownerId'))); $filter->setOrder(f('ProductImage.position')); $r = ActiveRecordModel::getRecordSetArray('ProductImage', $filter, true); $order = array($imageID); foreach ($r as $item) { if ($imageID != $item['ID']) { $order[] = $item['ID']; } } parent::saveOrder($order); } return $result; }
public function get() { $parser = $this->getParser(); $id = $this->getRequestID(); $categories = ActiveRecordModel::getRecordSetArray('ShippingAddress', select(eq(f('ShippingAddress.ID'), $id))); if (count($categories) == 0) { throw new Exception('Shipping address not found'); } $apiFieldNames = $parser->getApiFieldNames(); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $responseCategory = $response->addChild('shipping_address'); while ($category = array_shift($categories)) { foreach ($category as $k => $v) { if (in_array($k, $apiFieldNames)) { $responseCategory->addChild($k, $v); } } } return new SimpleXMLResponse($response); }
public function getSelectFilter($disableFilters = false) { $selectFilter = $this->category->getProductsFilter($this, false); $selectFilter->merge($this->productFilter); $cond = null; if ($disableFilters == false) { $list = array(); // group filters by class foreach ($this->filters as $filter) { $id = $filter instanceof SpecificationFilterInterface ? $filter->getFilterGroup()->getID() : ''; $list[get_class($filter) . '_' . $id][] = $filter->getCondition(); $filter->defineJoin($selectFilter); } // convert filter group to OrChainCondition foreach ($list as &$filterGroup) { $filterGroup = new OrChainCondition($filterGroup); } if ($fCond = $selectFilter->getCondition()) { $list[] = $fCond; } $selectFilter->setCondition(new AndChainCondition($list)); // all merged with and } if (!empty(ActiveRecordModel::getApplication()->variationCond)) { $c = ActiveRecordModel::getApplication()->variationCond; $c->addAND(eq(f('Product.isEnabled'), true)); $noOrphans = new IsNotNullCond(f('Product.categoryID')); $orphanVariations = new IsNotNullCond(f('Product.parentID')); $orphanVariations->addAND(new IsNotNullCond(new ARExpressionHandle('(SELECT categoryID FROM Product AS par WHERE par.ID=Product.parentID)'))); $noOrphans->addOr($orphanVariations); $c->addAND($noOrphans); //$c->addAND(gt(f('Product.stockCount'), 0)); $conds = array($selectFilter->getCondition(), $c); $selectFilter->setCondition(new OrChainCondition($conds)); $selectFilter->setOrder(new ARExpressionHandle('(Product.parentID IS NULL)'), 'DESC'); //var_dump($selectFilter->createString()); } ActiveRecordModel::getApplication()->processInstancePlugins('finalProductFilter', $selectFilter); return $selectFilter; }
/** * Non-strict equality (==) using type coercion * http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/ * @param $a * @param $b * @return bool */ function eq($a, $b) { $typeA = $a === null || $a === Object::$null ? 'null' : ($a instanceof Object ? 'object' : gettype($a)); $typeB = $b === null || $b === Object::$null ? 'null' : ($b instanceof Object ? 'object' : gettype($b)); if ($typeA === 'null' && $typeB === 'null') { return true; } if ($typeA === 'integer') { $a = (double) $a; $typeA = 'double'; } if ($typeB === 'integer') { $b = (double) $b; $typeB = 'double'; } if ($typeA === $typeB) { return $a === $b; } if ($typeA === 'double' && $typeB === 'string') { return $a === to_number($b); } if ($typeB === 'double' && $typeA === 'string') { return $b === to_number($a); } if ($typeA === 'boolean') { return eq((double) $a, $b); } if ($typeB === 'boolean') { return eq((double) $b, $a); } if (($typeA === 'string' || $typeA === 'double') && $typeB === 'object') { return eq($a, to_primitive($b)); } if (($typeB === 'string' || $typeB === 'double') && $typeA === 'object') { return eq($b, to_primitive($a)); } return false; }
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; }
public function read($id) { if (!$this->db) { return; } try { $data = ActiveRecordModel::getRecordSetArray('SessionData', select(eq('SessionData.ID', $id))); } catch (SQLException $e) { return ''; } $this->isExistingSession = count($data) > 0; if ($data) { $data = array_shift($data); $this->originalData = $data['data']; if (time() - $data['lastUpdated'] > self::KEEPALIVE_INTERVAL || !$data['userID'] && !$data['cacheUpdated']) { $this->forceUpdate = true; } $this->id = $data['ID']; $this->userID = $data['userID']; $this->cacheUpdated = $data['cacheUpdated']; return $data['data']; } return ''; }
public function get() { $request = $this->application->getRequest(); $parser = $this->getParser(); $users = ActiveRecordModel::getRecordSetArray('User', select(eq(f('User.ID'), $this->getRequestID()))); if (count($users) == 0) { throw new Exception('User not found'); } $apiFieldNames = $parser->getApiFieldNames(); $addressFieldNames = array('firstName', 'lastName', 'address1', 'address2', 'city', 'stateName', 'postalCode', 'phone'); // -- $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $responseCustomer = $response->addChild('customer'); while ($user = array_shift($users)) { foreach ($user as $k => $v) { if (in_array($k, $apiFieldNames)) { $responseCustomer->addChild($k, $v); } } // todo: join? how?? m?! $u = User::getInstanceByID($user['ID']); $u->loadAddresses(); // default billing and shipping addreses foreach (array('defaultShippingAddress', 'defaultBillingAddress') as $addressType) { if (is_numeric($user[$addressType . 'ID'])) { $address = $u->defaultBillingAddress->get()->userAddressID->get(); foreach ($addressFieldNames as $addressFieldName) { $responseCustomer->addChild($addressType . '_' . $addressFieldName, $address->{$addressFieldName}->get()); } } } $this->mergeUserEavFields($responseCustomer, $u); $this->clear($u); } return new SimpleXMLResponse($response); }
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)); } }
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()); } }
public function invalidateSessionCache() { if ($this->isAnonymous()) { return; } $f = new ARUpdateFilter(eq(f('SessionData.userID'), $this->getID())); $f->addModifier('cacheUpdated', 0); self::updateRecordSet('SessionData', $f); }
function occur($a, $lat) { return empty($lat) ? 0 : (eq(car($lat), $a) ? add(1, occur($a, cdr($lat))) : occur($a, cdr($lat))); }