/** * Extracts data from the summary holdings holdings table * * @param string $html html response from catalog * @return Holding[] */ protected function extractHoldingsRecords($html) { $final_array = array(); // check to see if there are summary (journal) holdings as well as item records // if not, just return out if (strpos($html, "class=\"bibHoldings\">") === false) { return $final_array; } $html = Parser::removeLeft($html, "class=\"bibHoldings"); $html = Parser::removeRight($html, "</table>"); $holdings_blocks = explode("holdingsDivider", $html); // first and last element are unused array_pop($holdings_blocks); array_shift($holdings_blocks); foreach ($holdings_blocks as $block) { $holding = new Search\Holding(); while (strstr($block, "<tr")) { // get just this row $block = Parser::removeLeft($block, "<tr"); $item_data = "<tr" . Parser::removeRight($block, "</tr>"); $block = Parser::removeLeft($block, "</tr>"); // knock out line breaks and spaces $item_data = str_replace("\n", " ", $item_data); $item_data = str_replace(" ", " ", $item_data); // put a colon and period between the label and display $item_data = str_replace("class=\"bibHoldingsEntry\">", ">|| ", $item_data); $item_data = strip_tags($item_data); $item_data = trim($item_data); // last one is blank if ($item_data == "") { continue; } $pair = explode("||", $item_data); $id = $pair[0]; $value = $pair[1]; $id = str_replace(":", "", $id); $id = trim($id); // empty descriptor if ($id == "" && strstr($value, ":")) { $parts = explode(":", $value); $id = array_shift($parts); $value = implode(":", $parts); } $holding->setProperty($id, $value); } array_push($final_array, $holding); } return $final_array; }
/** * Fetch record information * * @param string $id bibliographic id */ public function getHoldings($id) { $holdings = new Search\Holdings(); // fetch holdings page from web service $url = $this->server . "GetHoldingsService?bibId={$id}"; $content = $this->client->getUrl($url, 4); // load and parse it $xml = Parser::convertToDOMDocument($content); // header("Content-type: text/xml"); echo $xml->saveXML(); exit; $records = $xml->getElementsByTagName("mfhdRecord"); foreach ($records as $record) { $item = new Search\Item(); $item->id = $record->getAttribute("mfhdId"); $item_count = (int) $record->getElementsByTagName("itemCount")->item(0)->nodeValue; // @todo what is this? foreach ($record->getElementsByTagName("datafield") as $datafield) { if ($datafield->getAttribute("tag") == "866") { $datafield->textContent; } } if ($item_count == 0) { continue; } $unavailable = 0; foreach ($record->getElementsByTagName("itemData") as $itemData) { if ($itemData->getAttribute("name") == "statusCode") { if ($itemData->nodeValue != 1) { $unavailable++; } } } // holding record if ($item_count > 1 && $unavailable > 0) { $holding = new Search\Holding(); // item count summary $available = $item_count - $unavailable; $number_of_items = "{$item_count} items ({$available} available)"; $holding->setProperty('Number of items', $number_of_items); $holdings->addHolding($holding); continue; } // locations $locations = array(); foreach ($record->getElementsByTagName("itemLocation") as $location_node) { $location = ""; $caption = ""; $temp = false; foreach ($location_node->getElementsByTagName("itemLocationData") as $location_data) { if ($location_data->getAttribute("name") == "tempLocation") { if (!in_array($location_data->nodeValue, $this->ignore_locations)) { $location = $location_data->nodeValue; } } elseif ($location_data->getAttribute("name") == "itemCaption") { $caption = $location_data->nodeValue; } elseif ($location_data->getAttribute("name") == "tmpLoc") { $temp = true; } } if ($location != "") { // if this is the temp location, then previous one is the 'old' location if ($temp == true) { array_pop($locations); } $locations[$location] = $caption; } } // no locations, so skip it yo! if (count($locations) == 0) { continue; } // call number foreach ($record->getElementsByTagName("mfhdData") as $data) { if ($data->getAttribute("name") == "callNumber") { $item->callnumber = $data->nodeValue; } } // status foreach ($record->getElementsByTagName("itemData") as $data) { if ($data->getAttribute("name") == "statusCode") { $status = $data->nodeValue; $public_status = $this->config->getPublicStatus($status); if ($public_status != null) { $item->status = $public_status; if ($item_count > count($locations)) { $item->status .= " ({$item_count} items)"; } } if ($status == 1) { $item->availability = true; } else { $item->availability = false; } } elseif ($data->getAttribute("name") == "statusDate") { $date = $data->nodeValue; $matches = array(); if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})/', $date, $matches)) { $item->duedate = $matches[2] . "-" . $matches[3] . "-" . $matches[1]; $item->status = str_replace('\\d', $item->duedate, $item->status); } } } foreach ($locations as $item_location => $caption) { if ($caption != "") { $item->location = "{$caption} shelved at {$item_location}"; } else { $item->location = $item_location; } $holdings->addItem($item); } } return $holdings; }