/** * Send a text message of this record to carrier using email gateway * * @param string $phone * @param string $provider * @param int $item_number * @throws \Exception */ public function textLocationTo($phone, $provider, $item_number) { $phone = preg_replace('/\\D/', "", $phone); // did we get 10? if (strlen($phone) != 10) { throw new \Exception("Please enter a 10 digit phone number, including area code"); } $email = $phone . '@' . $provider; if ($this->holdings->length() == 0) { $this->fetchHoldings(); // nothing here to text! if ($this->holdings->length() == 0) { return $this; } } // title $title = $this->getXerxesRecord()->getTitle(); // item info $item = $this->holdings->getItems($item_number); $item_message = $item->location . " " . $item->callnumber; // make sure we don't go over sms size limit $title_length = strlen($title); $item_length = strlen($item_message); $total_length = $title_length + $item_length; if ($total_length > 150) { $title = substr($title, 0, $total_length - $item_length - 6) . "..."; } $body = $title . " / " . $item_message; $email_client = new Email(); return $email_client->send($email, 'library', $body); // @todo l18n this }
/** * Fetch record information * * @param string $bib_id bibliographic id */ public function getHoldings($bib_id) { // echo strlen($bib_id); $holdings = new Search\Holdings(); // fetch info from server $id = substr($bib_id, 1); $query = "/record={$id}"; $this->url = $this->server . $query; $response = $this->client->getUrl($this->url); // parse record $holdings->id = $this->extractID($response); $holdings->hold_url = $this->extractHoldLink($response); // marc record // $query = "/search/.$bib_id/.$bib_id/1,1,1,B/detlmarc~$id&FF=&1,0,"; // $record->setBibliographicRecord( $this->extractMarc($response) ); // items foreach ($this->extractItemRecords($response) as $item) { // this isn't the location you are looking for if (in_array($item->location, $this->locations_to_ignore)) { continue; } // this status shows the item is available if (in_array($item->status, $this->availability_status)) { $item->availability = true; } $holdings->addItem($item); } // periodical holdings foreach ($this->extractHoldingsRecords($response) as $periodical_holdings) { $holdings->addHolding($periodical_holdings); } // erm records foreach ($this->extractERMRecords($response) as $electronic) { $holdings->addElectronicResource($electronic); } return $holdings; }
/** * 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; }