/**
  * Cache search results
  * 
  * @param ResultSet $results
  * @param string|Query $query
  */
 public function setCachedResults(ResultSet $results, $query)
 {
     // if cache is turned off, then don't bother caching
     if ($this->should_cache_results == false) {
         return null;
     }
     $id = $this->getResultsID($query);
     try {
         $this->cache->set($id, $results);
     } catch (\Exception $e) {
         trigger_error("Could not cache results");
     }
 }
Exemple #2
0
 /**
  * Fetch list of databases
  * 
  * @param bool $force_new  get data from ebsco 
  * @return array
  */
 public function getDatabases($force_new = false)
 {
     $cache = new Cache();
     $id = 'ebsco_databases';
     if ($force_new == false) {
         // do we have it already?
         if (count($this->databases) > 0) {
             return $this->databases;
         }
         // check the cache
         $this->databases = $cache->get($id);
         if ($this->databases != null) {
             return $this->databases;
         }
     }
     // fetch 'em from ebsco
     $url = $this->host . '/Info?' . 'prof=' . $this->username . '&pwd=' . $this->password;
     $client = Factory::getHttpClient();
     $response = $client->getUrl($url);
     $xml = new \DOMDocument();
     $loaded = $xml->loadXML($response);
     if ($loaded == true) {
         $nodes = $xml->getElementsByTagName('db');
         if ($nodes->length > 1) {
             foreach ($nodes as $db) {
                 if ((string) $db->getAttribute('dbType') == 'Regular') {
                     $id = (string) $db->getAttribute('shortName');
                     $name = (string) $db->getAttribute('longName');
                     $this->databases[$id] = $name;
                 }
             }
             // cache 'em
             $cache->set($id, $this->databases);
         }
     }
     return $this->databases;
 }
Exemple #3
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
     $cache_id = $xerxes_record->getSource() . "." . $id;
     // to identify this in the cache
     $url = $this->config->getConfig("LOOKUP");
     // url to availability server
     // 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 || $url == "" || $id == "") {
         return null;
     }
     // get the data
     $url .= "?action=status&id=" . urlencode($id);
     // @todo this needs to be gotten from a factory or something
     $client = new Client();
     $client->setUri($url);
     $client->setConfig(array('timeout' => 5));
     $data = $client->send()->getBody();
     // echo $url; exit;
     // no data, what's up with that?
     if ($data == "") {
         throw new \Exception("could not connect to availability server");
     }
     // response is (currently) an array of json objects
     $results = json_decode($data);
     // parse the response
     if (is_array($results)) {
         if (count($results) > 0) {
             // now just slot them into our item object
             foreach ($results as $holding) {
                 $is_holding = property_exists($holding, "holding");
                 if ($is_holding == true) {
                     $item = new Holding();
                     $this->holdings->addHolding($item);
                 } else {
                     $item = new Item();
                     $this->holdings->addItem($item);
                 }
                 foreach ($holding as $property => $value) {
                     $item->setProperty($property, $value);
                 }
             }
         }
     }
     // cache it for the future
     // @todo: zend\cache
     $cache = new Cache();
     $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 2 * 60 * 60);
     // expiry set for two hours
     $expiry += time();
     $cache->set($cache_id, serialize($this->holdings), $expiry);
     return null;
 }
Exemple #4
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();
     // @todo: zend\cache
     $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 2 * 60 * 60);
     // expiry set for two hours
     $expiry += time();
     $cache->set($this->getCacheId(), serialize($this->holdings), $expiry);
     return $this;
 }