-
Notifications
You must be signed in to change notification settings - Fork 0
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
Correct ids relation in the degree programs overview shortcode #8
Conversation
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.
Thanks. LGTM!
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.
Thanks for working on this! Approving because code-wise LGTM. My local data is quite unusable, so could you please confirm that comma-separated combinations of HIS codes with varying campo key values and lengths (i.e., number of campo keys) work as expected? Thank you!
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'm a bit afraid of such changes. I think the safer way would be to have HIS subquery:
Index: src/Infrastructure/Repository/WpQueryArgsBuilder.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Infrastructure/Repository/WpQueryArgsBuilder.php b/src/Infrastructure/Repository/WpQueryArgsBuilder.php
--- a/src/Infrastructure/Repository/WpQueryArgsBuilder.php (revision 4a72cbaf0318d8804397f2d94b6884a695bbd7af)
+++ b/src/Infrastructure/Repository/WpQueryArgsBuilder.php (date 1717078209710)
@@ -87,37 +87,52 @@
$queryArgs = $this->applyFilter($filter, $queryArgs, $criteria->languageCode());
}
- foreach ($criteria->hisCodes() as $hisCode) {
- $queryArgs = $this->applyHisCode($hisCode, $queryArgs);
+ if (count($criteria->hisCodes()) > 0) {
+ $queryArgs = $this->applyHisCodes($criteria->hisCodes(), $queryArgs);
}
return $queryArgs;
}
- public function applyHisCode(string $hisCode, WpQueryArgs $queryArgs): WpQueryArgs
+ /**
+ * @param array<string> $hisCodes
+ */
+ public function applyHisCodes(array $hisCodes, WpQueryArgs $queryArgs): WpQueryArgs
{
- $taxQueryItem = [
- 'relation' => 'AND',
- ];
+ $hisCodesQuery = [];
+
+ foreach ($hisCodes as $hisCode) {
+ $taxQueryItem = [
+ 'relation' => 'AND',
+ ];
- $taxonomyToTermMapping = $this->campoKeysRepository->taxonomyToTermsMapFromCampoKeys(
- CampoKeys::fromHisCode($hisCode)
- );
+ $taxonomyToTermMapping = $this->campoKeysRepository->taxonomyToTermsMapFromCampoKeys(
+ CampoKeys::fromHisCode($hisCode)
+ );
- if (count($taxonomyToTermMapping) === 0) {
- return $queryArgs;
- }
+ if (count($taxonomyToTermMapping) === 0) {
+ continue;
+ }
- foreach ($taxonomyToTermMapping as $taxonomy => $termId) {
- $taxQueryItem[] = [
- 'taxonomy' => $taxonomy,
- 'terms' => [
- $termId,
- ],
- ];
- }
+ foreach ($taxonomyToTermMapping as $taxonomy => $termId) {
+ $taxQueryItem[] = [
+ 'taxonomy' => $taxonomy,
+ 'terms' => [
+ $termId,
+ ],
+ ];
+ }
- return $queryArgs->withTaxQueryItem($taxQueryItem);
+ $hisCodesQuery[] = $taxQueryItem;
+ }
+
+ if (count($hisCodesQuery) === 0) {
+ return $queryArgs;
+ }
+
+ $hisCodesQuery['relation'] = 'OR';
+
+ return $queryArgs->withTaxQueryItem($hisCodesQuery);
}
private function applyOrderBy(
Does it work?
Thanks for the suggestion. @tyrann0us, @o-samaras, could you please review updated PR? Thanks a lot. |
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.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix
What is the current behavior? (You can also link to an open issue here)
Currently separating HIS codes by a comma in the
ids
attribute connects them byAND
(source). This makes it impossible to display programs using multiple codes.What is the new behavior (if this is a feature change)?
The relation is changed to
OR
. Introduced the possibility to set any relation in the taxonomy parametertax_query
.Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No
Other information: