本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::addFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::addFilter方法的具体用法?PHP QueryBuilder::addFilter怎么用?PHP QueryBuilder::addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::addFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterListQuery
/**
* Filters the displayed fields by the passed filter value.
*
* @param \Doctrine\ORM\QueryBuilder $builder
* @param array|null $filters
* @return \Doctrine\ORM\QueryBuilder
*/
protected function filterListQuery(\Doctrine\ORM\QueryBuilder $builder, $filters = null)
{
$expr = Shopware()->Models()->getExpressionBuilder();
if (!empty($filters)) {
foreach ($filters as $filter) {
if (empty($filter['property']) || $filter['value'] === null || $filter['value'] === '') {
continue;
}
switch ($filter['property']) {
case "free":
$builder->andWhere($expr->orX($expr->like('orders.number', '?1'), $expr->like('orders.invoiceAmount', '?1'), $expr->like('orders.transactionId', '?1'), $expr->like('billing.company', '?3'), $expr->like('customer.email', '?3'), $expr->like('billing.lastName', '?3'), $expr->like('billing.firstName', '?3'), $expr->like('orders.comment', '?3'), $expr->like('orders.customerComment', '?3'), $expr->like('orders.internalComment', '?3')));
$builder->setParameter(1, $filter['value'] . '%');
$builder->setParameter(3, '%' . $filter['value'] . '%');
break;
case "from":
$tmp = new \DateTime($filter['value']);
$builder->andWhere('orders.orderTime > :orderTimeFrom');
$builder->setParameter('orderTimeFrom', $tmp->format('Ymd'));
break;
case "to":
$tmp = new \Zend_Date($filter['value']);
$tmp->setHour('23');
$tmp->setMinute('59');
$tmp->setSecond('59');
$builder->andWhere('orders.orderTime <= :orderTimeTo');
$builder->setParameter('orderTimeTo', $tmp->get('yyyy-MM-dd HH:mm:ss'));
break;
case 'details.articleNumber':
$builder->leftJoin('orders.details', 'details');
$builder->andWhere('details.articleNumber LIKE :articleNumber');
$builder->setParameter('articleNumber', $filter['value']);
break;
default:
$builder->addFilter(array($filter));
}
}
}
return $builder;
}
示例2: addFilter
/**
* Adds filters to the query results.
*
* <code>
* $this->addFilter($builder, array(array(
* 'property' => 'name'
* 'value' => 'A%'
* )));
* </code>
*
* @param QueryBuilder $builder
* @param array $filter
* @return QueryBuilder
*/
public function addFilter(QueryBuilder $builder, array $filter)
{
return $builder->addFilter($filter);
}