Skip to content

Commit

Permalink
fix GetSearchResults in-memory sort (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbraswell authored Dec 19, 2022
1 parent e946626 commit c419f5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/Repositories/MeetingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function getSearchResults(

return $meetings->sortBy([function ($m1, $m2) use ($sortKeys, $mainTableKeys, $dataByMeeting) {
foreach ($sortKeys as $sortKey) {
if (isset($mainTableKeys[$sortKey])) {
if (array_key_exists($sortKey, $mainTableKeys)) {
$field1 = $m1->{$sortKey};
$field2 = $m2->{$sortKey};
} else {
Expand Down
22 changes: 22 additions & 0 deletions src/tests/Feature/GetSearchResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,28 @@ public function testSortKeysLongDataFields()
}
}

public function testSortKeysMultipleFields()
{
$meeting1 = $this->createMeeting(['weekday_tinyint' => 1, 'start_time' => '19:00:00', ['meeting_name' => 'abc']]);
$meeting2 = $this->createMeeting(['weekday_tinyint' => 1, 'start_time' => '09:00:00', ['meeting_name' => 'abc']]);
$meeting3 = $this->createMeeting(['weekday_tinyint' => 2, 'start_time' => '23:59:59', ['meeting_name' => 'abc']]);
$meeting4 = $this->createMeeting(['weekday_tinyint' => 2, 'start_time' => '01:00:00', ['meeting_name' => 'abc']]);
$meeting5 = $this->createMeeting(['weekday_tinyint' => 3, 'start_time' => '01:00:00'], ['meeting_name' => 'def']);
$meeting6 = $this->createMeeting(['weekday_tinyint' => 3, 'start_time' => '01:00:00'], ['meeting_name' => 'abc']);

$data = collect($this->get("/client_interface/json/?switcher=GetSearchResults&sort_keys=weekday_tinyint,start_time,meeting_name")
->assertStatus(200)
->assertJsonCount(6)
->json());

$this->assertEquals(strval($meeting2->id_bigint), $data[0]['id_bigint']);
$this->assertEquals(strval($meeting1->id_bigint), $data[1]['id_bigint']);
$this->assertEquals(strval($meeting4->id_bigint), $data[2]['id_bigint']);
$this->assertEquals(strval($meeting3->id_bigint), $data[3]['id_bigint']);
$this->assertEquals(strval($meeting6->id_bigint), $data[4]['id_bigint']);
$this->assertEquals(strval($meeting5->id_bigint), $data[5]['id_bigint']);
}

// data_field_key
//
//
Expand Down

0 comments on commit c419f5c

Please sign in to comment.