-
Notifications
You must be signed in to change notification settings - Fork 44
NGSTACK-906 eztags priority sorting #170
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
base: master
Are you sure you want to change the base?
Changes from 16 commits
c843d14
1c5b716
2d27fc0
a8cf605
3a84111
8e535ea
7d59685
fe7ba81
9158a5d
9ce9427
60cf2cf
1041265
0955f35
43def26
f0aa890
f1e4e1a
6139978
df8003b
ef0d60a
be00504
d88c066
c0bf0f4
c719cc4
93c1134
41e6787
705fc35
2397fcc
c6c4555
4a5391d
4224d33
e16f73f
dba4689
a6100ae
5733962
5479257
148a3c3
3704566
59beb45
84d9758
fd507dd
a81d3f6
0ce8c25
3e9628a
c6d1f47
031c1aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Netgen\TagsBundle\API\Repository\TagsService; | ||
use Netgen\TagsBundle\API\Repository\Values\Tags\Tag; | ||
use Netgen\TagsBundle\Core\Pagination\Pagerfanta\ChildrenTagsAdapter; | ||
use Netgen\TagsBundle\Core\Pagination\Pagerfanta\SearchTagsAdapter; | ||
use Netgen\TagsBundle\Form\Type\CopyTagsType; | ||
use Netgen\TagsBundle\Form\Type\LanguageSelectType; | ||
|
@@ -16,7 +17,6 @@ | |
use Netgen\TagsBundle\Form\Type\TagCreateType; | ||
use Netgen\TagsBundle\Form\Type\TagMergeType; | ||
use Netgen\TagsBundle\Form\Type\TagUpdateType; | ||
use Pagerfanta\Adapter\AdapterInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
|
@@ -29,7 +29,7 @@ final class TagController extends Controller | |
public function __construct( | ||
private TagsService $tagsService, | ||
private ContentTypeService $contentTypeService, | ||
private AdapterInterface $tagChildrenAdapter, | ||
private ChildrenTagsAdapter $tagChildrenAdapter, | ||
private SearchTagsAdapter $searchTagsAdapter, | ||
) {} | ||
|
||
|
@@ -45,6 +45,12 @@ public function showTagAction(Request $request, ?Tag $tag = null): Response | |
if (!$tag instanceof Tag || !$tag->isSynonym()) { | ||
$configResolver = $this->getConfigResolver(); | ||
|
||
$sortBy = $request->query->get('sort_by'); | ||
|
||
$sortOrder = $request->query->get('sort_order'); | ||
if ($sortBy !== null && $sortOrder !== null) { | ||
$this->tagChildrenAdapter->setSorting($sortBy, $sortOrder); | ||
} | ||
|
||
$currentPage = (int) $request->query->get('page'); | ||
$pager = $this->createPager( | ||
$this->tagChildrenAdapter, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ public function getFullTagDataByKeywordAndParentId(string $keyword, int $parentI | |
return $query->execute()->fetchAll(FetchMode::ASSOCIATIVE); | ||
} | ||
|
||
public function getChildren(int $tagId, int $offset = 0, int $limit = -1, ?array $translations = null, bool $useAlwaysAvailable = true): array | ||
public function getChildren(int $tagId, int $offset = 0, int $limit = -1, ?array $translations = null, bool $useAlwaysAvailable = true, ?string $sortBy = null, ?string $sortOrder = null): array | ||
{ | ||
$tagIdsQuery = $this->createTagIdsQuery($translations, $useAlwaysAvailable); | ||
$tagIdsQuery->andWhere( | ||
|
@@ -137,10 +137,17 @@ public function getChildren(int $tagId, int $offset = 0, int $limit = -1, ?array | |
), | ||
$tagIdsQuery->expr()->eq('eztags.main_tag_id', 0), | ||
), | ||
)->setParameter('parent_id', $tagId, Types::INTEGER) | ||
->orderBy('eztags.keyword', 'ASC') | ||
->setFirstResult($offset) | ||
->setMaxResults($limit > 0 ? $limit : PHP_INT_MAX); | ||
)->setParameter('parent_id', $tagId, Types::INTEGER); | ||
|
||
if ($sortBy !== null && $sortOrder !== null) { | ||
|
||
$tagIdsQuery->orderBy('eztags.' . $sortBy, $sortOrder); | ||
} else { | ||
$tagIdsQuery->orderBy('eztags.keyword', 'ASC'); | ||
} | ||
|
||
$tagIdsQuery | ||
|
||
->setFirstResult($offset) | ||
->setMaxResults($limit > 0 ? $limit : PHP_INT_MAX); | ||
|
||
$statement = $tagIdsQuery->execute(); | ||
|
||
|
@@ -160,8 +167,13 @@ public function getChildren(int $tagId, int $offset = 0, int $limit = -1, ?array | |
[':id'], | ||
), | ||
) | ||
->setParameter('id', $tagIds, Connection::PARAM_INT_ARRAY) | ||
->orderBy('eztags_keyword.keyword', 'ASC'); | ||
->setParameter('id', $tagIds, Connection::PARAM_INT_ARRAY); | ||
|
||
if ($sortBy !== null && $sortOrder !== null) { | ||
$query->orderBy('eztags.' . $sortBy, $sortOrder); | ||
} else { | ||
$query->orderBy('eztags_keyword.keyword', 'ASC'); | ||
} | ||
|
||
return $query->execute()->fetchAll(FetchMode::ASSOCIATIVE); | ||
} | ||
|
@@ -847,7 +859,7 @@ public function deleteTag(int $tagId): void | |
private function createTagIdsQuery(?array $translations = null, bool $useAlwaysAvailable = true): QueryBuilder | ||
{ | ||
$query = $this->connection->createQueryBuilder(); | ||
$query->select('DISTINCT eztags.id, eztags.keyword') | ||
$query->select('DISTINCT eztags.id, eztags.keyword, eztags.modified, eztags.priority') | ||
->from('eztags', 'eztags') | ||
// @todo: Joining with eztags_keyword is probably a VERY bad way to gather that information | ||
// since it creates an additional cartesian product with translations. | ||
|
@@ -930,6 +942,7 @@ private function createTagFindQuery(?array $translations = null, bool $useAlways | |
'eztags.remote_id', | ||
'eztags.main_language_id', | ||
'eztags.language_mask', | ||
'eztags.priority', | ||
// Tag keywords | ||
'eztags_keyword.keyword', | ||
'eztags_keyword.locale', | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this level of control, in contrast to just using whatever info is storred on parent tag?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this level of control is necessary because in the Gateway layer (
getChildren()
method), the fetched data from the database needs to first be sorted and then sliced using $limit and $offset values.Which info stored on parent tag do you mean? Perhaps another approach for sorting would be if each Tag object would have information attached to it about the sortBy and sortOrder, something like the Location object in Ibexa has (if I'm not mistaken).
EDIT: read the comment below this one. OK, I will implement the sorting mechanism similar to the Ibexa one