Example #1
0
 /**
  * Format a single 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 formatFilterListEntry($field, $value, $operator, $translate)
 {
     $res = parent::formatFilterListEntry($field, $value, $operator, $translate);
     if ($this->spatialDateRangeFilter && isset($this->spatialDateRangeFilter['field']) && $this->spatialDateRangeFilter['field'] == $field) {
         $filter = $this->spatialDateRangeFilter['val'];
         $type = isset($this->spatialDateRangeFilter['type']) ? $this->spatialDateRangeFilter['type'] : null;
         $range = Utils::parseSpatialDateRange($filter, $type, true);
         if ($range) {
             $display = '';
             $from = $range['from'];
             $to = $range['to'];
             if ($from != '*') {
                 $display .= $from;
             }
             $display .= '–';
             if ($to != '*') {
                 $display .= $to;
             }
             $res['displayText'] = $display;
         }
     }
     return $res;
 }
Example #2
0
 /**
  * Initialize date range filter (search_daterange_mv)
  *
  * @param \Zend\StdLib\Parameters $request Parameter object representing user
  * request.
  *
  * @return void
  */
 public function initSpatialDateRangeFilter($request)
 {
     $type = $request->get('search_daterange_mv_type');
     if (!$type) {
         $type = $request->get('search_sdaterange_mvtype');
     }
     if (!$type) {
         $type = 'overlap';
     }
     $dateFilter = [];
     $dateFilter['type'] = $type;
     $from = $to = null;
     $filters = $this->getFilters();
     $found = false;
     // VuFind1/VuFind2 date range filter
     if ($reqFilters = $request->get('filter')) {
         foreach ($reqFilters as $f) {
             list($field, $value) = $this->parseFilter($f);
             $daterange_VF1 = $field == self::SPATIAL_DATERANGE_FIELD_VF1;
             $daterange = $field == self::SPATIAL_DATERANGE_FIELD;
             if ($daterange || $daterange_VF1) {
                 if ($range = Utils::parseSpatialDateRange($f, $type, $daterange)) {
                     $from = $range['from'];
                     $to = $range['to'];
                     $found = true;
                     break;
                 }
             }
         }
     }
     // Uninitialized VuFind1 date range query
     if (!$found && $request->get('sdaterange')) {
         // Search for VuFind1 search_sdaterange_mvfrom, search_sdaterange_mvto
         $from = $request->get('search_sdaterange_mvfrom');
         if ($from === null) {
             $from = -9999;
         }
         $to = $request->get('search_sdaterange_mvto');
         if ($to === null) {
             $to = 9999;
         }
         $vufind2Range = false;
         $found = true;
     }
     $this->spatialDateRangeFilter = $dateFilter;
     if (!$found) {
         return;
     }
     $dateFilter['to'] = $to;
     $dateFilter['from'] = $from;
     $dateFilter['val'] = "[{$from} TO {$to}]";
     $dateFilter['field'] = self::SPATIAL_DATERANGE_FIELD;
     $dateFilter['query'] = $dateFilter['field'] . ':' . $dateFilter['val'];
     $this->spatialDateRangeFilter = $dateFilter;
     parent::addFilter($dateFilter['query']);
 }
Example #3
0
 /**
  * Format a single 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 formatFilterListEntry($field, $value, $operator, $translate)
 {
     if (!in_array($field, $this->newItemsFacets) || !($range = Utils::parseRange($value))) {
         return parent::formatFilterListEntry($field, $value, $operator, $translate);
     }
     $domain = $this->getOptions()->getTextDomainForTranslatedFacet($field);
     list($from, $fromDate) = $this->formatNewItemsDateForDisplay($range['from'], $domain);
     list($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');
 }