function isValidForUser($locationCode, $eContentFieldData)
 {
     $sharing = $this->getSharing($locationCode, $eContentFieldData);
     if ($sharing == 'shared') {
         $searchLibrary = Library::getSearchLibrary();
         if ($searchLibrary == null || $searchLibrary->econtentLocationsToInclude == 'all' || strlen($searchLibrary->econtentLocationsToInclude) == 0 || strpos($searchLibrary->econtentLocationsToInclude, $locationCode) !== FALSE) {
             return true;
         } else {
             return false;
         }
     } else {
         if ($sharing == 'library') {
             $searchLibrary = Library::getSearchLibrary();
             if ($searchLibrary == null || $searchLibrary->includeOutOfSystemExternalLinks || strlen($searchLibrary->ilsCode) > 0 && strpos($locationCode, $searchLibrary->ilsCode) === 0) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $searchLibrary = Library::getSearchLibrary();
             $searchLocation = Location::getSearchLocation();
             if ($searchLibrary->includeOutOfSystemExternalLinks || strpos($locationCode, $searchLocation->code) === 0) {
                 return true;
             } else {
                 return false;
             }
         }
     }
 }
 public function getLibraryScopingId()
 {
     //For econtent, we need to be more specific when restricting copies
     //since patrons can't use copies that are only available to other libraries.
     $searchLibrary = Library::getSearchLibrary();
     $searchLocation = Location::getSearchLocation();
     $activeLibrary = Library::getActiveLibrary();
     $activeLocation = Location::getActiveLocation();
     $homeLibrary = Library::getPatronHomeLibrary();
     //Load the holding label for the branch where the user is physically.
     if (!is_null($homeLibrary)) {
         return $homeLibrary->includeOutOfSystemExternalLinks ? -1 : $homeLibrary->libraryId;
     } else {
         if (!is_null($activeLocation)) {
             $activeLibrary = Library::getLibraryForLocation($activeLocation->locationId);
             return $activeLibrary->includeOutOfSystemExternalLinks ? -1 : $activeLibrary->libraryId;
         } else {
             if (isset($activeLibrary)) {
                 return $activeLibrary->includeOutOfSystemExternalLinks ? -1 : $activeLibrary->libraryId;
             } else {
                 if (!is_null($searchLocation)) {
                     $searchLibrary = Library::getLibraryForLocation($searchLibrary->locationId);
                     return $searchLibrary->includeOutOfSystemExternalLinks ? -1 : $searchLocation->libraryId;
                 } else {
                     if (isset($searchLibrary)) {
                         return $searchLibrary->includeOutOfSystemExternalLinks ? -1 : $searchLibrary->libraryId;
                     } else {
                         return -1;
                     }
                 }
             }
         }
     }
 }
Example #3
0
 static function getSearchLibrary($searchSource = null)
 {
     if (is_null($searchSource)) {
         global $searchSource;
         if (strpos($searchSource, 'library') === 0) {
             $trimmedSearchSource = str_replace('library', '', $searchSource);
             require_once ROOT_DIR . '/Drivers/marmot_inc/LibrarySearchSource.php';
             $librarySearchSource = new LibrarySearchSource();
             $librarySearchSource->id = $trimmedSearchSource;
             if ($librarySearchSource->find(true)) {
                 $searchSource = $librarySearchSource;
             }
         }
     }
     if (!array_key_exists($searchSource, Library::$searchLibrary)) {
         if (is_object($searchSource)) {
             $scopingSetting = $searchSource->catalogScoping;
         } else {
             $scopingSetting = $searchSource;
         }
         if ($scopingSetting == 'local' || $scopingSetting == 'econtent' || $scopingSetting == 'library' || $scopingSetting == 'location') {
             Library::$searchLibrary[$searchSource] = Library::getActiveLibrary();
         } else {
             if ($scopingSetting == 'marmot' || $scopingSetting == 'unscoped') {
                 Library::$searchLibrary[$searchSource] = null;
             } else {
                 $location = Location::getSearchLocation();
                 if (is_null($location)) {
                     //Check to see if we have a library for the subdomain
                     $library = new Library();
                     $library->subdomain = $scopingSetting;
                     $library->find();
                     if ($library->N > 0) {
                         $library->fetch();
                         return clone $library;
                     }
                     Library::$searchLibrary[$searchSource] = null;
                 } else {
                     Library::$searchLibrary[$searchSource] = self::getLibraryForLocation($location->locationId);
                 }
             }
         }
     }
     return Library::$searchLibrary[$searchSource];
 }
 public function getItemsFast()
 {
     global $configArray;
     if ($this->fastItems == null) {
         $searchLibrary = Library::getSearchLibrary();
         if ($searchLibrary) {
             $libraryLocationCode = $searchLibrary->ilsCode;
         }
         $searchLocation = Location::getSearchLocation();
         if ($searchLocation) {
             $homeLocationCode = $searchLocation->code;
         } else {
             $homeLocation = Location::getUserHomeLocation();
             if ($homeLocation) {
                 $homeLocationCode = $homeLocation->code;
             }
         }
         $this->fastItems = array();
         if ($this->itemsFromIndex) {
             $this->fastItems = array();
             foreach ($this->itemsFromIndex as $itemData) {
                 $isLocalItem = false;
                 $isLibraryItem = false;
                 if (array_key_exists('item', $itemData)) {
                     $itemId = $itemData['item'][0];
                     $locationCode = $itemData['item'][1];
                     $shelfLocation = mapValue('shelf_location', $locationCode);
                     $sharing = $itemData['item'][3];
                     $source = $itemData['item'][4];
                     $fileOrUrl = '';
                     if (count($itemData['item']) > 5) {
                         $fileOrUrl = $itemData['item'][5];
                     }
                     if (array_key_exists('scope', $itemData)) {
                         $isLocalItem = $itemData['scope'][1] == 'true';
                         $isLibraryItem = $itemData['scope'][2] == 'true';
                     }
                 } else {
                     $itemId = $itemData[1];
                     $locationCode = $itemData[2];
                     $shelfLocation = mapValue('shelf_location', $itemData[2]);
                     $sharing = $itemData[4];
                     $source = $itemData[5];
                     $fileOrUrl = '';
                     if (count($itemData) > 6) {
                         $fileOrUrl = $itemData[6];
                     }
                     $isLocalItem = isset($libraryLocationCode) && strlen($libraryLocationCode) > 0 && strpos($locationCode, $libraryLocationCode) === 0;
                     $isLibraryItem = isset($homeLocationCode) && strlen($homeLocationCode) > 0 && strpos($locationCode, $homeLocationCode) === 0;
                 }
                 $actions = $this->getActionsForItem($itemId, $fileOrUrl, null);
                 $libraryLabelObj = new Library();
                 $libraryLabelObj->whereAdd("'{$locationCode}' LIKE CONCAT(ilsCode, '%') and ilsCode <> ''");
                 $libraryLabelObj->selectAdd();
                 $libraryLabelObj->selectAdd('displayName');
                 if ($libraryLabelObj->find(true)) {
                     $libraryLabel = $libraryLabelObj->displayName;
                 } else {
                     $libraryLabel = $locationCode . ' Online';
                 }
                 //TODO: Get the correct number of available copies
                 $totalCopies = 1;
                 $this->fastItems[] = array('itemId' => $itemId, 'location' => $locationCode, 'callnumber' => '', 'availability' => $this->isItemAvailable($itemId, $totalCopies), 'holdable' => $this->isEContentHoldable($locationCode, $itemData), 'inLibraryUseOnly' => false, 'isLocalItem' => $isLocalItem, 'isLibraryItem' => $isLibraryItem, 'locationLabel' => 'Online', 'libraryLabel' => $libraryLabel, 'shelfLocation' => $shelfLocation, 'source' => 'Online ' . $source, 'sharing' => $sharing, 'actions' => $actions);
             }
         } else {
             /** @var File_MARC_Data_Field[] $itemFields */
             $itemFields = $this->getMarcRecord()->getFields('989');
             foreach ($itemFields as $itemField) {
                 $locationCode = trim($itemField->getSubfield('d') != null ? $itemField->getSubfield('d')->getData() : '');
                 //Each item can have multiple item fields
                 /** @var File_MARC_Subfield[] $eContentFields */
                 $eContentFields = $itemField->getSubfields('w');
                 $itemId = $itemField->getSubfield('1')->getData();
                 $iType = $itemField->getSubfield($configArray['Reindex']['iTypeSubfield'])->getData();
                 foreach ($eContentFields as $eContentField) {
                     $eContentData = trim($eContentField->getData() != null ? $eContentField->getData() : '');
                     if ($eContentData && strpos($eContentData, ':') > 0) {
                         $eContentFieldData = explode(':', $eContentData);
                         $source = trim($eContentFieldData[0]);
                         $protectionType = strtolower(trim($eContentFieldData[1]));
                         $totalCopies = 1;
                         if ($this->isValidProtectionType($protectionType)) {
                             if ($this->isValidForUser($locationCode, $eContentFieldData)) {
                                 $libraryLabelObj = new Library();
                                 $libraryLabelObj->whereAdd("'{$locationCode}' LIKE CONCAT(ilsCode, '%') and ilsCode <> ''");
                                 $libraryLabelObj->selectAdd();
                                 $libraryLabelObj->selectAdd('displayName');
                                 if ($libraryLabelObj->find(true)) {
                                     $libraryLabel = $libraryLabelObj->displayName;
                                 } else {
                                     $libraryLabel = $locationCode . ' Online';
                                 }
                                 $locationLabelObj = new Location();
                                 $locationLabelObj->whereAdd("'{$locationCode}' LIKE CONCAT(code, '%') and code <> ''");
                                 if ($locationLabelObj->find(true)) {
                                     $locationLabel = $locationLabelObj->displayName;
                                 } else {
                                     $locationLabel = $locationCode . ' Online';
                                 }
                                 //Get the file or url that is related to this item.
                                 $fileOrUrl = '';
                                 $acsId = null;
                                 if ($protectionType == 'external') {
                                     $urlSubfield = $itemField->getSubfield('u');
                                     if ($urlSubfield != null) {
                                         $fileOrUrl = $urlSubfield->getData();
                                     } else {
                                         //Get from the 856 field
                                         /** @var File_MARC_Data_Field[] $linkFields */
                                         $linkFields = $this->getMarcRecord()->getFields('856');
                                         foreach ($linkFields as $link) {
                                             $urlSubfield = $link->getSubfield('u');
                                             if ($urlSubfield != null) {
                                                 $fileOrUrl = $urlSubfield->getData();
                                             }
                                         }
                                     }
                                 } else {
                                     if (count($eContentFieldData) > 3) {
                                         $fileOrUrl = trim($eContentFieldData[3]);
                                     }
                                     if (count($eContentFieldData) > 4) {
                                         $acsId = trim($eContentFieldData[4]);
                                     }
                                     if (count($eContentFieldData) > 5) {
                                         $totalCopies = trim($eContentFieldData[5]);
                                     }
                                 }
                                 $fileOrUrl = trim($fileOrUrl);
                                 $actions = $this->getActionsForItem($itemId, $fileOrUrl, $acsId);
                                 $format = $this->getEContentFormat($fileOrUrl, $iType);
                                 $sharing = $this->getSharing($locationCode, $eContentFieldData);
                                 //Add an item
                                 $item = array('itemId' => $itemId, 'location' => $locationCode, 'locationLabel' => $locationLabel, 'libraryLabel' => $libraryLabel, 'callnumber' => '', 'availability' => $this->isItemAvailable($itemId, $totalCopies), 'holdable' => $this->isEContentHoldable($locationCode, $eContentFieldData), 'isLocalItem' => $this->isLocalItem($locationCode, $eContentFieldData), 'isLibraryItem' => $this->isLibraryItem($locationCode, $eContentFieldData), 'shelfLocation' => 'Online ' . $source, 'source' => $source, 'sharing' => $sharing, 'fileOrUrl' => $fileOrUrl, 'format' => $format, 'helpText' => $this->getHelpText($fileOrUrl), 'usageNotes' => $this->getUsageRestrictions($sharing, $libraryLabel, $locationLabel), 'formatNotes' => $this->getFormatNotes($fileOrUrl), 'size' => $this->getFileSize($fileOrUrl), 'actions' => $actions);
                                 $this->fastItems[] = $item;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->fastItems;
 }
Example #5
0
function loadSearchInformation()
{
    //Determine the Search Source, need to do this always.
    global $searchSource;
    global $library;
    global $interface;
    $module = isset($_GET['module']) ? $_GET['module'] : null;
    $module = preg_replace('/[^\\w]/', '', $module);
    $searchSource = 'global';
    if (isset($_GET['searchSource'])) {
        $searchSource = $_GET['searchSource'];
        $_REQUEST['searchSource'] = $searchSource;
        //Update request since other check for it here
        $_SESSION['searchSource'] = $searchSource;
        //Update the session so we can remember what the user was doing last.
    } else {
        if (isset($_SESSION['searchSource'])) {
            //Didn't get a source, use what the user was doing last
            $searchSource = $_SESSION['searchSource'];
            $_REQUEST['searchSource'] = $searchSource;
        } else {
            //Use a default search source
            if ($module == 'Person') {
                $searchSource = 'genealogy';
            } else {
                $searchSource = 'local';
            }
            $_REQUEST['searchSource'] = $searchSource;
        }
    }
    $searchLibrary = Library::getSearchLibrary(null);
    $searchLocation = Location::getSearchLocation(null);
    //Based on the search source, determine the search scope and set a global variable
    global $solrScope;
    global $scopeType;
    $solrScope = false;
    $scopeType = '';
    if ($searchSource == 'local' || $searchSource == 'econtent') {
        $locationIsScoped = $searchLocation != null && ($searchLocation->restrictSearchByLocation || $searchLocation->econtentLocationsToInclude != 'all' || $searchLocation->useScope || !$searchLocation->enableOverdriveCollection || strlen($searchLocation->extraLocationCodesToInclude) > 0);
        $libraryIsScoped = $searchLibrary != null && ($searchLibrary->restrictSearchByLibrary || $searchLibrary->econtentLocationsToInclude != 'all' || strlen($searchLibrary->pTypes) > 0 && $searchLibrary->pTypes != -1 || $searchLibrary->useScope || !$searchLibrary->enableOverdriveCollection);
        if ($locationIsScoped && ($searchLocation->econtentLocationsToInclude != $searchLibrary->econtentLocationsToInclude && strlen($searchLocation->econtentLocationsToInclude) > 0 && $searchLocation->econtentLocationsToInclude != 'all' || $searchLocation->useScope && $searchLibrary->scope != $searchLocation->scope)) {
            $solrScope = $searchLocation->code;
            $scopeType = 'Location';
        } else {
            $solrScope = $searchLibrary->subdomain;
            $scopeType = 'Library';
        }
    } elseif ($searchSource != 'marmot' && $searchSource != 'global') {
        $solrScope = $searchSource;
        $scopeType = 'Search Source';
    }
    $solrScope = trim($solrScope);
    if (strlen($solrScope) == 0) {
        $solrScope = false;
        $scopeType = 'Unscoped';
    }
    $searchLibrary = Library::getSearchLibrary($searchSource);
    $searchLocation = Location::getSearchLocation($searchSource);
    global $millenniumScope;
    if ($library) {
        if ($searchLibrary) {
            $millenniumScope = $searchLibrary->scope;
        } elseif (isset($searchLocation)) {
            MillenniumDriver::$scopingLocationCode = $searchLocation->code;
        } else {
            $millenniumScope = isset($configArray['OPAC']['defaultScope']) ? $configArray['OPAC']['defaultScope'] : '93';
        }
    } else {
        $millenniumScope = isset($configArray['OPAC']['defaultScope']) ? $configArray['OPAC']['defaultScope'] : '93';
    }
}
Example #6
0
 public function getMillenniumScope()
 {
     if (isset($_REQUEST['useUnscopedHoldingsSummary'])) {
         return $this->getDefaultScope();
     }
     $searchLibrary = Library::getSearchLibrary();
     $searchLocation = Location::getSearchLocation();
     $branchScope = '';
     //Load the holding label for the branch where the user is physically.
     if (!is_null($searchLocation)) {
         if ($searchLocation->useScope && $searchLocation->restrictSearchByLocation) {
             $branchScope = $searchLocation->scope;
         }
     }
     if (strlen($branchScope)) {
         return $branchScope;
     } else {
         if (isset($searchLibrary) && $searchLibrary->useScope && $searchLibrary->restrictSearchByLibrary) {
             return $searchLibrary->scope;
         } else {
             return $this->getDefaultScope();
         }
     }
 }
Example #7
0
 /**
  * Execute a search.
  *
  * @param	 string	$query			The XQuery script in binary encoding.
  * @param	 string	$handler		The Query Handler to use (null for default)
  * @param	 array	$filter		 The fields and values to filter results on
  * @param	 int	  $start			The record to start with
  * @param	 int	  $limit			The amount of records to return
  * @param	 array	$facet			An array of faceting options
  * @param	 string	$spell			Phrase to spell check
  * @param	 string	$dictionary Spell check dictionary to use
  * @param	 string	$sort			 Field name to use for sorting
  * @param	 string	$fields		 A list of fields to be returned
  * @param	 string	$method		 Method to use for sending request (GET/POST)
  * @param	 bool		$returnSolrError		If Solr reports a syntax error,
  *																			should we fail outright (false) or
  *																			treat it as an empty result set with
  *																			an error key set (true)?
  * @access	public
  * @throws	object							PEAR Error
  * @return	array							 An array of query results
  */
 function search($query, $handler = null, $filter = null, $start = 0, $limit = 20, $facet = null, $spell = '', $dictionary = null, $sort = null, $fields = null, $method = HTTP_REQUEST_METHOD_POST, $returnSolrError = false)
 {
     global $timer;
     // Query String Parameters
     $options = array('q' => $query, 'rows' => $limit, 'start' => $start, 'indent' => 'yes');
     //For FRBR, enable this and then update display
     //$options['group'] = 'true';
     //$options['group.field'] = 'grouping_term';
     // Add Sorting
     if ($sort && !empty($sort)) {
         // There may be multiple sort options (ranked, with tie-breakers);
         // process each individually, then assemble them back together again:
         $sortParts = explode(',', $sort);
         for ($x = 0; $x < count($sortParts); $x++) {
             $sortParts[$x] = $this->_normalizeSort($sortParts[$x]);
         }
         $options['sort'] = implode(',', $sortParts);
     }
     //Check to see if we need to automatically convert to a proper case only (no stemming search)
     //We will do this whenever all or part of a string is surrounded by quotes.
     if (preg_match('/\\".+?\\"/', $query)) {
         if ($handler == 'Keyword') {
             $handler = 'KeywordProper';
         } else {
             if ($handler == 'Subject') {
                 $handler = 'SubjectProper';
             } else {
                 if ($handler == 'AllFields') {
                     $handler = 'AllFieldsProper';
                 } else {
                     if ($handler == 'Title') {
                         $handler = 'TitleProper';
                     }
                 }
             }
         }
     }
     // Determine which handler to use
     if (!$this->isAdvanced($query)) {
         //Escape : to make sure that the query isn't treated as a field spec.
         $query = str_replace(':', '\\:', $query);
         $ss = is_null($handler) ? null : $this->_getSearchSpecs($handler);
         // Is this a Dismax search?
         if (isset($ss['DismaxFields'])) {
             // Specify the fields to do a Dismax search on:
             $options['qf'] = implode(' ', $ss['DismaxFields']);
             // Specify the default dismax search handler so we can use any
             // global settings defined by the user:
             $options['qt'] = 'dismax';
             // Load any custom Dismax parameters from the YAML search spec file:
             if (isset($ss['DismaxParams']) && is_array($ss['DismaxParams'])) {
                 foreach ($ss['DismaxParams'] as $current) {
                     $options[$current[0]] = $current[1];
                 }
             }
             // Apply search-specific filters if necessary:
             if (isset($ss['FilterQuery'])) {
                 if (is_array($filter)) {
                     $filter[] = $ss['FilterQuery'];
                 } else {
                     $filter = array($ss['FilterQuery']);
                 }
             }
         } else {
             // Not DisMax... but do we need to format the query based on
             // a setting in the YAML search specs?	If $ss is an array
             // at this point, it indicates that we found YAML details.
             if (is_array($ss)) {
                 $options['q'] = $this->_buildQueryComponent($handler, $query);
             } else {
                 if (!empty($handler)) {
                     $options['q'] = "({$handler}:{$query})";
                 }
             }
         }
     } else {
         // Force boolean operators to uppercase if we are in a case-insensitive
         // mode:
         if (!$this->caseSensitiveBooleans) {
             $query = SolrUtils::capitalizeBooleans($query);
         }
         // Process advanced search -- if a handler was specified, let's see
         // if we can adapt the search to work with the appropriate fields.
         if (!empty($handler)) {
             $options['q'] = $this->_buildAdvancedQuery($handler, $query);
         }
     }
     $timer->logTime("build query");
     // Limit Fields
     if ($fields) {
         $options['fl'] = $fields;
     } else {
         // This should be an explicit list
         $options['fl'] = '*,score';
     }
     if (is_object($this->searchSource)) {
         $defaultFilters = preg_split('/\\r\\n/', $this->searchSource->defaultFilter);
         foreach ($defaultFilters as $tmpFilter) {
             $filter[] = $tmpFilter;
         }
     }
     //Apply automatic boosting (only to biblio and econtent queries)
     if (preg_match('/.*(biblio|econtent).*/i', $this->host)) {
         //unset($options['qt']); //Force the query to never use dismax handling
         $searchLibrary = Library::getSearchLibrary($this->searchSource);
         //Boost items owned at our location
         $searchLocation = Location::getSearchLocation($this->searchSource);
         $boostFactors = $this->getBoostFactors($searchLibrary, $searchLocation);
         if (isset($options['qt']) && $options['qt'] == 'dismax') {
             //Boost by number of holdings
             if (count($boostFactors) > 0) {
                 $options['bf'] = "sum(" . implode(',', $boostFactors) . ")";
             }
             //print ($options['bq']);
         } else {
             $baseQuery = $options['q'];
             //Boost items in our system
             if (count($boostFactors) > 0) {
                 $boost = "sum(" . implode(',', $boostFactors) . ")";
             } else {
                 $boost = '';
             }
             $options['q'] = "{!boost b={$boost}} {$baseQuery}";
             //echo ("Advanced Query " . $options['q']);
         }
         $timer->logTime("apply boosting");
         $scopingFilters = $this->getScopingFilters($searchLibrary, $searchLocation);
         $timer->logTime("apply filters based on location");
     } else {
         //Non book search (genealogy)
         $scopingFilters = array();
     }
     if ($filter != null && $scopingFilters != null) {
         if (!is_array($filter)) {
             $filter = array($filter);
         }
         $filters = array_merge($filter, $scopingFilters);
     } else {
         if ($filter == null) {
             $filters = $scopingFilters;
         } else {
             $filters = $filter;
         }
     }
     // Build Facet Options
     if ($facet && !empty($facet['field'])) {
         $options['facet'] = 'true';
         $options['facet.mincount'] = 1;
         $options['facet.limit'] = isset($facet['limit']) ? $facet['limit'] : null;
         unset($facet['limit']);
         if (isset($facet['field']) && is_array($facet['field']) && in_array('date_added', $facet['field'])) {
             $options['facet.date'] = 'date_added';
             $options['facet.date.end'] = 'NOW';
             $options['facet.date.start'] = 'NOW-1YEAR';
             $options['facet.date.gap'] = '+1WEEK';
             foreach ($facet['field'] as $key => $value) {
                 if ($value == 'date_added') {
                     unset($facet['field'][$key]);
                     break;
                 }
             }
         }
         if (isset($facet['field'])) {
             $options['facet.field'] = $facet['field'];
             if ($options['facet.field'] && is_array($options['facet.field'])) {
                 foreach ($options['facet.field'] as $key => $facetName) {
                     if (strpos($facetName, 'availability_toggle') === 0) {
                         $options['facet.field'][$key] = '{!ex=avail}' . $facetName;
                     }
                 }
             }
         } else {
             $options['facet.field'] = null;
         }
         unset($facet['field']);
         $options['facet.prefix'] = isset($facet['prefix']) ? $facet['prefix'] : null;
         unset($facet['prefix']);
         $options['facet.sort'] = isset($facet['sort']) ? $facet['sort'] : null;
         unset($facet['sort']);
         if (isset($facet['offset'])) {
             $options['facet.offset'] = $facet['offset'];
             unset($facet['offset']);
         }
         if ($searchLibrary && $searchLibrary->showAvailableAtAnyLocation) {
             $options['f.available_at.facet.missing'] = 'true';
         }
         foreach ($facet as $param => $value) {
             $options[$param] = $value;
         }
     }
     $timer->logTime("build facet options");
     //Check to see if there are filters we want to show all values for
     if (isset($filters) && is_array($filters)) {
         foreach ($filters as $key => $value) {
             if (strpos($value, 'availability_toggle') === 0) {
                 $filters[$key] = '{!tag=avail}' . $value;
             }
         }
     }
     // Build Filter Query
     if (is_array($filters) && count($filters)) {
         $options['fq'] = $filters;
     }
     // Enable Spell Checking
     if ($spell != '') {
         $options['spellcheck'] = 'true';
         $options['spellcheck.q'] = $spell;
         if ($dictionary != null) {
             $options['spellcheck.dictionary'] = $dictionary;
         }
     }
     // Enable highlighting
     if ($this->_highlight) {
         $options['hl'] = 'true';
         $options['hl.fl'] = '*';
         $options['hl.simple.pre'] = '{{{{START_HILITE}}}}';
         $options['hl.simple.post'] = '{{{{END_HILITE}}}}';
     }
     if ($this->debug) {
         echo '<pre>Search options: ' . print_r($options, true) . "\n";
         if ($filters) {
             echo "\nFilterQuery: ";
             foreach ($filters as $filterItem) {
                 echo " {$filterItem}";
             }
         }
         if ($sort) {
             echo "\nSort: " . $options['sort'];
         }
         echo "</pre>\n";
         $options['debugQuery'] = 'on';
     }
     $timer->logTime("end solr setup");
     $result = $this->_select($method, $options, $returnSolrError);
     $timer->logTime("run select");
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result);
     }
     return $result;
 }
Example #8
0
 public function getItemsFast()
 {
     global $timer;
     if ($this->fastItems == null || isset($_REQUEST['reload'])) {
         $searchLibrary = Library::getSearchLibrary();
         $extraLocations = '';
         if ($searchLibrary) {
             $libraryLocationCode = $searchLibrary->ilsCode;
         }
         $searchLocation = Location::getSearchLocation();
         if ($searchLocation) {
             $homeLocationCode = $searchLocation->code;
             $extraLocations = $searchLocation->extraLocationCodesToInclude;
         }
         if ($this->itemsFromIndex) {
             $this->fastItems = array();
             foreach ($this->itemsFromIndex as $itemData) {
                 $isOrderItem = false;
                 $onOrderCopies = 0;
                 $status = null;
                 $groupedStatus = null;
                 $inLibraryUseOnly = false;
                 $isHoldable = true;
                 $isLocalItem = false;
                 $isLibraryItem = false;
                 if (array_key_exists('item', $itemData)) {
                     //New style with item, record, and scope information separated
                     $shelfLocation = $itemData['item'][7];
                     $locationCode = $itemData['item'][1];
                     $callNumber = $itemData['item'][2];
                     if (substr($itemData['item'][0], 0, 2) == '.o') {
                         $isOrderItem = true;
                         $onOrderCopies = $itemData['item'][7];
                         $available = false;
                         $shelfLocation = mapValue('shelf_location', $itemData['item'][1]);
                     } else {
                         $status = mapValue('item_status', $itemData['item'][6]);
                         $groupedStatus = mapValue('item_grouped_status', $itemData['item'][6]);
                         $available = $itemData['item'][3] == 'true';
                         $inLibraryUseOnly = $itemData['item'][4] == 'true';
                     }
                     //Don't use scoping section yet because it isn't ready for prime time.
                     /*if (array_key_exists('scope', $itemData) && count($itemData['scope']) > 0){
                     			$isHoldable = $itemData['scope'][0] == 'true';
                     			$isLocalItem = $itemData['scope'][1] == 'true';
                     			$isLibraryItem = $itemData['scope'][2] == 'true';
                     		}*/
                     if (!isset($libraryLocationCode) || $libraryLocationCode == '') {
                         $isLibraryItem = true;
                     } else {
                         $isLibraryItem = strpos($locationCode, $libraryLocationCode) === 0;
                     }
                     $isLocalItem = isset($homeLocationCode) && strlen($homeLocationCode) > 0 && strpos($locationCode, $homeLocationCode) === 0 || $extraLocations != '' && preg_match("/^{$extraLocations}\$/i", $locationCode);
                 } else {
                     //Old style where record and item information are combined
                     $shelfLocation = $itemData[2];
                     $locationCode = $itemData[2];
                     if (strpos($shelfLocation, ':') === false) {
                         $shelfLocation = mapValue('shelf_location', $itemData[2]);
                     } else {
                         $shelfLocationParts = explode(":", $shelfLocation);
                         $locationCode = $shelfLocationParts[0];
                         $branch = mapValue('shelf_location', $locationCode);
                         $shelfLocationTmp = mapValue('collection', $shelfLocationParts[1]);
                         $shelfLocation = $branch . ' ' . $shelfLocationTmp;
                     }
                     $callNumber = $itemData[3];
                     if (substr($itemData[1], 0, 2) == '.o') {
                         $isOrderItem = true;
                         $onOrderCopies = $itemData[8];
                         $available = false;
                     } else {
                         $status = mapValue('item_status', $itemData[7]);
                         $groupedStatus = mapValue('item_grouped_status', $itemData[7]);
                         $available = $itemData[4] == 'true';
                         $inLibraryUseOnly = $itemData[5] == 'true';
                     }
                     if (!isset($libraryLocationCode) || $libraryLocationCode == '') {
                         $isLibraryItem = true;
                     } else {
                         $isLibraryItem = strpos($locationCode, $libraryLocationCode) === 0;
                     }
                     $isLocalItem = isset($homeLocationCode) && strlen($homeLocationCode) > 0 && strpos($locationCode, $homeLocationCode) === 0 || $extraLocations != '' && preg_match("/^{$extraLocations}\$/i", $locationCode);
                 }
                 //Try to trim the courier code if any
                 if (preg_match('/(.*?)\\sC\\d{3}\\w{0,2}$/', $shelfLocation, $locationParts)) {
                     $shelfLocation = $locationParts[1];
                 }
                 //Determine the structure of the item data based on if it's an order record or not.
                 //TODO: This needs a better way of handling things because .o will only work for Sierra/Millennium systems
                 if ($isOrderItem) {
                     $groupedStatus = "On Order";
                     $callNumber = "ON ORDER";
                     $status = "On Order";
                 } else {
                     //This is a regular (physical) item
                     if ($status != null) {
                         if ($status == 'On Shelf' && $available != true) {
                             $status = 'Checked Out';
                             $groupedStatus = "Checked Out";
                         }
                     } else {
                         if ($available) {
                             $status = "On Shelf";
                             $groupedStatus = "On Shelf";
                         } else {
                             $status = "Checked Out";
                             $groupedStatus = "Checked Out";
                         }
                     }
                 }
                 $this->fastItems[] = array('location' => $locationCode, 'callnumber' => $callNumber, 'availability' => $available, 'holdable' => $isHoldable, 'inLibraryUseOnly' => $inLibraryUseOnly, 'isLibraryItem' => $isLibraryItem, 'isLocalItem' => $isLocalItem, 'locationLabel' => true, 'shelfLocation' => $shelfLocation, 'onOrderCopies' => $onOrderCopies, 'status' => $status, 'groupedStatus' => $groupedStatus);
             }
             $timer->logTime("Finished getItemsFast for marc record based on data in index");
         } else {
             $driver = MarcRecord::getCatalogDriver();
             $this->fastItems = $driver->getItemsFast($this->getUniqueID(), $this->scopingEnabled, $this->getMarcRecord());
             $timer->logTime("Finished getItemsFast for marc record based on data in driver");
         }
     }
     return $this->fastItems;
 }
Example #9
0
 public function process()
 {
     global $interface;
     // Grab the facet set -- note that we need to take advantage of the third
     // parameter to getFacetList in order to pass down row and column
     // information for inclusion in the final list.
     $facetList = $this->searchObject->getFacetList($this->facets, false);
     foreach ($facetList as $facetSetkey => $facetSet) {
         if ($facetSet['label'] == 'Category' || $facetSet['label'] == 'Format Category') {
             $validCategories = array('Books', 'eBook', 'Audio Books', 'eAudio', 'Music', 'Movies');
             //add an image name for display in the template
             foreach ($facetSet['list'] as $facetKey => $facet) {
                 if (in_array($facetKey, $validCategories)) {
                     $facet['imageName'] = strtolower(str_replace(' ', '', $facet['value'])) . ".png";
                     $facet['imageNameSelected'] = strtolower(str_replace(' ', '', $facet['value'])) . "_selected.png";
                     $facetSet['list'][$facetKey] = $facet;
                 } else {
                     unset($facetSet['list'][$facetKey]);
                 }
             }
             uksort($facetSet['list'], "format_category_comparator");
             $facetList[$facetSetkey] = $facetSet;
         } elseif (preg_match('/available/i', $facetSet['label'])) {
             $numSelected = 0;
             foreach ($facetSet['list'] as $facetKey => $facet) {
                 if ($facet['isApplied']) {
                     $numSelected++;
                 }
             }
             //If nothing is selected, select entire collection by default
             $sortedFacetList = array();
             $numTitlesWithNoValue = 0;
             $numTitlesWithEntireCollection = 0;
             $searchLibrary = Library::getSearchLibrary(null);
             $searchLocation = Location::getSearchLocation(null);
             if ($searchLocation) {
                 $superScopeLabel = $searchLocation->availabilityToggleLabelSuperScope;
                 $localLabel = $searchLocation->availabilityToggleLabelLocal;
                 $localLabel = str_ireplace('{display name}', $searchLocation->displayName, $localLabel);
                 $availableLabel = $searchLocation->availabilityToggleLabelAvailable;
                 $availableLabel = str_ireplace('{display name}', $searchLocation->displayName, $availableLabel);
             } else {
                 $superScopeLabel = $searchLibrary->availabilityToggleLabelSuperScope;
                 $localLabel = $searchLibrary->availabilityToggleLabelLocal;
                 $localLabel = str_ireplace('{display name}', $searchLibrary->displayName, $localLabel);
                 $availableLabel = $searchLibrary->availabilityToggleLabelAvailable;
                 $availableLabel = str_ireplace('{display name}', $searchLibrary->displayName, $availableLabel);
             }
             foreach ($facetSet['list'] as $facet) {
                 if ($facet['value'] == 'Entire Collection') {
                     $includeButton = true;
                     $facet['value'] = $localLabel;
                     if (trim($localLabel) == '') {
                         $includeButton = false;
                     } else {
                         if ($searchLocation) {
                             $includeButton = !$searchLocation->restrictSearchByLocation;
                         } elseif ($searchLibrary) {
                             $includeButton = !$searchLibrary->restrictSearchByLibrary;
                         }
                     }
                     $numTitlesWithEntireCollection = $facet['count'];
                     if ($includeButton) {
                         $sortedFacetList[1] = $facet;
                     }
                 } elseif ($facet['value'] == '') {
                     $facet['isApplied'] = $facet['isApplied'] || $numSelected == 0;
                     $facet['value'] = $superScopeLabel;
                     $sortedFacetList[0] = $facet;
                     $numTitlesWithNoValue = $facet['count'];
                     break;
                 } else {
                     $facet['value'] = $availableLabel;
                     $sortedFacetList[2] = $facet;
                 }
             }
             if (isset($sortedFacetList[0])) {
                 $sortedFacetList[0]['count'] = $numTitlesWithEntireCollection + $numTitlesWithNoValue;
             }
             ksort($sortedFacetList);
             $facetSet['list'] = $sortedFacetList;
             $facetList[$facetSetkey] = $facetSet;
         }
     }
     $interface->assign('topFacetSet', $facetList);
     $interface->assign('topFacetSettings', $this->baseSettings);
 }
 function isValidForUser($locationCode, $eContentFieldData)
 {
     $sharing = $this->getSharing($locationCode, $eContentFieldData);
     if ($sharing == 'shared') {
         return true;
     } else {
         if ($sharing == 'library') {
             $searchLibrary = Library::getSearchLibrary();
             if ($searchLibrary == null || strlen($searchLibrary->ilsCode) > 0 && strpos($locationCode, $searchLibrary->ilsCode) === 0) {
                 global $user;
                 if ($user) {
                     $patronHomeLibrary = Library::getPatronHomeLibrary();
                     return $patronHomeLibrary == null || strlen($patronHomeLibrary->ilsCode) > 0 && strpos($locationCode, $patronHomeLibrary->ilsCode) === 0;
                 } else {
                     return true;
                 }
             } else {
                 return false;
             }
         } else {
             //Just share with the specific location
             $searchLocation = Location::getSearchLocation();
             if (!$searchLocation) {
                 return true;
             } elseif (strpos($locationCode, $searchLocation->code) === 0) {
                 return true;
             } else {
                 return false;
             }
         }
     }
 }