本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::getRootAliases方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getRootAliases方法的具体用法?PHP QueryBuilder::getRootAliases怎么用?PHP QueryBuilder::getRootAliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::getRootAliases方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAliases
private function checkAliases($column)
{
if (Strings::contains($column, ".")) {
return $column;
}
return current($this->data_source->getRootAliases()) . '.' . $column;
}
示例2: createPropertyPathMapping
public function createPropertyPathMapping(QueryBuilder $qb, array $fieldMapping, array $existingMapping = [])
{
if (count($qb->getRootAliases()) > 1) {
throw new \UnexpectedValueException("Expected 1 root alias");
}
$rootAlias = $qb->getRootAliases()[0];
$aliasMapping = [$rootAlias => ''];
foreach ($qb->getDQLPart('join') as $joinFrom => $joins) {
foreach ($joins as $join) {
$joinParts = explode(".", $join->getJoin());
$aliasMapping[$join->getAlias()] = trim($aliasMapping[$joinParts[0]] . '.' . $joinParts[1], '.');
}
}
$mapping = [];
foreach ($fieldMapping as $key => $field) {
if (array_key_exists($key, $existingMapping)) {
$mapping[$key] = $existingMapping[$key];
continue;
}
$fieldParts = explode('.', $field);
if (isset($fieldParts[1])) {
$alias = $fieldParts[0];
$mapping[$key] = trim($aliasMapping[$fieldParts[0]] . '.' . $fieldParts[1], '.');
} else {
$mapping[$key] = trim($fieldParts[0]);
}
}
return $mapping;
}
示例3: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value)
{
$field = current($this->qb->getRootAliases()) . '.' . $field;
$condition = $this->prepareCriteriaCondition($field, $operator, $value);
$this->qb->andWhere($condition);
return $this;
}
示例4: addFieldSorter
/**
* {@inheritdoc}
*/
public function addFieldSorter($field, $direction, $locale = null, $scope = null)
{
$field = current($this->qb->getRootAliases()) . '.' . $field;
$this->qb->addOrderBy($field, $direction);
$idField = $this->qb->getRootAlias() . '.id';
$this->qb->addOrderBy($idField);
return $this;
}
示例5: setOriginalQueryBuilder
/**
* Set original query builder.
*
* @param QueryBuilder $originalQb
*/
protected function setOriginalQueryBuilder(QueryBuilder $originalQb)
{
$this->originalQb = $originalQb;
$this->qbTools->prepareFieldAliases($originalQb->getDQLPart('select'));
$this->qbTools->prepareJoinTablePaths($originalQb->getDQLPart('join'));
$this->rootAlias = current($this->originalQb->getRootAliases());
$this->initIdFieldName();
}
示例6: getCount
public function getCount()
{
if ($this->count === NULL) {
$alias = $this->builder->getRootAliases();
$builder = clone $this->builder;
$result = $builder->select('COUNT(' . current($alias) . '.id) AS count')->getQuery()->getSingleResult();
$this->count = $result['count'];
}
return $this->count;
}
示例7: checkAliases
/**
* @param string $column
* @return string
*/
private function checkAliases($column)
{
if (Strings::contains($column, ".")) {
return $column;
}
if (!isset($this->root_alias)) {
$this->root_alias = $this->data_source->getRootAliases();
$this->root_alias = current($this->root_alias);
}
return $this->root_alias . '.' . $column;
}
示例8: addFilterByOrderStatus
/**
* @param QueryBuilder $qb
* @param string $orderStatus
*/
protected function addFilterByOrderStatus(QueryBuilder $qb, $orderStatus)
{
$aliases = $qb->getRootAliases();
$subQueryBuilder = $this->customerRepository->createQueryBuilder('c');
$subQueryBuilder->select('IDENTITY(c.account)')->join('c.orders', 'o', 'WITH', $subQueryBuilder->expr()->eq($subQueryBuilder->expr()->lower('o.status'), ':filteredOrderStatus'));
$qb->andWhere($qb->expr()->in($aliases[0] . '.account', $subQueryBuilder->getDQL()))->setParameter('filteredOrderStatus', $orderStatus);
}
示例9: autoJoin
private function autoJoin(QueryBuilder $queryBuilder)
{
foreach ($this->expectedJoinChains as $tablesToJoin) {
// check if the first dimension is a known alias
if (isset($this->knownAliases[$tablesToJoin[0]])) {
$joinTo = $tablesToJoin[0];
array_pop($tablesToJoin);
} else {
// if not, it's the root table
$joinTo = $queryBuilder->getRootAliases()[0];
}
foreach ($tablesToJoin as $table) {
$joinAlias = self::ALIAS_PREFIX . $table;
$join = sprintf('%s.%s', $joinTo, $table);
if (!isset($this->joinMap[$join])) {
$this->joinMap[$join] = $joinAlias;
$this->knownAliases[$joinAlias] = true;
$queryBuilder->join(sprintf('%s.%s', $joinTo, $table), $joinAlias);
} else {
$joinAlias = $this->joinMap[$join];
}
$joinTo = $joinAlias;
}
}
}
示例10: paginateQuery
/**
* @param QueryBuilder $query
* @param int $per_page
* @param int $current_page
*
* @return Configuration
*/
public function paginateQuery(QueryBuilder $query, $per_page, $current_page = 1)
{
$counter = clone $query;
$total = $counter->select(sprintf('COUNT(%s)', current($query->getRootAliases())))->getQuery()->getSingleScalarResult();
$query->setFirstResult(($current_page - 1) * $per_page)->setMaxResults($per_page);
return (new Configuration(ceil($total / $per_page), $current_page))->setMaxNavigate($this->max_navigate);
}
示例11: Expr
function it_adds_binary_filter_in_the_query(QueryBuilder $queryBuilder)
{
$queryBuilder->expr()->willReturn(new Expr());
$queryBuilder->getRootAliases()->willReturn(['p']);
$queryBuilder->andWhere('p.id = \'12\'')->shouldBeCalled();
$this->addFieldFilter('id', '=', '12');
}
示例12: sort
/**
* Sets sorting.
* @param array $sorting
*/
public function sort(array $sorting)
{
foreach ($sorting as $key => $value) {
$column = isset($this->sortMapping[$key]) ? $this->sortMapping[$key] : current($this->qb->getRootAliases()) . '.' . $key;
$this->qb->addOrderBy($column, $value);
}
}
示例13: getItems
/**
* @return mixed
*/
public function getItems()
{
$this->qb->setMaxResults($this->getLimit());
$this->qb->setFirstResult($this->getOffset());
if (count($this->getSorting()) > 0) {
foreach ($this->getSorting() as $sortColumn => $sortType) {
if (isset($this->columnAliases[$sortColumn])) {
$sortColumn = $this->columnAliases[$sortColumn]->qbName;
} else {
$aliases = $this->qb->getRootAliases();
$sortColumn = $aliases[0] . '.' . $sortColumn;
}
$this->qb->addOrderBy($sortColumn, is_string($sortType) && strncasecmp($sortType, 'd', 1) || $sortType > 0 ? 'ASC' : 'DESC');
}
}
return $this->qb->getQuery()->getResult();
}
示例14: filter
/**
* {@inheritdoc}
*/
public function filter(Request $request, QueryBuilder $queryBuilder)
{
$order = $request->query->get('order') ?: self::DEFAULT_ORDER;
if ($request->query->has('sort')) {
$alias = $queryBuilder->getRootAliases()[0];
$queryBuilder->orderBy($alias . '.' . $request->query->get('sort'), $order);
}
}
示例15: setSourceQueryBuilder
/**
* {@inheritdoc}
*/
public function setSourceQueryBuilder(QueryBuilder $queryBuilder)
{
if ($this->priceListId) {
$aliases = $queryBuilder->getRootAliases();
$rootAlias = reset($aliases);
$queryBuilder->andWhere($queryBuilder->expr()->eq(sprintf('IDENTITY(%s.priceList)', $rootAlias), ':priceList'))->setParameter('priceList', $this->priceListId);
}
parent::setSourceQueryBuilder($queryBuilder);
}