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

Allow searching for decision using the English abbreviations for meeting #1719

Merged
merged 1 commit into from
Sep 26, 2023
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
11 changes: 5 additions & 6 deletions module/Decision/src/Mapper/Decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Decision\Model\Enums\MeetingTypes;

use function addcslashes;
use function implode;
use function is_numeric;
use function preg_match;

Expand Down Expand Up @@ -36,7 +37,7 @@ public function search(string $query): array
$qb->setParameter('query', '%' . addcslashes($query, '%_') . '%');

// Start by matching meeting type and meeting number, then we also match additional meeting points and decision
// numbers.
// numbers. Both the Dutch and English abbreviation for the meeting types can be used.
//
// To make it usable, we also split the meeting type and meeting number match into two separate capture groups.
// In total there are four capture groups.
Expand All @@ -52,13 +53,11 @@ public function search(string $query): array
// [3]=> string(3) "456"
// [4]=> string(3) "789"
// }
$meetingRegex = '/(?:(' . MeetingTypes::ALV->value . '|'
. MeetingTypes::BV->value . '|'
. MeetingTypes::VV->value . '|'
. MeetingTypes::VIRT->value . ') ([0-9]+))(?:.([0-9]+))?(?:.([0-9]+))?/';
$meetingRegex = '/(?:(' . implode('|', MeetingTypes::getSearchableStrings()) . ')'
. ' ([0-9]+))(?:.([0-9]+))?(?:.([0-9]+))?/';
$meetingInfo = [];
if (1 === preg_match($meetingRegex, $query, $meetingInfo, PREG_UNMATCHED_AS_NULL)) {
$meetingType = MeetingTypes::from($meetingInfo[1]);
$meetingType = MeetingTypes::tryFromSearch($meetingInfo[1]);
$meetingNumber = (int) $meetingInfo[2];

$where = 'd.meeting_type = :meeting_type AND d.meeting_number = :meeting_number';
Expand Down
32 changes: 32 additions & 0 deletions module/Decision/src/Model/Enums/MeetingTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Decision\Model\Enums;

use InvalidArgumentException;
use Laminas\Mvc\I18n\Translator;

use function array_column;

/**
* Enum for the different address types.
*/
Expand Down Expand Up @@ -35,4 +38,33 @@ public function getAbbreviation(Translator $translator): string
self::VIRT => $translator->translate('VIRT'),
};
}

/**
* @return string[]
*/
public static function getSearchableStrings(): array
{
return [
...array_column(self::cases(), 'value'),
'GMM',
'BM',
'CM',
];
}

public static function tryFromSearch(string $input): MeetingTypes
{
$value = self::tryFrom($input);

if (null !== $value) {
return $value;
}

return match ($input) {
'GMM' => MeetingTypes::ALV,
'BM' => MeetingTypes::BV,
'CM' => MeetingTypes::VV,
default => throw new InvalidArgumentException('MeetingType is not recognized'),
};
}
}