From c7f19049d23e6d1c2492375f16d6ffe68dd00bdd Mon Sep 17 00:00:00 2001 From: Paul Sarrassat Date: Sat, 6 Jul 2019 22:48:12 +0200 Subject: [PATCH 1/2] Fix itemSet sorting priority in site view: sort_by (URL param) > position (configured in admin side) > id Previously, position was prioritized and fallback was 'created' --- application/src/Api/Adapter/ItemSetAdapter.php | 16 ++++++++++++---- .../src/Controller/Site/ItemSetController.php | 2 -- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/application/src/Api/Adapter/ItemSetAdapter.php b/application/src/Api/Adapter/ItemSetAdapter.php index 2b78a3fbfc..c37d7f2157 100644 --- a/application/src/Api/Adapter/ItemSetAdapter.php +++ b/application/src/Api/Adapter/ItemSetAdapter.php @@ -14,6 +14,11 @@ class ItemSetAdapter extends AbstractResourceEntityAdapter 'created' => 'created', 'modified' => 'modified', ]; + /** + * Alias of query builder for join clause between `site` and `item_sets`. + * @var string + */ + protected $siteItemSetsAlias; public function getResourceName() { @@ -67,16 +72,15 @@ public function buildQuery(QueryBuilder $qb, array $query) } catch (Exception\NotFoundException $e) { $site = null; } - $siteItemSetsAlias = $this->createAlias(); + $this->siteItemSetsAlias = $this->createAlias(); $qb->innerJoin( 'Omeka\Entity\ItemSet.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'); } } @@ -89,6 +93,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, diff --git a/application/src/Controller/Site/ItemSetController.php b/application/src/Controller/Site/ItemSetController.php index 9a44699903..85943e1c05 100644 --- a/application/src/Controller/Site/ItemSetController.php +++ b/application/src/Controller/Site/ItemSetController.php @@ -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); From 495dbdbeabcbe2a74ef618c68252acefd15afaee Mon Sep 17 00:00:00 2001 From: Paul Sarrassat Date: Tue, 9 Jul 2019 01:33:24 +0200 Subject: [PATCH 2/2] Coding Standard fix --- application/src/Api/Adapter/ItemSetAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/Api/Adapter/ItemSetAdapter.php b/application/src/Api/Adapter/ItemSetAdapter.php index 45287971d4..c240ac7f2f 100644 --- a/application/src/Api/Adapter/ItemSetAdapter.php +++ b/application/src/Api/Adapter/ItemSetAdapter.php @@ -95,7 +95,7 @@ public function sortQuery(QueryBuilder $qb, array $query) } } //In site view, sorting by admin-defined position - if(isset($this->siteItemSetsAlias)) { + if (isset($this->siteItemSetsAlias)) { $qb->addOrderBy("$this->siteItemSetsAlias.position", 'ASC'); } }