本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::distinct方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::distinct方法的具体用法?PHP QueryBuilder::distinct怎么用?PHP QueryBuilder::distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::distinct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyGreatestNPerGroupDate
public function applyGreatestNPerGroupDate(QueryBuilder $qb)
{
$qb->distinct();
$qb2 = $this->createQueryBuilder('ss')->select('MAX(ss.timestamp)')->where('DATE(ss.timestamp) = DATE(s.timestamp)');
$qb->innerJoin($this->getEntityName(), 'sub', 'WITH', $qb->expr()->eq('s.timestamp', '(' . $qb2->getDQL() . ')'));
}
示例2: makeDistinct
public function makeDistinct()
{
$this->queryBuilder->distinct();
}
示例3: applyJoins
/**
* Applies the given joins for the query builder
*
* @param QueryBuilder $qb
* @param array|null $joins
*/
public static function applyJoins(QueryBuilder $qb, $joins)
{
if (empty($joins)) {
return;
}
$qb->distinct(true);
$rootAlias = self::getSingleRootAlias($qb);
foreach ($joins as $key => $val) {
if (empty($val)) {
$qb->leftJoin($rootAlias . '.' . $key, $key);
} elseif (is_array($val)) {
if (isset($val['join'])) {
$join = $val['join'];
if (false === strpos($join, '.')) {
$join = $rootAlias . '.' . $join;
}
} else {
$join = $rootAlias . '.' . $key;
}
$condition = null;
$conditionType = null;
if (isset($val['condition'])) {
$condition = $val['condition'];
$conditionType = Expr\Join::WITH;
}
if (isset($val['conditionType'])) {
$conditionType = $val['conditionType'];
}
$qb->leftJoin($join, $key, $conditionType, $condition);
} else {
$qb->leftJoin($rootAlias . '.' . $val, $val);
}
}
}
示例4: parse
/**
* {@inheritdoc}
*/
public function parse($value, QueryBuilder $qb)
{
if (!is_array($value)) {
$value = Yaml::parse($value);
}
$processor = new Processor();
$value = $processor->processConfiguration(new QueryConfiguration(), $value);
if (!isset($value['from'])) {
throw new \RuntimeException('Missing mandatory "from" section');
}
foreach ((array) $value['from'] as $from) {
$qb->from($from['table'], $from['alias']);
}
if (isset($value['select'])) {
foreach ($value['select'] as $select) {
$qb->add('select', new Expr\Select($select), true);
}
}
if (isset($value['distinct'])) {
$qb->distinct((bool) $value['distinct']);
}
if (isset($value['groupBy'])) {
$qb->groupBy($value['groupBy']);
}
if (isset($value['having'])) {
$qb->having($value['having']);
}
$this->addJoin($qb, $value);
$this->addWhere($qb, $value);
$this->addOrder($qb, $value);
return $qb;
}
示例5: execute
/**
* {@inheritdoc}
*/
public function execute()
{
// emit listbuilder.create event
$event = new ListBuilderCreateEvent($this);
$this->eventDispatcher->dispatch(ListBuilderEvents::LISTBUILDER_CREATE, $event);
$this->expressionFields = $this->getUniqueExpressionFieldDescriptors($this->expressions);
// first create simplified id query
// select ids with all necessary filter data
$ids = $this->findIdsByGivenCriteria();
// if no results are found - return
if (count($ids) < 1) {
return [];
}
// now select all data
$this->queryBuilder = $this->em->createQueryBuilder()->from($this->entityName, $this->entityName);
$this->assignJoins($this->queryBuilder);
// Add all select fields
foreach ($this->selectFields as $field) {
$this->queryBuilder->addSelect($field->getSelect() . ' AS ' . $field->getName());
}
// group by
$this->assignGroupBy($this->queryBuilder);
// assign sort-fields
$this->assignSortFields($this->queryBuilder);
// use ids previously selected ids for query
$select = $this->entityName . '.id';
if (null !== $this->idField) {
$select = $this->idField->getSelect();
}
$this->queryBuilder->where($select . ' IN (:ids)')->setParameter('ids', $ids);
$this->queryBuilder->distinct($this->distinct);
return $this->queryBuilder->getQuery()->getArrayResult();
}
示例6: __wakeup
/**
* Recreate query builder and set state again.
*
* @return void
*/
public function __wakeup()
{
if ($this->constraint !== null) {
$this->queryBuilder->where($this->constraint);
}
if (is_array($this->orderings)) {
$aliases = $this->queryBuilder->getRootAliases();
foreach ($this->orderings as $propertyName => $order) {
$this->queryBuilder->addOrderBy($aliases[0] . '.' . $propertyName, $order);
}
}
if (is_array($this->joins)) {
foreach ($this->joins as $joinAlias => $join) {
$this->queryBuilder->leftJoin($join, $joinAlias);
}
}
$this->queryBuilder->setFirstResult($this->offset);
$this->queryBuilder->setMaxResults($this->limit);
$this->queryBuilder->distinct($this->distinct);
$this->queryBuilder->setParameters($this->parameters);
unset($this->parameters);
}