本文整理汇总了PHP中Cake\ORM\Query::newExpr方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::newExpr方法的具体用法?PHP Query::newExpr怎么用?PHP Query::newExpr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::newExpr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findDistance
/**
* Custom finder for distance.
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += ['tableName' => null];
$sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
$query->where(['(' . $sql . ') <' => $options['distance']]);
}
return $query->order(['distance' => 'ASC']);
}
示例2: apply
/**
* {@inheritdoc}
*/
public function apply($fromAlias, $fromIdentifier, $resourcePrefix, array $requesterIdentifiers, $mask, array $orX = [])
{
$this->query->join(['table' => $this->getAclSchema()->getPermissionsTableName(), 'alias' => 'acl_p', 'type' => 'LEFT', 'conditions' => $this->query->newExpr()->eq('acl_p.resource', $this->query->func()->concat([':acl_resource_prefix' => 'literal', $fromAlias . '.' . $fromIdentifier => 'literal']))]);
$orX[] = $this->query->newExpr()->and_([$this->query->newExpr()->in('acl_p.requester', $requesterIdentifiers, 'string'), $this->query->newExpr(':acl_mask = (acl_p.mask & :acl_mask)')]);
$this->query->andWhere($this->query->newExpr()->or_($orX));
$this->query->bind(':acl_resource_prefix', $resourcePrefix);
$this->query->bind(':acl_mask', $mask, 'integer');
return $this->query;
}
示例3: findWithTrashed
/**
* Custom finder to get all rows (`trashed` or not).
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Options.
* @return \Cake\ORM\Query
*/
public function findWithTrashed(Query $query, array $options)
{
return $query->where(['OR' => [$query->newExpr()->isNotNull($this->getTrashField()), $query->newExpr()->isNull($this->getTrashField())]]);
}
示例4: findDistance
/**
* Custom finder for distance.
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
* - sort
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += ['tableName' => null, 'sort' => true];
$sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
if ($query->autoFields() === null) {
$query->autoFields(true);
}
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
$query->where(function ($exp) use($sql, $options) {
return $exp->lt($sql, $options['distance']);
});
}
if ($options['sort']) {
$sort = $options['sort'] === true ? 'ASC' : $options['sort'];
$query->order(['distance' => $sort]);
}
return $query;
}
示例5: findFemaleRatio
public function findFemaleRatio(Query $query, $options = [])
{
$allManagers = $this->find()->select($query->func()->count('*'));
return $query->find('female')->select(['female_ratio' => $query->newExpr($query->func()->count('*'))->add($allManagers)->type('/')]);
}
示例6: findDistance
/**
* Custom finder for distance.
*
* Used to be a virtual field in 2.x via setDistanceAsVirtualField()
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += array('tableName' => null);
$sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
$query->where(['distance <' => $options['distance']]);
}
return $query->order(['distance' => 'ASC']);
}