Skip to content

Commit

Permalink
Added functionality for searching for meetings
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarhunt authored and rinkp committed Feb 17, 2024
1 parent 9fa82bc commit 97d459a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
11 changes: 10 additions & 1 deletion module/Database/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@
],
],
],
'search' => [
'type' => Literal::class,
'options' => [
'route' => '/search',
'defaults' => [
'action' => 'searchDecision',
],
],
],
],
],
'view' => [
Expand Down Expand Up @@ -133,7 +142,7 @@
'options' => [
'route' => '/search',
'defaults' => [
'action' => 'search',
'action' => 'searchMeeting',
],
],
],
Expand Down
21 changes: 19 additions & 2 deletions module/Database/src/Controller/MeetingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,28 @@ public function deleteAction(): ViewModel
}

/**
* Search action.
* Search action for meetings.
*
* Uses JSON to search for decisions.
*/
public function searchAction(): JsonModel
public function searchMeetingAction(): JsonModel
{
$query = $this->params()->fromQuery('q');
$res = $this->meetingService->meetingSearch($query);

$res = array_map(static function ($meeting) {
return $meeting->toArray();
}, $res);

return new JsonModel(['json' => $res]);
}

/**
* Search action for decisions.
*
* Uses JSON to search for decisions.
*/
public function searchDecisionAction(): JsonModel
{
$query = $this->params()->fromQuery('q');
$res = $this->meetingService->decisionSearch($query);
Expand Down
30 changes: 30 additions & 0 deletions module/Database/src/Mapper/Meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ public function isManaged(MeetingModel $meeting): bool
return $this->em->getUnitOfWork()->isInIdentityMap($meeting);
}

/**
* Search for a meeting.
*
* @return MeetingModel[]
*/
public function searchMeeting(
string $query,
): array {
$qb = $this->em->createQueryBuilder();

$fields = [];
$fields[] = 'LOWER(m.type)';
$fields[] = "' '";
$fields[] = 'm.number';
$fields[] = "' '";
$fields = implode(', ', $fields);
$fields = 'CONCAT(' . $fields . ')';

$qb->select('m')
->from(MeetingModel::class, 'm')
->where($fields . ' LIKE :search')
->andWhere('CONCAT(m.number, \'\') NOT LIKE :searchClean')
->orderBy('m.date');

$qb->setParameter(':search', '%' . strtolower($query) . '%');
$qb->setParameter(':searchClean', '%_' . strtolower($query));

return $qb->getQuery()->getResult();
}

/**
* Find all meetings. Also counts all decision per meeting.
*
Expand Down
16 changes: 16 additions & 0 deletions module/Database/src/Model/Meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,20 @@ public function addDecisions(array $decisions): void
$this->addDecision($decision);
}
}

/**
* Transform into an array.
*
* @return array{
* meeting_type: MeetingTypes,
* meeting_number: int,
* }
*/
public function toArray(): array
{
return [
'meeting_type' => $this->getType(),
'meeting_number' => $this->getNumber(),
];
}
}
10 changes: 10 additions & 0 deletions module/Database/src/Service/Meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,16 @@ public function decisionSearch(string $query): array
return $this->getMeetingMapper()->searchDecision($query);
}

/**
* Search for meetings by name.
*
* @return MeetingModel[]
*/
public function meetingSearch(string $query): array
{
return $this->getMeetingMapper()->searchMeeting($query);
}

/**
* Get the foundation of an organ.
*/
Expand Down
2 changes: 1 addition & 1 deletion module/Database/view/database/meeting/destroyform.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(document).ready(function() {
source: function(rq, response) {
$.ajax({
dataType: 'json',
url: '<?= $this->url('meeting/search') ?>?q=' + rq.term,
url: '<?= $this->url('meeting/decision/search') ?>?q=' + rq.term,
context: document.body
}).done(function(data) {
var ret = [];
Expand Down

0 comments on commit 97d459a

Please sign in to comment.