Exemple #1
0
 /**
  * Returns the search results for the given SQL statement.
  *
  * @param MW_DB_Connection_Interface $conn Database connection
  * @param $sql SQL statement
  * @return MW_DB_Result_Interface Search result object
  */
 protected function _getSearchResults(MW_DB_Connection_Interface $conn, $sql)
 {
     $statement = $conn->create($sql);
     $this->_getContext()->getLogger()->log(__METHOD__ . ': SQL statement: ' . $statement, MW_Logger_Abstract::DEBUG);
     $results = $statement->execute();
     return $results;
 }
Exemple #2
0
 /**
  * Returns the search result of the statement combined with the given criteria.
  *
  * @param MW_DB_Connection_Interface $conn Database connection
  * @param MW_Common_Criteria_Interface $search Search criteria
  * @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 MShop_Locale_Manager_Abstract for defining which site IDs should be used for searching
  * @return MW_DB_Result_Interface SQL result object for accessing the found records
  * @throws MShop_Exception if no number of all matching records is available
  */
 protected function _searchItems(MW_DB_Connection_Interface $conn, MW_Common_Criteria_Interface $search, $cfgPathSearch, $cfgPathCount, array $required, &$total = null, $sitelevel = MShop_Locale_Manager_Abstract::SITE_ONE, array $plugins = array())
 {
     $joins = $cond = array();
     $sep = $this->_getKeySeparator();
     $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));
         }
         $name = $key . $sep . 'siteid';
         if (isset($attributes[$name])) {
             $cond[] = $search->compare('==', $name, $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);
     }
     if ($total !== null) {
         $sql = new MW_Template_SQL($this->_context->getConfig()->get($cfgPathCount, $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, MW_Logger_Abstract::DEBUG);
         if ($row === false) {
             throw new MShop_Exception(sprintf('Total results value not found'));
         }
         $total = (int) $row['count'];
     }
     $sql = new MW_Template_SQL($this->_context->getConfig()->get($cfgPathSearch, $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, MW_Logger_Abstract::DEBUG);
     return $results;
 }
Exemple #3
0
 /**
  * Returns the search result object for the given SQL statement.
  *
  * @param MW_DB_Connection_Interface $conn Database connection
  * @param string $sql SQL-statement to execute
  * @return MW_DB_Result_Interface Returns db result set from given sql statment
  */
 protected function _getSearchResults(MW_DB_Connection_Interface $conn, $sql)
 {
     $context = $this->_getContext();
     $statement = $conn->create($sql);
     try {
         $statement->bind(1, $context->getLocale()->getSiteId(), MW_DB_Statement_Abstract::PARAM_INT);
     } catch (Exception $e) {
         $statement->bind(1, null, MW_DB_Statement_Abstract::PARAM_INT);
     }
     return $statement->execute();
 }
Exemple #4
0
 /**
  * Returns the search result object for the given SQL statement.
  *
  * @param MW_DB_Connection_Interface $conn Database connection
  * @param string $sql SQL-statement to execute
  * @return MW_DB_Result_Interface Returns db result set from given sql statment
  */
 protected function _getSearchResults(MW_DB_Connection_Interface $conn, $sql)
 {
     $context = $this->_getContext();
     $siteId = $context->getLocale()->getSiteId();
     $statement = $conn->create($sql);
     $statement->bind(1, $siteId, MW_DB_Statement_Abstract::PARAM_INT);
     $context->getLogger()->log(__METHOD__ . ': SQL statement: ' . $statement, MW_Logger_Abstract::DEBUG);
     return $statement->execute();
 }