-
Notifications
You must be signed in to change notification settings - Fork 393
Add support for "new items" facet. #4996
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,8 @@ | |||||||||||||||
|
|
||||||||||||||||
| use VuFind\Config\Config; | ||||||||||||||||
| use VuFind\Config\ConfigManagerInterface; | ||||||||||||||||
| use VuFind\Date\Converter as DateConverter; | ||||||||||||||||
| use VuFind\Solr\Utils; | ||||||||||||||||
| use VuFindSearch\ParamBag; | ||||||||||||||||
|
|
||||||||||||||||
| use function count; | ||||||||||||||||
|
|
@@ -105,13 +107,6 @@ class Params extends \VuFind\Search\Base\Params | |||||||||||||||
| */ | ||||||||||||||||
| protected $pivotFacets = null; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Hierarchical Facet Helper | ||||||||||||||||
| * | ||||||||||||||||
| * @var HierarchicalFacetHelper | ||||||||||||||||
| */ | ||||||||||||||||
| protected $facetHelper; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Are we searching by ID only (instead of a normal query)? | ||||||||||||||||
| * | ||||||||||||||||
|
|
@@ -149,14 +144,15 @@ class Params extends \VuFind\Search\Base\Params | |||||||||||||||
| * @param \VuFind\Search\Base\Options $options Options to use | ||||||||||||||||
| * @param ConfigManagerInterface $configManager Config manager | ||||||||||||||||
| * @param ?HierarchicalFacetHelper $facetHelper Hierarchical facet helper | ||||||||||||||||
| * @param ?DateConverter $dateConverter Date converter | ||||||||||||||||
| */ | ||||||||||||||||
| public function __construct( | ||||||||||||||||
| $options, | ||||||||||||||||
| ConfigManagerInterface $configManager, | ||||||||||||||||
| ?HierarchicalFacetHelper $facetHelper = null | ||||||||||||||||
| protected ?HierarchicalFacetHelper $facetHelper = null, | ||||||||||||||||
| protected ?DateConverter $dateConverter = null | ||||||||||||||||
| ) { | ||||||||||||||||
| parent::__construct($options, $configManager); | ||||||||||||||||
| $this->facetHelper = $facetHelper; | ||||||||||||||||
|
|
||||||||||||||||
| // Use basic facet limit by default, if set: | ||||||||||||||||
| $facetConfigName = $options->getFacetsIni(); | ||||||||||||||||
|
|
@@ -680,6 +676,10 @@ public function getPivotFacets() | |||||||||||||||
| */ | ||||||||||||||||
| protected function formatFilterListEntry($field, $value, $operator, $translate) | ||||||||||||||||
| { | ||||||||||||||||
| if (isset($this->options->getNewItemsFacets()[$field])) { | ||||||||||||||||
| return $this->formatNewItemsFilterListEntry($field, $value, $operator, $translate); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| $filter = parent::formatFilterListEntry( | ||||||||||||||||
| $field, | ||||||||||||||||
| $value, | ||||||||||||||||
|
|
@@ -742,6 +742,65 @@ function ($part) { | |||||||||||||||
| return $filter; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Format a new items filter for use in getFilterList(). | ||||||||||||||||
| * | ||||||||||||||||
| * @param string $field Field name | ||||||||||||||||
| * @param string $value Field value | ||||||||||||||||
| * @param string $operator Operator (AND/OR/NOT) | ||||||||||||||||
| * @param bool $translate Should we translate the label? | ||||||||||||||||
| * | ||||||||||||||||
| * @return array | ||||||||||||||||
| */ | ||||||||||||||||
| protected function formatNewItemsFilterListEntry($field, $value, $operator, $translate): array | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| { | ||||||||||||||||
| $range = Utils::parseRange($value); | ||||||||||||||||
| $domain = $this->getOptions()->getTextDomainForTranslatedFacet($field); | ||||||||||||||||
| [$from, $fromDate] = $this->formatNewItemsDateForDisplay( | ||||||||||||||||
| $range['from'], | ||||||||||||||||
| $domain | ||||||||||||||||
| ); | ||||||||||||||||
| [$to, $toDate] = $this->formatNewItemsDateForDisplay( | ||||||||||||||||
| $range['to'], | ||||||||||||||||
| $domain | ||||||||||||||||
| ); | ||||||||||||||||
| $ndash = html_entity_decode('–', ENT_NOQUOTES, 'UTF-8'); | ||||||||||||||||
| if ($fromDate && $toDate) { | ||||||||||||||||
| $displayText = $from ? "$from $ndash" : $ndash; | ||||||||||||||||
| $displayText .= $to ? " $to" : ''; | ||||||||||||||||
| } else { | ||||||||||||||||
| $displayText = $from; | ||||||||||||||||
| $displayText .= $to ? " $ndash $to" : ''; | ||||||||||||||||
| } | ||||||||||||||||
| return compact('value', 'displayText', 'field', 'operator'); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Format a Solr date for display | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should expand this comment to explain the return value... because at present, I don't entirely understand what the second Boolean value is doing. |
||||||||||||||||
| * | ||||||||||||||||
| * @param string $date Date | ||||||||||||||||
| * @param string $domain Translation domain | ||||||||||||||||
| * | ||||||||||||||||
| * @return string | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| */ | ||||||||||||||||
| protected function formatNewItemsDateForDisplay($date, $domain) | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| { | ||||||||||||||||
| if ($date == '' || $date == '*') { | ||||||||||||||||
| return ['', true]; | ||||||||||||||||
| } | ||||||||||||||||
| if (preg_match('/^NOW-(\d+)DAY/', $date, $matches)) { | ||||||||||||||||
| return [ | ||||||||||||||||
| $this->translate('past_days', ['range' => $matches[1]], useIcuFormatter: true), | ||||||||||||||||
| false, | ||||||||||||||||
| ]; | ||||||||||||||||
| } | ||||||||||||||||
| $date = substr($date, 0, 10); | ||||||||||||||||
| return [ | ||||||||||||||||
| $this->dateConverter?->convertToDisplayDate('Y-m-d', $date) ?? $date, | ||||||||||||||||
| true, | ||||||||||||||||
| ]; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Get information on the current state of the boolean checkbox facets. | ||||||||||||||||
| * | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -453,9 +453,9 @@ protected function getAliasesForFacetField($field) | |||||
| /** | ||||||
| * Remove a facet from the parameters. | ||||||
| * | ||||||
| * @param string $field Facet field | ||||||
| * @param string $value Facet value | ||||||
| * @param string $operator Facet type to add (AND, OR, NOT) | ||||||
| * @param string $field Facet field | ||||||
| * @param ?string $value Facet value, or null to remove all values for the facet field | ||||||
| * @param string $operator Facet type to add (AND, OR, NOT) | ||||||
| * | ||||||
| * @return UrlQueryHelper | ||||||
| */ | ||||||
|
|
@@ -480,7 +480,7 @@ public function removeFacet($field, $value, $operator = 'AND') | |||||
| = $this->parseFilter($current); | ||||||
| if ( | ||||||
| !in_array($currentField, $fieldAliases) | ||||||
| || $currentValue != $value | ||||||
| || (null !== $value && $currentValue != $value) | ||||||
| ) { | ||||||
| $newFilter[] = $current; | ||||||
| } | ||||||
|
|
@@ -498,6 +498,21 @@ public function removeFacet($field, $value, $operator = 'AND') | |||||
| return new static($params, $this->queryObject, $this->config, false); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Remove any instance of the facet from the parameters and add a new one. | ||||||
| * | ||||||
| * @param string $field Facet field | ||||||
| * @param string $value Facet value | ||||||
| * @param string $operator Facet type to add (AND, OR, NOT) | ||||||
| * | ||||||
| * @return string | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure this isn't returning a string...
Suggested change
|
||||||
| */ | ||||||
| public function replaceFacet($field, $value, $operator = 'AND') | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well add types to new methods...
Suggested change
|
||||||
| { | ||||||
| return $this->removeFacet($field, null, $operator) | ||||||
| ->addFacet($field, $value, $operator); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Remove a filter from the parameters. | ||||||
| * | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor formatting suggestions: