public static function byName($name) { $niceName = str_replace('_', ' ', $name); $settings = new self(); $settings->addFilter(new Ajde_Filter_Join('setting_meta', 'setting_meta.setting', 'setting.id')); $settings->addFilter(new Ajde_Filter_Join('meta', 'meta.id', 'setting_meta.meta')); $settings->addFilter(new Ajde_Filter_Where('setting.name', Ajde_Filter::FILTER_EQUALS, $niceName)); $settings->getQuery()->addSelect('setting_meta.value'); $settings->getQuery()->addSelect('meta.name AS meta_name'); $result = []; if ($settings->count()) { foreach ($settings as $setting) { $result[$setting->meta_name] = $setting->value; } } return $result; }
/** * @param $query * @param int $offset * @param int $perPage * @param array $config * @param null $facet * @return Cse */ public static function search($query, $offset = 0, $perPage = 10, array $config = array(), $facet = null) { $list = new self(); $list->setConfig($config); $list->setOffset($offset); $list->setPerPage($perPage); $list->setQuery($query); if (!empty($facet)) { $list->setQuery($list->getQuery() . " more:" . $facet); } return $list; }
/** * Resolve a base URI with a relative URI and return a new URI. * * @param UriInterface $base Base URI * @param null|string|UriInterface $rel Relative URI * * @throws \InvalidArgumentException * * @return UriInterface */ public static function resolve(UriInterface $base, $rel = null) { if ($rel === null || $rel === '') { return $base; } if (!$rel instanceof UriInterface) { $rel = new self($rel); } // Return the relative uri as-is if it has a scheme. if ($rel->getScheme()) { return $rel->withPath(static::removeDotSegments($rel->getPath())); } $relParts = ['scheme' => $rel->getScheme(), 'authority' => $rel->getAuthority(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()]; $parts = ['scheme' => $base->getScheme(), 'authority' => $base->getAuthority(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()]; if (!empty($relParts['path'])) { if (strpos($relParts['path'], '/') === 0) { $parts['path'] = self::removeDotSegments($relParts['path']); $parts['query'] = $relParts['query']; $parts['fragment'] = $relParts['fragment']; } else { $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1); $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']); $parts['query'] = $relParts['query']; $parts['fragment'] = $relParts['fragment']; } } elseif (!empty($relParts['query'])) { $parts['query'] = $relParts['query']; } elseif ($relParts['fragment'] !== null) { $parts['fragment'] = $relParts['fragment']; } return new self(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment'])); }
/** * get all available values that can bee used for filter * @param string $field * * @return array * @deprecated refactoring */ protected function getAvailableFilterValues($field) { if (!$this->availableFilterValues) { $listing = new self(); $query = $listing->getQuery(); $query = str_replace('-- [GET_AVAILABLE_OPTIONS]', ' , ifnull(GROUP_CONCAT(DISTINCT product.o_id, "|", product.o_parentId SEPARATOR "|"),0) as "available_productId" , ifnull(GROUP_CONCAT(DISTINCT pricingRule.ruleId SEPARATOR "|"),0) as "available_pricingRules" ', $query); $query = str_replace('GROUP BY orderItem', '', $query); $conn = \Pimcore\Resource::getConnection(); $conn->query('SET SESSION group_concat_max_len = 1000000'); $this->availableFilterValues = $conn->fetchRow($query); } return explode('|', $this->availableFilterValues['available_' . $field]); }
/** * Add a condition over a related model. * * Usage: * ------ * * There is different calling form for this function. * * * Check existence of related models. This is a merely a WHERE EXISTS * clause in SQL: * * `$query->root('Blog')->has('articles');` * * * Perform a condition over the *number* of related models: * * `$query->root('Blog')->where('articles', '>', 100);` * * This would retrieve blogs instance which contains at least one hundred * articles. * * * Use a Closure to add conditions to the subquery: * * ```php * $query->root('Blog')->has('articles', function ($q) { * $q->where('online', true); * }); * * @param string $relation The name of the relation to check on. * @param string $op Optional. The operator for the second use form. * @param mixed $value Optional. The value for the second use form. * * @return $this */ public function whereHas($relation, $op = null, $value = null, $not = false) { $mainQuery = $this->getQueryOrNewSelect(); $mainQueryRootAlias = $mainQuery->getBuilder()->getRootAlias(); // We'll use $rels for recursivity. $rels = explode('/', $relation); $relation = array_shift($rels); $root = $this->getRoot(); $rel = $root::relation($relation); // We construct the sub-query. It can be the sub-query of an Exists // clause or a Count (if $op and $value are given). $subRootAlias = $this->getRootAlias(); $subRootAlias = $subRootAlias ? $subRootAlias . '.' . $rel->name : $rel->name; $subQuery = new self($rel->lm->class, $subRootAlias); $subQuery->setConnection($this->getConnection()); $subQuery->newSelect(); $subQuery->whereRelation($rel, $mainQueryRootAlias); $subQuery->getQuery()->getCompiler()->useTableAlias = true; $mainQuery->getQuery()->getCompiler()->useTableAlias = true; if ($rels) { $relation = implode('/', $rels); $subQuery->whereHas($relation); } // We want a Count sub-query. if ($op !== null && $value !== null) { $subQuery->getQuery()->addAggregate('COUNT'); $mainQuery->selectSub($subQuery->getQuery(), '#' . $relation); $mainQuery->where(DB::expr('#' . $relation), $op, $value, null, $not); } else { if ($op instanceof \Closure) { $op($subQuery); } $subQuery->get(array('*'), false); $mainQuery->whereExists($subQuery->getQuery(), null, $not); } return $this; }
/** * Resolve a base URI with a relative URI and return a new URI. * * @param UriInterface $base Base URI * @param string|UriInterface $rel Relative URI * * @return UriInterface * @link http://tools.ietf.org/html/rfc3986#section-5.2 */ public static function resolve(UriInterface $base, $rel) { if (!$rel instanceof UriInterface) { $rel = new self($rel); } if ((string) $rel === '') { // we can simply return the same base URI instance for this same-document reference return $base; } if ($rel->getScheme() != '') { return $rel->withPath(self::removeDotSegments($rel->getPath())); } if ($rel->getAuthority() != '') { $targetAuthority = $rel->getAuthority(); $targetPath = self::removeDotSegments($rel->getPath()); $targetQuery = $rel->getQuery(); } else { $targetAuthority = $base->getAuthority(); if ($rel->getPath() === '') { $targetPath = $base->getPath(); $targetQuery = $rel->getQuery() != '' ? $rel->getQuery() : $base->getQuery(); } else { if ($rel->getPath()[0] === '/') { $targetPath = $rel->getPath(); } else { if ($targetAuthority != '' && $base->getPath() === '') { $targetPath = '/' . $rel->getPath(); } else { $lastSlashPos = strrpos($base->getPath(), '/'); if ($lastSlashPos === false) { $targetPath = $rel->getPath(); } else { $targetPath = substr($base->getPath(), 0, $lastSlashPos + 1) . $rel->getPath(); } } } $targetPath = self::removeDotSegments($targetPath); $targetQuery = $rel->getQuery(); } } return new self(self::createUriString($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment())); }
/** * Add a field subquery to the query itself. The phrase will be splited by words * * @param string $field * @param string $phrase * @param string $type : OR | AND operator * @param string $inner_type : OR | AND operator * @return sfLuceneCriteria */ public function addFieldSane($field, $phrase, $type = sfLuceneCriteria::TYPE_AND, $inner_type = sfLuceneCriteria::TYPE_OR) { $keywords = preg_split("/[\\ ,\\.]+/", $phrase); $c = new self(); foreach ($keywords as $keyword) { $c->add(self::sanitize($keyword), $inner_type, true); } $this->addField($field, $c->getQuery(), $type, true); return $this; }