Skip to content

Fixbug/add order by query #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Bundle/QueryBundle/Entity/Traits/QueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ trait QueryTrait
*/
protected $query;

/**
* @var string
*
* @ORM\Column(name="orderBy", type="text", nullable=true)
*/
protected $orderBy;

/**
* Auto list mode: businessentity type
* @var string
Expand Down Expand Up @@ -42,6 +49,26 @@ public function setQuery($query)
$this->query = $query;
}

/**
* Get orderBy
*
* @return string
*/
public function getOrderBy()
{
return $this->orderBy;
}

/**
* Set orderBy
*
* @param string $orderBy
*/
public function setOrderBy($orderBy)
{
$this->orderBy = $orderBy;
}

/**
* Get businessEntity
*
Expand Down
6 changes: 6 additions & 0 deletions Bundle/QueryBundle/Helper/QueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function buildWithSubQuery($containerEntity, QueryBuilder $itemsQueryBuil

//get the query of the container entity
$query = $containerEntity->getQuery();
$orderBy = json_decode($containerEntity->getOrderBy(), true);
if ($query !== '' && $query !== null) {

$subQuery = $this->entityManager->createQueryBuilder()
Expand All @@ -133,6 +134,11 @@ public function buildWithSubQuery($containerEntity, QueryBuilder $itemsQueryBuil

$itemsQueryBuilder
->andWhere('main_item.id IN ('.$subQuery->getQuery()->getDql().' '.$query.')');
if ($orderBy) {
foreach ($orderBy as $addOrderBy) {
$itemsQueryBuilder->addOrderBy('main_item.' . $addOrderBy['by'], $addOrderBy['order']);
}
}
}
$currentView = $this->currentView;

Expand Down