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


PHP Query::where方法代码示例

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


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

示例1: findRecent

 /**
  * Custom finder method, returns recent to-do's based on status
  *
  * @param Query $query  cakephp query object
  * @param array $options list of options
  * @return query $query cakephp query object
  */
 public function findRecent(Query $query, array $options = ['status' => 0])
 {
     return $query->where(['is_done' => $options['status']])->order(['updated' => 'DESC'])->formatResults(function ($results, $query) {
         return $results->map(function ($row) {
             $timeCreated = new Time($row->created);
             $timeUpdated = new Time($row->updated);
             $row->created = $timeCreated->timeAgoInWords();
             $row->updated = $timeUpdated->timeAgoInWords();
             $row->todo = htmlspecialchars($row->todo);
             return $row;
         });
     });
 }
开发者ID:surjit,项目名称:todo,代码行数:20,代码来源:TodosTable.php

示例2: findBetween

 public function findBetween(Query $query, array $options)
 {
     if (array_key_exists('start', $options)) {
         $query->where(['Requests.created <=' => new DateTime($options['start'])]);
     }
     if (array_key_exists('end', $options)) {
         $query->where(['Requests.created >=' => new DateTime($options['end'])]);
     }
     return $query;
 }
开发者ID:jxav,项目名称:cakephp-analyzer,代码行数:10,代码来源:RequestsTable.php

示例3: beforeFind

 /**
  * beforeFind
  * @param Event $event
  * @param Query $query
  * @param ArrayObject $options
  * @param $primary
  */
 public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
 {
     $getOptions = $query->getOptions();
     if (!array_key_exists('enableSoftDelete', $getOptions) || $getOptions['enableSoftDelete'] == true) {
         $modelName = $this->_table->alias();
         $booleanField = $this->config('boolean');
         $timestampField = $this->config('timestamp');
         if ($booleanField !== false && $this->_table->hasField($booleanField)) {
             $query->where([$modelName . '.' . $booleanField => false]);
         }
         if ($booleanField === false && $timestampField !== false && $this->_table->hasField($timestampField)) {
             $query->where([$modelName . '.' . $timestampField . ' IS' => null]);
         }
     }
 }
开发者ID:fusic,项目名称:reincarnation,代码行数:22,代码来源:SoftDeleteBehavior.php

示例4: 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

示例5: _buildQuery

 /**
  * Returns query with applied filter
  *
  * @param \Cake\ORM\Query $query Query.
  * @param string $field Field name.
  * @param string $value Field value.
  * @param array $data Filters values.
  * @return \Cake\ORM\Query
  */
 protected function _buildQuery(Query $query, $field, $value, array $data = [])
 {
     if (is_array($value)) {
         $field .= ' IN';
     }
     return $query->where([$field => $value]);
 }
开发者ID:kajko1973,项目名称:plum_search,代码行数:16,代码来源:ValueFilter.php

示例6: findByRequest

 /**
  * Find panels by requestid
  *
  * @param Cake\ORM\Query $query The query
  * @param array $options The options to use.
  * @return Cake\ORM\Query The query.
  * @throws \RuntimeException
  */
 public function findByRequest(Query $query, array $options)
 {
     if (empty($options['requestId'])) {
         throw new \RuntimeException('Missing request id in findByRequest.');
     }
     return $query->where(['Panels.request_id' => $options['requestId']])->order(['Panels.title' => 'ASC']);
 }
开发者ID:meotimdihia,项目名称:cakephp-test-elasticsearch,代码行数:15,代码来源:PanelsTable.php

示例7: findVisible

 /**
  * Filters Query to only show records that are marked visible
  * exposed to tables as `$table->find('visible')`
  * @param Query $query
  * @param array $options
  * @return Query
  */
 public function findVisible(Query $query, array $options)
 {
     # get the merged (possibly customized) config values
     $config = $this->config();
     # filter the query by visibility
     return $query->where(["{$this->_table->alias()}.{$config['field']}" => true]);
 }
开发者ID:cwbit,项目名称:cakephp-visibility,代码行数:14,代码来源:VisibilityBehavior.php

示例8: _buildQuery

 /**
  * Returns query with applied filter
  *
  * @param  \Cake\ORM\Query $query Query.
  * @param  string $field Field name.
  * @param  string $value Field value.
  * @param  array  $data Filters values.
  * @return \Cake\ORM\Query
  */
 protected function _buildQuery(Query $query, $field, $value, array $data = [])
 {
     $value = '%' . $value . '%';
     return $query->where(function ($exp) use($field, $value) {
         return $exp->like($field, $value);
     });
 }
开发者ID:kajko1973,项目名称:plum_search,代码行数:16,代码来源:LikeFilter.php

示例9: findTasksByProject

 /**
  * Find all tasks grouped by project
  * 
  * @param Query $query
  * @param type $options
  * @return Query
  */
 public function findTasksByProject(Query $query, $options = [])
 {
     $options += ['where' => NULL];
     $query->find('list', ['groupField' => 'project_id']);
     $query->where($options['where']);
     return $query;
 }
开发者ID:OrigamiStructures,项目名称:foldingTime,代码行数:14,代码来源:TasksTable.php

示例10: findByAuthor

 public function findByAuthor(Query $query, array $options = [])
 {
     if (isset($options['author_id'])) {
         $query->where(['Articles.id' => $options['author_id']]);
     }
     return $query;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:7,代码来源:AuthorsTable.php

示例11: checkRecordAccess

 /**
  * Check
  *
  * @param \Cake\Event\Event $event The beforeFind event that was fired.
  * @param \Cake\ORM\Query $query Query
  * @param \ArrayObject $options The options for the query
  * @return void
  */
 public function checkRecordAccess(Event $event, Query $query, ArrayObject $options)
 {
     $table = TableRegistry::get('RolesCapabilities.Capabilities');
     // current request parameters
     $request = $table->getCurrentRequest();
     // skip if current model does not match request's model
     if (array_diff(pluginSplit($event->subject()->registryAlias()), [$request['plugin'], $request['controller']])) {
         return;
     }
     // get capability owner type identifier
     $type = $table->getTypeOwner();
     // get user's action capabilities
     $userActionCapabilities = $table->getUserActionCapabilities();
     // skip if no user's action capabilities found or no user's action
     // owner specific capabilities found for current request's action
     if (empty($userActionCapabilities)) {
         return;
     }
     if (!isset($userActionCapabilities[$request['plugin']][$request['controller']][$request['action']][$type])) {
         return;
     }
     // set query where clause based on user's owner capabilities assignment fields
     foreach ($userActionCapabilities[$request['plugin']][$request['controller']][$request['action']][$type] as $userActionCapability) {
         $query->where([$userActionCapability->getField() => $table->getCurrentUser('id')]);
     }
 }
开发者ID:QoboLtd,项目名称:cakephp-roles-capabilities,代码行数:34,代码来源:ModelBeforeFindEventsListener.php

示例12: findForUser

 /**
  * forUser finder method
  *
  * It will find all todos for a given user id
  *
  * @param Query $q The Query builder
  * @param $options The options should have an index `id`
  * @return Query
  */
 public function findForUser(Query $query, $options)
 {
     if (!isset($options['id'])) {
         throw new \InvalidArgumentException("You should provide an user id through \$options\\['id'\\]");
     }
     return $query->where(['user_id' => $options['id']]);
 }
开发者ID:pedrofs,项目名称:cakedone,代码行数:16,代码来源:TodosTable.php

示例13: _addParametersToQuery

 public function _addParametersToQuery(Query $query, $restrictTo = [])
 {
     $parameters = $this->request->query;
     $parameters = $this->_restrictTo($parameters, $restrictTo);
     $query->where($parameters);
     return $query;
 }
开发者ID:abf6ug,项目名称:statbro,代码行数:7,代码来源:AppController.php

示例14: beforeFind

 /**
  * beforeFind callback
  *
  * inject where condition if context is 'tenant'
  *
  * @param \Cake\Event\Event $event The beforeFind event that was fired.
  * @param \Cake\ORM\Query $query The query.
  * @return void
  */
 public function beforeFind(Event $event, Query $query)
 {
     if (MTApp::getContext() == 'tenant') {
         $query->where([$this->_table->alias() . '.' . $this->config('foreign_key_field') . ' IN' => [$this->config('global_value'), MTApp::tenant()->id]]);
     }
     return $query;
 }
开发者ID:pdata,项目名称:multitenant,代码行数:16,代码来源:MixedScopeBehavior.php

示例15: findAuthor

 /**
  * Custom finder, used with fixture data to ensure Paginator is sending options
  *
  * @param Cake\ORM\Query $query
  * @param array $options
  * @return Cake\ORM\Query
  */
 public function findAuthor(Query $query, array $options = [])
 {
     if (isset($options['author_id'])) {
         $query->where(['PaginatorPosts.author_id' => $options['author_id']]);
     }
     return $query;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:14,代码来源:PaginatorPostsTable.php


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