当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Db_Expr::__toString方法代码示例

本文整理汇总了PHP中Zend_Db_Expr::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Expr::__toString方法的具体用法?PHP Zend_Db_Expr::__toString怎么用?PHP Zend_Db_Expr::__toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Db_Expr的用法示例。


在下文中一共展示了Zend_Db_Expr::__toString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getCaseCondition

 /**
  * Строит sql CASE WHEN .. THEN .. ELSE .. END для секции SELECT
  * т.е. на основаниие весов атрибутов строит части запроса для вычесления релевантности.
  *
  * @param string $query      оригинальный запрос
  * @param array  $arQuery    подготовленный запрос
  * @param array  $attributes атрибуты с весом
  *
  * @return string
  */
 protected function _getCaseCondition($query, $arQuery, $attributes)
 {
     $uid = Mage::helper('mstcore/debug')->start();
     $select = '';
     $cases = array();
     $fullCases = array();
     $words = Mage::helper('core/string')->splitWords($query, true);
     foreach ($attributes as $attr => $weight) {
         if ($weight == 0) {
             continue;
         }
         $cases[$weight * 4][] = $this->getCILike('s.' . $attr, $query);
         $cases[$weight * 3][] = $this->getCILike('s.' . $attr, ' ' . $query . ' ', array('position' => 'any'));
     }
     foreach ($words as $word) {
         foreach ($attributes as $attr => $weight) {
             $w = intval($weight / count($arQuery));
             if ($w == 0) {
                 continue;
             }
             $cases[$w][] = $this->getCILike('s.' . $attr, $word, array('position' => 'any'));
             $cases[$w + 1][] = $this->getCILike('s.' . $attr, ' ' . $word . ' ', array('position' => 'any'));
         }
     }
     foreach ($words as $word) {
         foreach ($attributes as $attr => $weight) {
             $w = intval($weight / count($arQuery));
             if ($w == 0) {
                 continue;
             }
             // $locate = new Zend_Db_Expr('LOCATE("'.$word.'", s.'.$attr.')');
             // $cases[$w.'-'.$locate->__toString()][] = $locate;
             $locate = new Zend_Db_Expr('(LENGTH(s.' . $attr . ') - LOCATE("' . addslashes($word) . '", s.' . $attr . ')) / LENGTH(s.' . $attr . ')');
             $cases[$w . '*' . $locate->__toString()][] = $locate;
         }
     }
     foreach ($cases as $weight => $conds) {
         foreach ($conds as $cond) {
             $fullCases[] = 'CASE WHEN ' . $cond . ' THEN ' . $weight . ' ELSE 0 END';
         }
     }
     if (count($fullCases)) {
         $select = '(' . implode('+', $fullCases) . ')';
     } else {
         $select = new Zend_Db_Expr('0');
     }
     Mage::helper('mstcore/debug')->end($uid, (string) $select);
     return $select;
 }
开发者ID:vishalpatel14,项目名称:indiankalaniketan,代码行数:59,代码来源:Fulltext.php

示例2: _quoteIdentifierAs

 /**
  * Quote an identifier and an optional alias.
  *
  * @param string|array|Zend_Db_Expr $ident The identifier or expression.
  * @param string $alias An optional alias.
  * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  * @param string $as The string to add between the identifier/expression and the alias.
  * @return string The quoted identifier and alias.
  */
 protected function _quoteIdentifierAs($ident, $alias = null, $auto = false, $as = ' AS ')
 {
     if ($ident instanceof Zend_Db_Expr) {
         $quoted = $ident->__toString();
     } elseif ($ident instanceof Zend_Db_Select) {
         $quoted = '(' . $ident->assemble() . ')';
     } else {
         if (is_string($ident)) {
             $ident = explode('.', $ident);
         }
         if (is_array($ident)) {
             $segments = array();
             foreach ($ident as $segment) {
                 if ($segment instanceof Zend_Db_Expr) {
                     $segments[] = $segment->__toString();
                 } else {
                     $segments[] = $this->_quoteIdentifier($segment, $auto);
                 }
             }
             if ($alias !== null && end($ident) == $alias) {
                 $alias = null;
             }
             $quoted = implode('.', $segments);
         } else {
             $quoted = $this->_quoteIdentifier($ident, $auto);
         }
     }
     if ($alias !== null) {
         $quoted .= $as . $this->_quoteIdentifier($alias, $auto);
     }
     return $quoted;
 }
开发者ID:Gradven,项目名称:what3.1.7,代码行数:41,代码来源:Abstract.php

示例3: order

 /**
  * Adds a row order to the query.
  *
  * @param mixed $spec The column(s) and direction to order by.
  * @return Zend_Db_Select This Zend_Db_Select object.
  */
 public function order($spec)
 {
     if (!is_array($spec)) {
         $spec = array($spec);
     }
     // force 'ASC' or 'DESC' on each order spec, default is ASC.
     foreach ($spec as $val) {
         if (preg_match('/\\(.*\\)/', $val)) {
             $val = new Zend_Db_Expr($val);
         }
         if ($val instanceof Zend_Db_Expr) {
             $expr = $val->__toString();
             if (empty($expr)) {
                 continue;
             }
             $this->_parts[self::ORDER][] = $val;
         } else {
             if (empty($val)) {
                 continue;
             }
             $direction = 'ASC';
             if (preg_match('/(.*)\\s+(ASC|DESC)\\s*$/i', $val, $matches)) {
                 $val = trim($matches[1]);
                 $direction = $matches[2];
             }
             $this->_parts[self::ORDER][] = array(trim($val), $direction);
         }
     }
     return $this;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:36,代码来源:Select.php

示例4: processOrCombination

 /**
  * process Or combination on collection.
  *
  * @param $collection
  * @param $conditions
  * @param $type
  *
  * @return mixed
  */
 public function processOrCombination($collection, $conditions, $type)
 {
     $fieldsConditions = [];
     $multiFieldsConditions = [];
     foreach ($conditions as $condition) {
         $attribute = $condition['attribute'];
         $cond = $condition['conditions'];
         $value = $condition['cvalue'];
         //ignore condition if value is null or empty
         if ($value == '' or $value == null) {
             continue;
         }
         if ($type == self::REVIEW && isset($this->attributeMapForQuote[$attribute])) {
             $attribute = $this->attributeMapForOrder[$attribute];
         } elseif ($type == self::ABANDONED && isset($this->attributeMapForOrder[$attribute])) {
             $attribute = $this->attributeMapForQuote[$attribute];
         } else {
             $this->productAttribute[] = $condition;
             continue;
         }
         if ($cond == 'null') {
             if ($value == '1') {
                 if (isset($fieldsConditions[$attribute])) {
                     $multiFieldsConditions[$attribute] = ['notnull' => true];
                     continue;
                 }
                 $fieldsConditions[$attribute] = ['notnull' => true];
             } elseif ($value == '0') {
                 if (isset($fieldsConditions[$attribute])) {
                     $multiFieldsConditions[$attribute] = [$cond => true];
                     continue;
                 }
                 $fieldsConditions[$attribute] = [$cond => true];
             }
         } else {
             if ($cond == 'like' or $cond == 'nlike') {
                 $value = '%' . $value . '%';
             }
             if (isset($fieldsConditions[$attribute])) {
                 $multiFieldsConditions[$attribute] = [$this->conditionMap[$cond] => $value];
                 continue;
             }
             $fieldsConditions[$attribute] = [$this->conditionMap[$cond] => $value];
         }
     }
     //all rules condition will be with or combination
     if (!empty($fieldsConditions)) {
         $column = [];
         $cond = [];
         foreach ($fieldsConditions as $key => $fieldsCondition) {
             $exp = new \Zend_Db_Expr($key);
             $column[] = $exp->__toString();
             $cond[] = $fieldsCondition;
         }
         if (!empty($multiFieldsConditions)) {
             foreach ($multiFieldsConditions as $key => $multiFieldsCondition) {
                 if (in_array($key, $column)) {
                     $exp = new \Zend_Db_Expr($key);
                     $column[] = $exp->__toString();
                     $cond[] = $multiFieldsCondition;
                     continue;
                 }
             }
         }
         $collection->addFieldToFilter($column, $cond);
     }
     return $this->_processProductAttributes($collection);
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:77,代码来源:Rules.php

示例5: getScoreQuery

 /**
  * @param array $columns
  * @param string $query
  * @return string
  */
 public function getScoreQuery($columns, $query)
 {
     $cases = [];
     $fullCases = [];
     $words = preg_split('#\\s#siu', $query, null, PREG_SPLIT_NO_EMPTY);
     foreach ($columns as $column) {
         $cases[5][] = $this->dbHelper->getCILike($column, ' ' . $query . ' ');
     }
     foreach ($words as $word) {
         foreach ($columns as $column) {
             $cases[3][] = $this->dbHelper->getCILike($column, ' ' . $word . ' ', ['position' => 'any']);
             $cases[2][] = $this->dbHelper->getCILike($column, $word, ['position' => 'any']);
         }
     }
     foreach ($words as $word) {
         foreach ($columns as $column) {
             $e = '(LENGTH(' . $column . ')';
             $e .= '- LOCATE("' . addslashes($word) . '", ' . $column . ')) / LENGTH(' . $column . ')';
             $locate = new \Zend_Db_Expr($e);
             $cases[$locate->__toString()][] = $locate;
         }
     }
     foreach ($cases as $weight => $conditions) {
         foreach ($conditions as $condition) {
             $fullCases[] = 'CASE WHEN ' . $condition . ' THEN ' . $weight . ' ELSE 0 END';
         }
     }
     if (count($fullCases)) {
         $select = '(' . implode('+', $fullCases) . ')';
     } else {
         $select = '0';
     }
     return $select;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:39,代码来源:Match.php

示例6: _quoteIdentifierAs

 /**
  * Quote an identifier and an optional alias.
  *
  * @param string|array|Zend_Db_Expr $ident The identifier or expression.
  * @param string $alias An optional alias.
  * @param string $as The string to add between the identifier/expression and the alias.
  * @return string The quoted identifier and alias.
  */
 protected function _quoteIdentifierAs($ident, $alias = null, $as = ' AS ')
 {
     $q = $this->getQuoteIdentifierSymbol();
     if ($ident instanceof Zend_Db_Expr) {
         $quoted = $ident->__toString();
     } else {
         if (is_string($ident)) {
             $ident = explode('.', $ident);
         }
         if (is_array($ident)) {
             $segments = array();
             foreach ($ident as $segment) {
                 if ($segment instanceof Zend_Db_Expr) {
                     $segments[] = $segment->__toString();
                 } else {
                     $segments[] = $q . str_replace("{$q}", "{$q}{$q}", $segment) . $q;
                 }
             }
             if ($alias !== null && end($ident) == $alias) {
                 $alias = null;
             }
             $quoted = implode('.', $segments);
         } else {
             $quoted = $q . str_replace("{$q}", "{$q}{$q}", $ident) . $q;
         }
     }
     if ($alias !== null) {
         $quoted .= $as . $q . str_replace("{$q}", "{$q}{$q}", $alias) . $q;
     }
     return $quoted;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:39,代码来源:Abstract.php

示例7: quoteIdentifier

 /**
  * Quotes an identifier.
  *
  * @param string|Zend_Db_Expr $ident The identifier.
  * @return string The quoted identifier.
  */
 public function quoteIdentifier($ident)
 {
     if ($ident instanceof Zend_Db_Expr) {
         return $ident->__toString();
     }
     $q = $this->getQuoteIdentifierSymbol();
     $ident = str_replace("{$q}", "{$q}{$q}", $ident);
     return $q . $ident . $q;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:15,代码来源:Abstract.php


注:本文中的Zend_Db_Expr::__toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。