Example #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->cache = new Cache();
     // application config
     $this->registry = Registry::getInstance();
     // local config
     $this->config = $this->getConfig();
     // cache results based on local config or registry, default true
     $this->should_cache_results = $this->config->getConfig('CACHE_RESULTS', false, $this->registry->getConfig('CACHE_RESULTS', false, true));
 }
Example #2
0
 /**
  * Look for any holdings data in the cache and add it to results
  */
 public function injectHoldings()
 {
     // get the record ids for all search results
     $ids = $this->extractRecordIDs();
     // only if there are actually records here
     if (count($ids) > 0) {
         // prefix the engine id
         for ($x = 0; $x < count($ids); $x++) {
             $ids[$x] = $this->config->getID() . "." . $ids[$x];
         }
         // look for any of our items
         $cache = new Cache();
         $cache_array = $cache->get($ids);
         foreach ($cache_array as $id => $holdings) {
             if (!$holdings instanceof Holdings) {
                 continue;
                 // skip it
             }
             // now associate this item with its corresponding result
             for ($x = 0; $x < count($this->records); $x++) {
                 $search_result = $this->records[$x];
                 if ($this->config->getID() . "." . $search_result->xerxes_record->getRecordID() == $id) {
                     $search_result->setHoldings($holdings);
                 }
                 $this->records[$x] = $search_result;
             }
         }
     }
 }
Example #3
0
 /**
  * Add labels to ResultSet
  * 
  * Primarily for formats, facets, and other 'data'-based labels
  *
  * @param ResultSet $results 
  */
 public function addResultsLabels(ResultSet &$results)
 {
     // format in record
     foreach ($results->getRecords() as $result) {
         $format = $result->getXerxesRecord()->format();
         $label_id = $format->getLabel();
         $label = $this->labels->getLabel($label_id);
         if ($label != $label_id) {
             $format->setPublicFormat($label);
         }
     }
     // facets
     foreach ($results->getFacets()->getGroups() as $group) {
         $label_group_name = $this->config->getFacetAttribute($group->name, 'label');
         if ($label_group_name == "") {
             $label_group_name = $this->config->getFacetAttribute($group->name, 'public');
         }
         $group->public = $this->labels->getLabel($label_group_name);
         // format values in facets
         foreach ($group->getFacets() as $facet) {
             $facet->display = $facet->name;
             $label_id = Format::createLabelIdentifier($facet->name);
             $label = $this->labels->getLabel($label_id);
             if ($label != $label_id) {
                 $facet->display = $label;
             }
         }
     }
 }
 /**
  * Individual record
  */
 public function recordAction()
 {
     $id = $this->request->getParam('id');
     // get the record
     $results = $this->engine->getRecord($id);
     if ($this->request->getParam('original') != null || $this->config->getConfig('INCLUDE_ORIGINAL_RECORD', false)) {
         $results->getRecord(0)->includeOriginalRecord();
     }
     // set lables and links
     $this->helper->addResultsLabels($results);
     $this->helper->addRecordLinks($results);
     // add to response
     $this->response->setVariable('results', $results);
     // view template
     $this->response->setView($this->id . '/record.xsl');
     return $this->response;
 }
Example #5
0
 /**
  * Fetch item and holding records from an ILS for this record
  */
 public function fetchHoldings()
 {
     $xerxes_record = $this->getXerxesRecord();
     $id = $xerxes_record->getRecordID();
     // id from the record
     $type = $this->config->getConfig("LOOKUP");
     // availability look-up type
     // mark that we've checked holdings either way
     $this->holdings->checked = true;
     // no holdings source defined or somehow id's are blank
     if ($xerxes_record->hasPhysicalHoldings() == false || $type == "" || $id == "") {
         return $this;
     }
     // get the data
     $availabilty_factory = new AvailabilityFactory();
     $availability = $availabilty_factory->getAvailabilityObject($type);
     $this->holdings = $availability->getHoldings($id);
     $this->holdings->checked = true;
     // items not to cache
     $no_cache = $this->config->getConfig('LOCATIONS_NO_CACHE', false);
     if ($no_cache != '' && $no_cache instanceof \SimpleXMLElement) {
         $locations = array();
         foreach ($no_cache->location as $location) {
             $locations[] = (string) $location;
         }
         foreach ($this->holdings->getItems() as $item) {
             if (in_array($item->location, $locations)) {
                 return $this;
             }
         }
     }
     // cache it for the future
     $cache = new Cache();
     $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 30 * 60);
     // expiry set for 30 mins
     $expiry += time();
     $cache->set($this->getCacheId(), $this->holdings, $expiry);
     return $this;
 }
Example #6
0
 /**
  * Change the case or add truncation to a search based on config
  * 
  * @param string $phrase		the search phrase
  * @param string $field			field to search on
  * 
  * @return string 				altereted phrase, or original as supplied if field has no definitions
  */
 public function alterQuery($phrase, $field)
 {
     $phrase = trim($phrase);
     $case = $this->config->getFieldAttribute($field, "case");
     $trunc = $this->config->getFieldAttribute($field, "truncate");
     switch ($case) {
         case "upper":
             $phrase = strtoupper($phrase);
             break;
         case "lower":
             $phrase = strtolower($phrase);
             break;
     }
     switch ($trunc) {
         case "left":
             $phrase = "*" . $phrase;
             break;
         case "right":
             $phrase = $phrase . "*";
             break;
         case "both":
             $phrase = "*" . $phrase . "*";
             break;
     }
     return $phrase;
 }