當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query::orWhere方法代碼示例

本文整理匯總了PHP中Cake\ORM\Query::orWhere方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::orWhere方法的具體用法?PHP Query::orWhere怎麽用?PHP Query::orWhere使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\ORM\Query的用法示例。


在下文中一共展示了Query::orWhere方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: scope

 /**
  * {@inheritDoc}
  */
 public function scope(Query $query, TokenInterface $token)
 {
     $column = $this->config('field');
     $value = $token->value();
     if (!$column || empty($value)) {
         return $query;
     }
     $tableAlias = $this->_table->alias();
     $range = $this->_parseRange($token->value());
     if ($range['lower'] !== $range['upper']) {
         $conjunction = $token->negated() ? 'AND NOT' : 'AND';
         $conditions = ["{$conjunction}" => ["{$tableAlias}.{$column} >=" => $range['lower'], "{$tableAlias}.{$column} <=" => $range['upper']]];
     } else {
         $cmp = $token->negated() ? '<=' : '>=';
         $conditions = ["{$tableAlias}.{$column} {$cmp}" => $range['lower']];
     }
     if ($token->where() === 'or') {
         $query->orWhere($conditions);
     } elseif ($token->where() === 'and') {
         $query->andWhere($conditions);
     } else {
         $query->where($conditions);
     }
     return $query;
 }
開發者ID:quickapps-plugins,項目名稱:search,代碼行數:28,代碼來源:RangeOperator.php

示例2: scope

 /**
  * {@inheritDoc}
  */
 public function scope(Query $query, TokenInterface $token)
 {
     list($conjunction, $value) = $this->_prepareConjunction($token);
     $subQuery = TableRegistry::get('Clients.ClientsRecords')->find()->contain(['Client'])->select(['ClientsRecords.record_id'])->where(['OR' => ["Client.name {$conjunction}" => $value, "Client.lastname {$conjunction}" => $value]]);
     $conditions = ['SearchDatasets.entity_id IN' => $subQuery];
     if ($token->where() === 'or') {
         $query->orWhere($conditions);
     } elseif ($token->where() === 'and') {
         $query->andWhere($conditions);
     }
     return $query->where($conditions);
 }
開發者ID:ChristopherCastro,項目名稱:gencon,代碼行數:15,代碼來源:ClienteOperator.php

示例3: findByLookupFields

 /**
  * Method that adds lookup fields with the id value to the Where clause in ORM Query
  *
  * @param  \Cake\ORM\Query $query Query instance
  * @param  string          $id    Record id
  * @return \Cake\ORM\Query
  */
 public function findByLookupFields(Query $query, $id)
 {
     $lookupFields = $this->lookupFields();
     if (empty($lookupFields)) {
         return $query;
     }
     $tableName = $this->alias();
     // check for record by table's lookup fields
     foreach ($lookupFields as $lookupField) {
         // prepend table name to avoid CakePHP ORM's ambiguous column errors
         if (false === strpos($lookupField, '.')) {
             $lookupField = $tableName . '.' . $lookupField;
         }
         $query->orWhere([$lookupField => $id]);
     }
     return $query;
 }
開發者ID:QoboLtd,項目名稱:cakephp-csv-migrations,代碼行數:24,代碼來源:FieldTrait.php

示例4: scope

 /**
  * {@inheritDoc}
  */
 public function scope(Query $query, TokenInterface $token)
 {
     $column = $this->config('field');
     $value = $token->value();
     if (!$column || empty($value)) {
         return $query;
     }
     list($conjunction, $value) = $this->_prepareConjunction($token);
     $tableAlias = $this->_table->alias();
     $conditions = ["{$tableAlias}.{$column} {$conjunction}" => $value];
     if ($token->where() === 'or') {
         $query->orWhere($conditions);
     } elseif ($token->where() === 'and') {
         $query->andWhere($conditions);
     } else {
         $query->where($conditions);
     }
     return $query;
 }
開發者ID:quickapps-plugins,項目名稱:search,代碼行數:22,代碼來源:GenericOperator.php

示例5: operatorTerm

 /**
  * Handles the "term:" search operator. Which filters all entities matching
  * a given collection of terms.
  *
  *     term:cat,dog,bird,...,term-slug
  *
  * You can provide up to 10 terms as maximum.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Query $query The query being scoped
  * @param \Search\Token $token Operator token
  * @return \Cake\ORM\Query Scoped query
  */
 public function operatorTerm(Event $event, $query, $token)
 {
     $slugs = explode(',', $token->value());
     $slugs = array_slice($slugs, 0, 10);
     if (!empty($slugs)) {
         $IN = $token->negated() ? 'NOT IN' : 'IN';
         $table = $event->subject();
         $pk = $table->primaryKey();
         $tableAlias = $table->alias();
         $termsIds = TableRegistry::get('Taxonomy.Terms')->find()->select(['id'])->where(['Terms.slug IN' => $slugs])->all()->extract('id')->toArray();
         $termsIds = empty($termsIds) ? [0] : $termsIds;
         $subQuery = TableRegistry::get('Taxonomy.EntitiesTerms')->find()->select(['entity_id'])->where(['term_id IN' => $termsIds, 'table_alias' => $tableAlias]);
         if ($token->where() === 'or') {
             $query->orWhere(["{$tableAlias}.{$pk} {$IN}" => $subQuery]);
         } elseif ($token->where() === 'and') {
             $query->andWhere(["{$tableAlias}.{$pk} {$IN}" => $subQuery]);
         } else {
             $query->where(["{$tableAlias}.{$pk} {$IN}" => $subQuery]);
         }
     }
     return $query;
 }
開發者ID:quickapps-plugins,項目名稱:taxonomy,代碼行數:35,代碼來源:TaxonomyHook.php

示例6: findByLookupFieldsWithValues

 /**
  * Method that adds lookup fields with the matching values to the Where clause in ORM Query
  *
  * @param  \Cake\ORM\Query $query  Query instance
  * @param  array           $values Entity lookup-fields values
  * @return \Cake\ORM\Query
  */
 public function findByLookupFieldsWithValues(Query $query, array $values)
 {
     $lookupFields = $this->lookupFields();
     if (empty($lookupFields) || empty($values)) {
         return $query;
     }
     // check for record by table's lookup fields
     foreach ($lookupFields as $lookupField) {
         if (!isset($values[$lookupField])) {
             continue;
         }
         $query->orWhere([$lookupField => $values[$lookupField]]);
     }
     return $query;
 }
開發者ID:QoboLtd,項目名稱:cakephp-csv-migrations,代碼行數:22,代碼來源:Table.php

示例7: operatorterm

 /**
  * Handles "term" search operator.
  *
  *     term:term1-slug,term2-slug,...
  *
  * @param \Cake\ORM\Query $query The query object
  * @param \Search\Parser\TokenInterface $token Operator token
  * @return \Cake\ORM\Query
  */
 public function operatorterm(Query $query, TokenInterface $token)
 {
     $terms = explode(',', strtolower($token->value()));
     $conjunction = $token->negated() ? 'NOT IN' : 'IN';
     if (empty($terms)) {
         return $query;
     }
     $conditions = ["Contents.id {$conjunction}" => TableRegistry::get('Taxonomy.EntitiesTerms')->find()->select(['EntitiesTerms.entity_id'])->where(['EntitiesTerms.table_alias' => $this->alias()])->matching('Terms', function ($q) use($terms) {
         return $q->where(['Terms.slug IN' => $terms]);
     })];
     if (!empty($conditions)) {
         if ($token->where() === 'or') {
             $query->orWhere($conditions);
         } elseif ($token->where() === 'and') {
             $query->andWhere($conditions);
         } else {
             $query->where($conditions);
         }
     }
     return $query;
 }
開發者ID:quickapps-plugins,項目名稱:content,代碼行數:30,代碼來源:ContentsTable.php

示例8: findAuth

 /**
  * Custom finder to log in users
  *
  * @param Query $query Query object to modify
  * @param array $options Query options
  * @return Query
  * @throws \BadMethodCallException
  */
 public function findAuth(Query $query, array $options = [])
 {
     $identifier = Hash::get($options, 'username');
     if (empty($identifier)) {
         throw new \BadMethodCallException(__d('CakeDC/Users', 'Missing \'username\' in options data'));
     }
     $query->orWhere([$this->aliasField('email') => $identifier])->find('active', $options);
     return $query;
 }
開發者ID:cakedc,項目名稱:users,代碼行數:17,代碼來源:UsersTable.php

示例9: _scopeWordsInFulltext

 /**
  * Similar to "_scopeWords" but using MySQL's fulltext indexes.
  *
  * @param \Cake\ORM\Query $query The query to scope
  * @param \Search\TokenInterface $token Token describing a words sequence. e.g `this is a phrase`
  * @return \Cake\ORM\Query Scoped query
  */
 protected function _scopeWordsInFulltext(Query $query, TokenInterface $token)
 {
     $value = str_replace(['*', '!'], ['*', '*'], $token->value());
     $value = mb_strpos($value, '+') === 0 ? mb_substr($value, 1) : $value;
     if (empty($value) || in_array($value, $this->_stopWords())) {
         return $query;
     }
     $not = $token->negated() ? 'NOT' : '';
     $value = str_replace("'", '"', $value);
     $conditions = ["{$not} MATCH(SearchDatasets.words) AGAINST('{$value}' IN BOOLEAN MODE) > 0"];
     if ($token->where() === 'or') {
         $query->orWhere($conditions);
     } elseif ($token->where() === 'and') {
         $query->andWhere($conditions);
     } else {
         $query->where($conditions);
     }
     return $query;
 }
開發者ID:quickapps-plugins,項目名稱:search,代碼行數:26,代碼來源:GenericEngine.php


注:本文中的Cake\ORM\Query::orWhere方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。