Skip to content

Commit

Permalink
Merge pull request #1719 from tomudding/feature/decision-search-english
Browse files Browse the repository at this point in the history
Allow searching for decision using the English abbreviations for meeting
  • Loading branch information
tomudding authored Sep 26, 2023
2 parents 532d2d7 + 7581f51 commit e0cd4ee
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
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'),
};
}
}

0 comments on commit e0cd4ee

Please sign in to comment.