本文整理汇总了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;
});
});
}
示例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;
}
示例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]);
}
}
}
示例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;
}
示例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]);
}
示例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']);
}
示例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]);
}
示例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);
});
}
示例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;
}
示例10: findByAuthor
public function findByAuthor(Query $query, array $options = [])
{
if (isset($options['author_id'])) {
$query->where(['Articles.id' => $options['author_id']]);
}
return $query;
}
示例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')]);
}
}
示例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']]);
}
示例13: _addParametersToQuery
public function _addParametersToQuery(Query $query, $restrictTo = [])
{
$parameters = $this->request->query;
$parameters = $this->_restrictTo($parameters, $restrictTo);
$query->where($parameters);
return $query;
}
示例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;
}
示例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;
}