本文整理汇总了PHP中Sonata\AdminBundle\Datagrid\ProxyQueryInterface::addMustNot方法的典型用法代码示例。如果您正苦于以下问题:PHP ProxyQueryInterface::addMustNot方法的具体用法?PHP ProxyQueryInterface::addMustNot怎么用?PHP ProxyQueryInterface::addMustNot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Datagrid\ProxyQueryInterface
的用法示例。
在下文中一共展示了ProxyQueryInterface::addMustNot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* {@inheritdoc}
*/
public function filter(ProxyQueryInterface $query, $alias, $field, $data)
{
if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
return;
}
$data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
if (is_array($data['value'])) {
if (count($data['value']) == 0) {
return;
}
if (in_array('all', $data['value'], true)) {
return;
}
$queryBuilder = new \Elastica\Query\Builder();
$queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm($data['value']))->fieldClose();
if ($firstOperator == 'must') {
$query->addMust($queryBuilder);
} else {
$query->addMustNot($queryBuilder);
}
} else {
if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') {
return;
}
$queryBuilder = new \Elastica\Query\Builder();
$queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm(array($data['value'])))->fieldClose();
if ($firstOperator == 'must') {
$query->addMust($queryBuilder);
} else {
$query->addMustNot($queryBuilder);
}
}
}
示例2: filter
/**
* {@inheritdoc}
*/
public function filter(ProxyQueryInterface $query, $alias, $field, $data)
{
// check data sanity
if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
return;
}
$format = array_key_exists('format', $this->getFieldOptions()) ? $this->getFieldOptions()['format'] : 'c';
$queryBuilder = new \Elastica\Query\Builder();
if ($this->range) {
// additional data check for ranged items
if (!array_key_exists('start', $data['value']) || !array_key_exists('end', $data['value'])) {
return;
}
if (!$data['value']['start'] || !$data['value']['end']) {
return;
}
// transform types
if ($this->getOption('input_type') == 'timestamp') {
$data['value']['start'] = $data['value']['start'] instanceof \DateTime ? $data['value']['start']->getTimestamp() : 0;
$data['value']['end'] = $data['value']['end'] instanceof \DateTime ? $data['value']['end']->getTimestamp() : 0;
}
// default type for range filter
$data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateRangeType::TYPE_BETWEEN : $data['type'];
$queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']['start']->format($format))->field('lte', $data['value']['end']->format($format))->fieldClose()->fieldClose();
if ($data['type'] == DateRangeType::TYPE_NOT_BETWEEN) {
$query->addMustNot($queryBuilder);
} else {
$query->addMust($queryBuilder);
}
} else {
if (!$data['value']) {
return;
}
// default type for simple filter
$data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_GREATER_EQUAL : $data['type'];
// just find an operator and apply query
$operator = $this->getOperator($data['type']);
// transform types
if ($this->getOption('input_type') == 'timestamp') {
$data['value'] = $data['value'] instanceof \DateTime ? $data['value']->getTimestamp() : 0;
}
// null / not null only check for col
if (in_array($operator, array('missing', 'exists'))) {
$queryBuilder->fieldOpen($operator)->field('field', $field)->fieldClose();
} elseif ($operator == '=') {
$queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']->format($format))->field('lte', $data['value']->format($format))->fieldClose()->fieldClose();
} else {
$queryBuilder->fieldOpen('range')->fieldOpen($field)->field($operator, $data['value']->format($format))->fieldClose()->fieldClose();
}
$query->addMust($queryBuilder);
}
}
示例3: filter
/**
* {@inheritdoc}
*/
public function filter(ProxyQueryInterface $query, $alias, $field, $data)
{
if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
return;
}
$data['value'] = trim($data['value']);
if (strlen($data['value']) == 0) {
return;
}
$data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
// Create a query that match terms (indepedent of terms order) or a phrase
$queryBuilder = new \Elastica\Query\Builder();
$queryBuilder->fieldOpen($secondOperator)->fieldOpen($field)->field('query', str_replace(array('\\', '"'), array('\\\\', '\\"'), $data['value']))->field('operator', 'and')->fieldClose()->fieldClose();
if ($firstOperator == 'must') {
$query->addMust($queryBuilder);
} else {
$query->addMustNot($queryBuilder);
}
}