/** * Adds the conditions for the selected attributes to the given search filter. * * @param array $params Associative list of parameters that should be used for filtering * @param \Aimeos\MW\Criteria\Iface $filter Criteria object for searching */ protected function addAttributeFilterByParam(array $params, \Aimeos\MW\Criteria\Iface $filter) { $attrids = isset($params['f_attrid']) ? (array) $params['f_attrid'] : array(); if (!empty($attrids)) { $func = $filter->createFunction('index.attributeaggregate', array(array_keys($attrids))); $expr = array($filter->getConditions(), $filter->compare('==', $func, count($attrids))); $filter->setConditions($filter->combine('&&', $expr)); } }
/** * Returns a sorted list of required criteria keys. * * @param \Aimeos\MW\Criteria\Iface $criteria Search criteria object * @param string[] $required List of prefixes of required search conditions * @return string[] Sorted list of criteria keys */ protected function getCriteriaKeyList(\Aimeos\MW\Criteria\Iface $criteria, array $required) { $keys = array_merge($required, $this->getCriteriaKeys($required, $criteria->getConditions())); foreach ($criteria->getSortations() as $sortation) { $keys = array_merge($keys, $this->getCriteriaKeys($required, $sortation)); } $keys = array_unique(array_merge($required, $keys)); sort($keys); return $keys; }
/** * Adds the conditions for the selected attributes to the given search filter. * * @param array $params Associative list of parameters that should be used for filtering * @param \Aimeos\MW\Criteria\Iface $filter Criteria object for searching */ protected function addAttributeFilterByParam(array $params, \Aimeos\MW\Criteria\Iface $filter) { $attrids = array(); if (isset($params['f_attrid'])) { foreach ((array) $params['f_attrid'] as $attrid) { if ($attrid != '') { $attrids[] = (int) $attrid; } } } if (!empty($attrids)) { $func = $filter->createFunction('index.attributeaggregate', array($attrids)); $expr = array($filter->getConditions(), $filter->compare('==', $func, count($attrids))); $filter->setConditions($filter->combine('&&', $expr)); } }
/** * Initializes the criteria object with conditions based on the given parameter. * * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object * @param \stdClass $params Object that may contain the properties "condition", "sort", "dir", "start" and "limit" */ private function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, \stdClass $params) { if (isset($params->condition) && is_object($params->condition)) { $existing = $criteria->getConditions(); $criteria->setConditions($criteria->toConditions((array) $params->condition)); $expr = array($criteria->getConditions(), $existing); $criteria->setConditions($criteria->combine('&&', $expr)); } }
/** * Returns the search result of the statement combined with the given criteria. * * @param \Aimeos\MW\DB\Connection\Iface $conn Database connection * @param \Aimeos\MW\Criteria\Iface $search Search criteria object * @param string $cfgPathSearch Path to SQL statement in configuration for searching * @param string $cfgPathCount Path to SQL statement in configuration for counting * @param string[] $required Additional search keys to add conditions for even if no conditions are available * @param integer|null $total Contains the number of all records matching the criteria if not null * @param integer $sitelevel Constant from \Aimeos\MShop\Locale\Manager\Base for defining which site IDs should be used for searching * @param array $plugins Associative list of item keys and plugin objects implementing \Aimeos\MW\Criteria\Plugin\Iface * @return \Aimeos\MW\DB\Result\Iface SQL result object for accessing the found records * @throws \Aimeos\MShop\Exception if no number of all matching records is available */ protected function searchItemsBase(\Aimeos\MW\DB\Connection\Iface $conn, \Aimeos\MW\Criteria\Iface $search, $cfgPathSearch, $cfgPathCount, array $required, &$total = null, $sitelevel = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL, array $plugins = array()) { $joins = array(); $conditions = $search->getConditions(); $attributes = $this->getSearchAttributes(); $siteIds = $this->getSiteIds($sitelevel); $keys = $this->getCriteriaKeyList($search, $required); $basekey = array_shift($required); foreach ($keys as $key) { if ($key !== $basekey) { $joins = array_merge($joins, $this->getJoins($attributes, $key)); } } $cond = $this->getSearchSiteConditions($search, $keys, $attributes, $siteIds); if ($conditions !== null) { $cond[] = $conditions; } $search = clone $search; $search->setConditions($search->combine('&&', $cond)); $types = $this->getSearchTypes($attributes); $translations = $this->getSearchTranslations($attributes); $find = array(':joins', ':cond', ':start', ':size'); $replace = array(implode("\n", array_unique($joins)), $search->getConditionString($types, $translations, $plugins), $search->getSliceStart(), $search->getSliceSize()); if (count($search->getSortations()) > 0) { $keys[] = 'orderby'; $find[] = ':order'; $replace[] = $search->getSortationString($types, $translations); $keys[] = 'columns'; $find[] = ':columns'; $replace[] = $search->getColumnString($search->getSortations(), $translations); } if ($total !== null) { $sql = new \Aimeos\MW\Template\SQL($this->getSqlConfig($cfgPathCount)); $sql->replace($find, $replace)->enable($keys); $time = microtime(true); $stmt = $conn->create($sql->str()); $results = $stmt->execute(); $row = $results->fetch(); $results->finish(); $this->context->getLogger()->log(__METHOD__ . '(' . (microtime(true) - $time) * 1000 . 'ms): SQL statement: ' . $stmt, \Aimeos\MW\Logger\Base::DEBUG); if ($row === false) { throw new \Aimeos\MShop\Exception(sprintf('Total results value not found')); } $total = (int) $row['count']; } $sql = new \Aimeos\MW\Template\SQL($this->getSqlConfig($cfgPathSearch)); $sql->replace($find, $replace)->enable($keys); $time = microtime(true); $stmt = $conn->create($sql->str()); $results = $stmt->execute(); $this->context->getLogger()->log(__METHOD__ . '(' . (microtime(true) - $time) * 1000 . 'ms): SQL statement: ' . $stmt, \Aimeos\MW\Logger\Base::DEBUG); return $results; }
/** * Returns the given search filter with the conditions attached for filtering by text. * * @param \Aimeos\MW\Criteria\Iface $search Criteria object used for product search * @param string $input Search string entered by the user * @param string $listtype List type of the text associated to the product, usually "default" * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching * @since 2015.08 */ public function addIndexFilterText(\Aimeos\MW\Criteria\Iface $search, $input, $listtype = 'default') { $langid = $this->getContext()->getLocale()->getLanguageId(); $expr = array($search->compare('>', $search->createFunction('index.text.relevance', array($listtype, $langid, $input)), 0)); $expr[] = $search->getConditions(); $search->setConditions($search->combine('&&', $expr)); return $search; }
/** * Initializes the criteria object with conditions based on the given parameter * * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object * @param array $params List of criteria data with condition, sorting and paging */ private function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params) { if (isset($params['filter']) && isset($params['filter']['key'])) { $expr = array(); $existing = $criteria->getConditions(); foreach ((array) $params['filter']['key'] as $idx => $key) { if ($key != '' && isset($params['filter']['op'][$idx]) && $params['filter']['op'][$idx] != '' && isset($params['filter']['val'][$idx])) { $expr[] = $criteria->compare($params['filter']['op'][$idx], $key, $params['filter']['val'][$idx]); } } $expr[] = $existing; $criteria->setConditions($criteria->combine('&&', $expr)); } }
/** * Initializes the criteria object with conditions based on the given parameter * * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object * @param array $params List of criteria data with condition, sorting and paging */ protected function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params) { if (!isset($params['filter'])) { return; } $existing = $criteria->getConditions(); $criteria->setConditions($criteria->toConditions((array) $params['filter'])); $expr = array($criteria->getConditions(), $existing); $criteria->setConditions($criteria->combine('&&', $expr)); }
/** * Returns a node and its descendants depending on the given resource. * * @param integer|null $id Retrieve nodes starting from the given ID * @param integer $level One of the level constants from \Aimeos\MW\Tree\Manager\Base * @param \Aimeos\MW\Criteria\Iface|null $condition Optional criteria object with conditions * @return \Aimeos\MW\Tree\Node\Iface Node, maybe with subnodes */ public function getNode($id = null, $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, \Aimeos\MW\Criteria\Iface $condition = null) { if ($id === null) { if (($node = $this->getRootNode()) === null) { throw new \Aimeos\MW\Tree\Exception('No root node available'); } if ($level === \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE) { return $node; } } else { $node = $this->getNodeById($id); if ($level === \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE) { return $node; } } $id = $node->getId(); $numlevel = $this->getLevelFromConstant($level); $search = $this->createSearch(); if ($condition !== null) { $expr = array($search->getConditions(), $condition->getConditions()); $search->setConditions($search->combine('&&', $expr)); } $types = $this->getSearchTypes($this->searchConfig); $translations = $this->getSearchTranslations($this->searchConfig); $conditions = $search->getConditionString($types, $translations); $conn = $this->dbm->acquire($this->dbname); try { $stmt = $conn->create(str_replace(':cond', $conditions, $this->config['get'])); $stmt->bind(1, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT); $stmt->bind(2, $numlevel, \Aimeos\MW\DB\Statement\Base::PARAM_INT); $result = $stmt->execute(); if (($row = $result->fetch()) === false) { throw new \Aimeos\MW\Tree\Exception(sprintf('No node with ID "%1$d" found', $id)); } $node = $this->createNodeBase($row); $this->createTree($result, $node); $this->dbm->release($conn, $this->dbname); } catch (\Exception $e) { $this->dbm->release($conn, $this->dbname); throw $e; } return $node; }
/** * Initializes the criteria object with conditions based on the given parameter * * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object * @param array $params List of criteria data with condition, sorting and paging */ private function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params) { if (isset($params['filter']) && is_array($params['filter'])) { $existing = $criteria->getConditions(); $criteria->setConditions($criteria->toConditions((array) $params['filter'])); $expr = array($criteria->getConditions(), $existing); $criteria->setConditions($criteria->combine('&&', $expr)); } }