public function addItems(Xerxes_Record_Items $items) { if ($items->length() == 0) { $this->setNoItems(true); } foreach ($items->getItems() as $item) { $this->addItem($item); } }
protected function getHoldings($arrIDs) { $items = new Xerxes_Record_Items(); $cache_id = ""; // id used in cache $bib_id = ""; // bibliographic id number $oclc = ""; // oclc number // figure out what is what foreach ($arrIDs as $id) { if (stristr($id, "ISBN:")) { continue; } if (stristr($id, "OCLC:")) { $oclc = $id; } else { $bib_id = $id; } } // no bib id supplied, so use oclc number as id if ($bib_id == "") { if ($oclc == "") { throw new Exception("no bibliographic id or oclc number suppled in availability lookup"); } $cache_id = str_replace("OCLC:", "", $oclc); } else { $cache_id = $bib_id; } // get url to availability server $strSource = $this->getSource(); $url = $this->getHoldingsURL($strSource); // no holdings source defined or somehow id's are blank if ($url == null || count($arrIDs) == 0) { return $items; // empty items } // get the data $url .= "?action=status&id=" . urlencode(implode(" ", $arrIDs)); $data = Xerxes_Framework_Parser::request($url); // echo $url; exit; // no data, what's up with that? if ($data == "") { throw new Exception("could not connect to availability server"); } // echo $data; exit; // response is (currently) an array of json objects $arrResults = json_decode($data); // parse the response if (is_array($arrResults)) { if (count($arrResults) > 0) { // now just slot them into our item object foreach ($arrResults as $holding) { $is_holdings = property_exists($holding, "holding"); if ($is_holdings == true) { $item = new Xerxes_Record_Holding(); } else { $item = new Xerxes_Record_Item(); } foreach ($holding as $property => $value) { $item->setProperty($property, $value); } $items->addItem($item); } } } // cache it for the future // expiry set for two hours $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 2 * 60 * 60); $expiry += time(); $cache = new Xerxes_Data_Cache(); $cache->source = $this->getSource(); $cache->id = $cache_id; $cache->expiry = $expiry; $cache->data = serialize($items); $this->data_map->setCache($cache); return $items; }
public function addItems(Xerxes_Record_Items $items) { if ($items->length() == 0) { $this->setNoItems(true); } else { // add item foreach ($items->getItems() as $item) { $this->addItem($item); } // include it in the XML as well if ($this->document instanceof DOMDocument) { $record = $this->document->getElementsByTagName("record")->item(0); if ($record != null) { foreach ($items->getItems() as $item) { $import = $this->document->importNode($item->toXML()->documentElement, true); $record->appendChild($import); } } } } }