Skip to content

Commit

Permalink
Merge pull request #88 from Chloe070196/toggle_display_location_in_se…
Browse files Browse the repository at this point in the history
…arch_facets

Toggle display location in search facets
  • Loading branch information
Chloe070196 authored Jul 26, 2024
2 parents 4925c7b + f15c6a7 commit 6e8e4bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/web/release_notes/24.08.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ To generate the passkey file, the following command should be run (as root):

// other

// chloe
### Other Updates
- Adds a new setting to Location(branch) which enables admins to toggle the visibility of specific branches under the 'Available At' search facet.

## This release includes code contributions from
- ByWater Solutions
- Mark Noble (MDN)
Expand All @@ -113,6 +117,7 @@ To generate the passkey file, the following command should be run (as root):
- PTFS-Europe
- Pedro Amorim (PA)
- Alexander Blanchard (AB)
- Chloe Zermatten (CZ)
- Jacob O'Mara (JOM)

- Theke Solutions
Expand Down
19 changes: 19 additions & 0 deletions code/web/sys/DBMaintenance/version_updates/24.08.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ function getUpdates24_08_00(): array {
]
], //web_builder_custom_form_increase_email

//James Staub - Nashville Public Library
'web_builder_custom_form_increase_email' => [
'title' => 'Increase Web Builder Custom Form "Email Results To" field character limit.',
'description' => 'Increase Web Builder Custom Form "Email Results To" field character limit.',
'continueOnError' => true,
'sql' => [
"ALTER TABLE web_builder_custom_form MODIFY COLUMN emailResultsTo VARCHAR(150)",
]
], //web_builder_custom_form_increase_email

//chloe - PTFS-Europe
'show_in_search_facet_column' => [
'title' => 'Show In Search Facet Column',
'description' => 'Adds the showInSearchFacet column to the Location table',
// 'continueOnError' => false,
'sql' => [
'ALTER TABLE location ADD COLUMN showInSearchFacet TINYINT(1) DEFAULT 1'
]
], //show_in_search_facet_column
//other

];
Expand Down
10 changes: 10 additions & 0 deletions code/web/sys/LibraryLocation/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Location extends DataObject {
public $createSearchInterface;
public $showInSelectInterface;
public $showOnDonationsPage;
public $showInSearchFacet;
public $enableAppAccess;
public $appReleaseChannel;
public $theme;
Expand Down Expand Up @@ -891,6 +892,15 @@ static function getObjectStructure($context = ''): array {
'default' => true,
'forcesReindex' => true,
],
[
'property' => 'showInSearchFacet',
'type' => 'checkbox',
'label' => 'Show This Branch In Search Facet',
'description' => 'Whether or not the library should appear as a location that can be selected to filter search results by.',
'hideInLists' => true,
'default' => true,
'forcesReindex' => false,
],
[
'property' => 'additionalLocationsToShowAvailabilityFor',
'type' => 'text',
Expand Down
24 changes: 24 additions & 0 deletions code/web/sys/SearchObject/GroupedWorkSearcher2.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,34 @@ public function getFacetList($filter = null) {
$numValidLibraries = 0;
// Loop through values:
$isScopedField = $this->isScopedField($field);

// Get a list of branches so we can access their 'showInSearchFacet' value
// Also rename the keys to the branches' names so they can easily be accessed later
$branchList = null;
if ($field == 'available_at' || $field == 'owning_location') {
$mainBranch = new Location();
$branchList = $mainBranch->getLocationListAsObjects(false);
// may need to be optimised / unsure how heavy this is
foreach ($branchList as $key=>$value) {
$branchList[$value->displayName] = $value;
unset($branchList[$key]);
}
}
foreach ($data as $facet) {
// Initialize the array of data about the current facet:
$currentSettings = [];
$facetValue = $facet[0];

// if populating the array of facet options for 'available at'
// then filter out any branch (location) for which showInSearchFacet has been set to "0"
// thus preventing these branches from being displayed as search by options
if ($field == 'available_at' || $field == 'owning_location') {
$branchName = substr($facetValue, 5);
if (empty($branchList[$branchName]->showInSearchFacet)) {
continue;
}
}

if ($isScopedField && strpos($facetValue, '#') !== false) {
$facetValue = substr($facetValue, strpos($facetValue, '#') + 1);
}
Expand Down

0 comments on commit 6e8e4bd

Please sign in to comment.