Skip to content
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

Fix itemSet sorting priority in site view #1426

Merged
merged 3 commits into from
Jul 15, 2019
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
16 changes: 12 additions & 4 deletions application/src/Api/Adapter/ItemSetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class ItemSetAdapter extends AbstractResourceEntityAdapter
'modified' => 'modified',
'title' => 'title',
];
/**
* Alias of query builder for join clause between `site` and `item_sets`.
* @var string
*/
protected $siteItemSetsAlias;

public function getResourceName()
{
Expand Down Expand Up @@ -68,16 +73,15 @@ public function buildQuery(QueryBuilder $qb, array $query)
} catch (Exception\NotFoundException $e) {
$site = null;
}
$siteItemSetsAlias = $this->createAlias();
$this->siteItemSetsAlias = $this->createAlias();
$qb->innerJoin(
'omeka_root.siteItemSets',
$siteItemSetsAlias
$this->siteItemSetsAlias
);
$qb->andWhere($qb->expr()->eq(
"$siteItemSetsAlias.site",
"$this->siteItemSetsAlias.site",
$this->createNamedParameter($qb, $query['site_id']))
);
$qb->addOrderBy("$siteItemSetsAlias.position", 'ASC');
}
}

Expand All @@ -90,6 +94,10 @@ public function sortQuery(QueryBuilder $qb, array $query)
parent::sortQuery($qb, $query);
}
}
//In site view, sorting by admin-defined position
if (isset($this->siteItemSetsAlias)) {
$qb->addOrderBy("$this->siteItemSetsAlias.position", 'ASC');
}
}

public function hydrate(Request $request, EntityInterface $entity,
Expand Down
2 changes: 0 additions & 2 deletions application/src/Controller/Site/ItemSetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public function browseAction()
{
$site = $this->currentSite();

$this->setBrowseDefaults('created');

$query = $this->params()->fromQuery();
$query['site_id'] = $site->id();
$response = $this->api()->search('item_sets', $query);
Expand Down