/** * Builds an alphabetical help string based on the default display date format. * * @return string */ public function getDisplayDateFormat() { $dueDateHelpString = $this->converter->convertToDisplayDate("m-d-y", "11-22-3333"); $search = ["1", "2", "3"]; $replace = [$this->view->translate("date_month_placeholder"), $this->view->translate("date_day_placeholder"), $this->view->translate("date_year_placeholder")]; return str_replace($search, $replace, $dueDateHelpString); }
/** * Format the given unix time stamp to a human readable format. The format is * configurable in Unicorn.ini * * @param int $time Unix time stamp. * * @return string Formatted date/time. */ protected function formatDateTime($time) { $dateTimeString = ''; if ($time) { $dateTimeString = strftime('%m/%d/%Y %H:%M', $time); $dateTimeString = $this->dateConverter->convertToDisplayDate('m/d/Y H:i', $dateTimeString); } return $dateTimeString; }
/** * Format a Solr date for display * * @param string $date Date * @param string $domain Translation domain * * @return string */ protected function formatNewItemsDateForDisplay($date, $domain) { if ($date == '' || $date == '*') { return ['', true]; } if (preg_match('/^NOW-(\\w+)/', $date, $matches)) { return [$this->translate("{$domain}::new_items_" . strtolower($matches[1])), false]; } $date = substr($date, 0, 10); return [$this->dateConverter->convertToDisplayDate('Y-m-d', $date), true]; }
/** * Get the year of publication for inclusion in a citation. * Shared by APA and MLA functionality. * * @return string */ protected function getYear() { if (isset($this->details['pubDate'])) { if (strlen($this->details['pubDate']) > 4) { try { return $this->dateConverter->convertFromDisplayDate('Y', $this->details['pubDate']); } catch (\Exception $e) { // Ignore date errors -- no point in dying here: return false; } } return preg_replace('/[^0-9]/', '', $this->details['pubDate']); } return false; }
/** * Protected support method for getMyHolds. * * @param array $sqlRow An array of keyed data * * @throws DateException * @return array Keyed data for display by template files */ protected function processMyHoldsData($sqlRow) { $available = $sqlRow['HOLD_RECALL_STATUS'] == 2 ? true : false; $expireDate = $this->translate("Unknown"); // Convert Voyager Format to display format if (!empty($sqlRow['EXPIRE_DATE'])) { $expireDate = $this->dateFormat->convertToDisplayDate("m-d-y", $sqlRow['EXPIRE_DATE']); } $createDate = $this->translate("Unknown"); // Convert Voyager Format to display format if (!empty($sqlRow['CREATE_DATE'])) { $createDate = $this->dateFormat->convertToDisplayDate("m-d-y", $sqlRow['CREATE_DATE']); } return array('id' => $sqlRow['BIB_ID'], 'type' => $sqlRow['HOLD_RECALL_TYPE'], 'location' => $sqlRow['PICKUP_LOCATION'], 'expire' => $expireDate, 'create' => $createDate, 'position' => $sqlRow['QUEUE_POSITION'], 'available' => $available, 'reqnum' => $sqlRow['HOLD_RECALL_ID'], 'item_id' => $sqlRow['ITEM_ID'], 'volume' => str_replace("v.", "", utf8_encode($sqlRow['ITEM_ENUM'])), 'publication_year' => $sqlRow['YEAR'], 'title' => empty($sqlRow['TITLE_BRIEF']) ? $sqlRow['TITLE'] : $sqlRow['TITLE_BRIEF']); }
/** * Get a Date Range from Index Fields * * @param string $event Event name * * @return null|array Array of two dates or null if not available */ protected function getDateRange($event) { if (!isset($this->fields["{$event}_sdaterange"])) { return null; } $range = explode(' ', $this->fields["{$event}_sdaterange"], 2); if (!$range) { return null; } $range[0] *= 86400; $range[1] *= 86400; $startDate = new \DateTime("@{$range[0]}"); $endDate = new \DateTime("@{$range[1]}"); if ($startDate->format('m') == 1 && $startDate->format('d') == 1 && $endDate->format('m') == 12 && $endDate->format('d') == 31) { return [$startDate->format('Y'), $endDate->format('Y')]; } return [$this->dateConverter->convertToDisplayDate('U', $range[0]), $this->dateConverter->convertToDisplayDate('U', $range[1])]; }
/** * Protected support method for getMyTransactions. * * @param array $row An array of keyed data * * @throws \VuFind\Exception\Date * @return array Keyed data for display by template files */ protected function processTransactionsRow($row) { $dueStatus = false; // Convert Horizon Format to display format if (!empty($row['DUEDATE'])) { $dueDate = $this->dateFormat->convertToDisplayDate("M d Y", trim($row['DUEDATE'])); $now = time(); $dueTimeStamp = $this->dateFormat->convertFromDisplayDate("U", $dueDate); if (is_numeric($dueTimeStamp)) { if ($now > $dueTimeStamp) { $dueStatus = "overdue"; } else { if ($now > $dueTimeStamp - 1 * 24 * 60 * 60) { $dueStatus = "due"; } } } } return ['id' => $row['BIB_NUM'], 'item_id' => $row['ITEM_NUM'], 'duedate' => $dueDate, 'barcode' => $row['ITEM_BARCODE'], 'renew' => $row['RENEW'], 'request' => $row['REQUEST'], 'dueStatus' => $dueStatus, 'volume' => $row['VOLUME'], 'publication_year' => $row['PUBLICATION_YEAR'], 'title' => $row['TITLE']]; }
/** * Protected support method for getMyStorageRetrievalRequests. * * @param array $sqlRow An array of keyed data * * @return array Keyed data for display by template files */ protected function processMyStorageRetrievalRequestsData($sqlRow) { $available = $sqlRow['STATUS'] == 4 ? true : false; $expireDate = ''; $processedDate = ''; $statusDate = ''; // Convert Voyager Format to display format if (!empty($sqlRow['PROCESSED_DATE'])) { $processedDate = $this->dateFormat->convertToDisplayDate("m-d-y", $sqlRow['PROCESSED_DATE']); } if (!empty($sqlRow['STATUS_DATE'])) { $statusDate = $this->dateFormat->convertToDisplayDate("m-d-y", $sqlRow['STATUS_DATE']); } $createDate = $this->translate("Unknown"); // Convert Voyager Format to display format if (!empty($sqlRow['CREATE_DATE'])) { $createDate = $this->dateFormat->convertToDisplayDate("m-d-y", $sqlRow['CREATE_DATE']); } return ['id' => $sqlRow['BIB_ID'], 'status' => utf8_encode($sqlRow['STATUS_DESC']), 'statusDate' => $statusDate, 'location' => $this->getLocationName($sqlRow['PICKUP_LOCATION_ID']), 'create' => $createDate, 'processed' => $processedDate, 'expire' => $expireDate, 'reply' => utf8_encode($sqlRow['REPLY_NOTE']), 'available' => $available, 'canceled' => $sqlRow['STATUS'] == 7 ? $statusDate : false, 'reqnum' => $sqlRow['CALL_SLIP_ID'], 'item_id' => $sqlRow['ITEM_ID'], 'volume' => str_replace("v.", "", utf8_encode($sqlRow['ITEM_ENUM'])), 'issue' => utf8_encode($sqlRow['ITEM_CHRON']), 'year' => utf8_encode($sqlRow['ITEM_YEAR']), 'title' => empty($sqlRow['TITLE_BRIEF']) ? $sqlRow['TITLE'] : $sqlRow['TITLE_BRIEF']]; }
public function placeILLRequest($user, $attrs) { $payment = $attrs['payment']; unset($attrs['payment']); $new = $attrs['new']; unset($attrs['new']); $additional_authors = $attrs['additional_authors']; unset($attrs['additional_authors']); $source = $attrs['source']; $publisher = $attrs['publisher']; unset($attrs['source']); if (!isset($attrs['ill-unit'])) { $attrs['ill-unit'] = $this->defaultIllUnit; } if (!isset($attrs['pickup-location'])) { $attrs['pickup-location'] = $this->defaultIllPickupPlocation; } try { $attrs['last-interest-date'] = $this->dateConverter->convertFromDisplayDate('Ymd', $attrs['last-interest-date']); } catch (DateException $de) { return array('success' => false, 'sysMessage' => 'hold_date_invalid'); } $attrs['allowed-media'] = $attrs['media']; $attrs['send-directly'] = 'N'; $attrs['delivery-method'] = 'S'; if ($new == 'serial') { $new = 'SE'; } else { if ($new == 'monography') { $new = 'MN'; } } $patronId = $user['id']; $illDom = new \DOMDocument('1.0', 'UTF-8'); $illRoot = $illDom->createElement('ill-parameters'); $illRootNode = $illDom->appendChild($illRoot); foreach ($attrs as $key => $value) { $element = $illDom->createElement($key); $element->appendChild($illDom->createTextNode($value)); $illRootNode->appendChild($element); } $xml = $illDom->saveXML(); try { $path = array('patron', $patronId, 'record', $new, 'ill'); $result = $this->alephWebService->doRestDLFRequest($path, null, 'PUT', 'post_xml=' . $xml); } catch (\Exception $ex) { return array('success' => false, 'sysMessage' => $ex->getMessage()); } $baseAndDocNumber = $result->{'create-ill'}->{'request-number'}; $base = substr($baseAndDocNumber, 0, 5); $docNum = substr($baseAndDocNumber, 5); $findDocParams = array('base' => $base, 'doc_num' => $docNum); $document = $this->alephWebService->doXRequest('find-doc', $findDocParams, true); // create varfield for ILL request type $varfield = $document->{'record'}->{'metadata'}->{'oai_marc'}->addChild('varfield'); $varfield->addAttribute('id', 'PNZ'); $varfield->addAttribute('i1', ' '); $varfield->addAttribute('i2', ' '); $subfield = $varfield->addChild('subfield', $payment); $subfield->addAttribute('label', 'a'); if (!empty($additional_authors)) { $varfield = $document->{'record'}->{'metadata'}->{'oai_marc'}->addChild('varfield'); $varfield->addAttribute('id', '700'); $varfield->addAttribute('i1', '1'); $varfield->addAttribute('i2', ' '); $subfield = $varfield->addChild('subfield', $additional_authors); $subfield->addAttribute('label', 'a'); } if (!empty($source)) { $varfield = $document->{'record'}->{'metadata'}->{'oai_marc'}->addChild('varfield'); $varfield->addAttribute('id', '590'); $varfield->addAttribute('i1', ' '); $varfield->addAttribute('i2', ' '); $subfield = $varfield->addChild('subfield', htmlspecialchars($source)); $subfield->addAttribute('label', 'a'); } if (!empty($publisher)) { $varfield = $document->{'record'}->{'metadata'}->{'oai_marc'}->addChild('varfield'); $varfield->addAttribute('id', '260'); $varfield->addAttribute('i1', ' '); $varfield->addAttribute('i2', ' '); $subfield = $varfield->addChild('subfield', htmlspecialchars($source)); $subfield->addAttribute('label', 'b'); } $updateDocParams = array('library' => $base, 'doc_num' => $docNum); $updateDocParams['xml_full_req'] = $document->asXml(); $updateDocParams['doc_action'] = 'UPDATE'; try { $update = $this->alephWebService->doXRequestUsingPost('update-doc', $updateDocParams, true); } catch (\Exception $ex) { return array('success' => false, 'sysMessage' => $ex->getMessage()); } return array('success' => true, 'id' => $docNum); }
/** * Returns an array with status information for provided item. * * @param array $item Array with DAIA item data * * @return array */ protected function getItemStatus($item) { $availability = false; $status = ''; // status cannot be null as this will crash the translator $duedate = null; $availableLink = ''; $queue = ''; if (array_key_exists('available', $item)) { if (count($item['available']) === 1) { $availability = true; } else { // check if item is loanable or presentation foreach ($item['available'] as $available) { // attribute service can be set once or not if (isset($available['service']) && in_array($available['service'], ['loan', 'presentation', 'openaccess'])) { // set item available if service is loan, presentation or // openaccess $availability = true; if ($available['service'] == 'loan' && isset($available['service']['href'])) { // save the link to the ils if we have a href for loan // service $availableLink = $available['service']['href']; } } // use limitation element for status string if (isset($available['limitation'])) { $status = $this->getItemLimitation($available['limitation']); } // log messages for debugging if (isset($available['message'])) { $this->logMessages($available['message'], 'item->available'); } } } } if (array_key_exists('unavailable', $item)) { foreach ($item['unavailable'] as $unavailable) { // attribute service can be set once or not if (isset($unavailable['service']) && in_array($unavailable['service'], ['loan', 'presentation', 'openaccess'])) { if ($unavailable['service'] == 'loan' && isset($unavailable['service']['href'])) { //save the link to the ils if we have a href for loan service } // use limitation element for status string if (isset($unavailable['limitation'])) { $status = $this->getItemLimitation($unavailable['limitation']); } } // attribute expected is mandatory for unavailable element if (isset($unavailable['expected'])) { try { $duedate = $this->dateConverter->convertToDisplayDate('Y-m-d', $unavailable['expected']); } catch (\Exception $e) { $this->debug('Date conversion failed: ' . $e->getMessage()); $duedate = null; } } // attribute queue can be set if (isset($unavailable['queue'])) { $queue = $unavailable['queue']; } // log messages for debugging if (isset($unavailable['message'])) { $this->logMessages($unavailable['message'], 'item->unavailable'); } } } /*'availability' => '0', 'status' => '', // string - needs to be computed from availability info 'duedate' => '', // if checked_out else null 'returnDate' => '', // false if not recently returned(?) 'requests_placed' => '', // total number of placed holds 'is_holdable' => false, // place holding possible?*/ if (!empty($availableLink)) { $return['ilslink'] = $availableLink; } $return['status'] = $status; $return['availability'] = $availability; $return['duedate'] = $duedate; $return['requests_placed'] = $queue; return $return; }
/** * Test citation generation * * @return void */ public function testDates() { // Build an object to test with (using empty configuration to ensure default // settings): $date = new Converter(new Config(array())); // Try some conversions: $this->assertEquals('11-29-1973', $date->convertToDisplayDate('U', 123456879)); $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y', '11-29-73')); $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y', '11-29-1973')); $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y H:i', '11-29-73 23:01')); $this->assertEquals('23:01', $date->convertToDisplayTime('m-d-y H:i', '11-29-73 23:01')); $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y', '01-02-01')); $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y', '01-02-2001')); $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y H:i', '01-02-01 05:11')); $this->assertEquals('05:11', $date->convertToDisplayTime('m-d-y H:i', '01-02-01 05:11')); $this->assertEquals('01-02-2001', $date->convertToDisplayDate('Y-m-d', '2001-01-02')); $this->assertEquals('01-02-2001', $date->convertToDisplayDate('Y-m-d H:i', '2001-01-02 05:11')); $this->assertEquals('05:11', $date->convertToDisplayTime('Y-m-d H:i', '2001-01-02 05:11')); $this->assertEquals('01-2001', $date->convertFromDisplayDate('m-Y', '01-02-2001')); // Check for proper handling of known problems: try { $bad = $date->convertToDisplayDate('U', 'invalid'); $this->fail('Expected exception did not occur'); } catch (DateException $e) { $this->assertTrue((bool) stristr($e->getMessage(), 'failed to parse time string')); } try { $bad = $date->convertToDisplayDate('d-m-Y', '31-02-2001'); $this->fail('Expected exception did not occur'); } catch (DateException $e) { $this->assertTrue((bool) stristr($e->getMessage(), 'parsed date was invalid')); } }
/** * Get an array of events for the record. * * @return array */ public function getEvents() { $events = []; foreach ($this->getSimpleXML()->xpath('/lidoWrap/lido/descriptiveMetadata/eventWrap/eventSet/event') as $node) { $name = isset($node->eventName->appellationValue) ? (string) $node->eventName->appellationValue : ''; $type = isset($node->eventType->term) ? mb_strtolower((string) $node->eventType->term, 'UTF-8') : ''; $date = isset($node->eventDate->displayDate) ? (string) $node->eventDate->displayDate : ''; if (!$date && isset($node->eventDate->date) && !empty($node->eventDate->date)) { $startDate = (string) $node->eventDate->date->earliestDate; $endDate = (string) $node->eventDate->date->latestDate; if (strlen($startDate) == 4 && strlen($endDate) == 4) { $date = "{$startDate}-{$endDate}"; } else { $startDateType = 'Y-m-d'; $endDateType = 'Y-m-d'; if (strlen($startDate) == 7) { $startDateType = 'Y-m'; } if (strlen($endDate) == 7) { $endDateType = 'Y-m'; } $date = $this->dateConverter->convertToDisplayDate($startDateType, $startDate); if ($startDate != $endDate) { $date .= '-' . $this->dateConverter->convertToDisplayDate($endDateType, $endDate); } } } if ($type == 'valmistus') { $confParam = 'lido_augment_display_date_with_period'; if ($this->getDataSourceConfigurationValue($confParam)) { if ($period = $node->periodName->term) { if ($date) { $date = $period . ', ' . $date; } else { $date = $period; } } } } $method = isset($node->eventMethod->term) ? (string) $node->eventMethod->term : ''; $materials = []; if (isset($node->eventMaterialsTech->displayMaterialsTech)) { // Use displayMaterialTech (default) $materials[] = (string) $node->eventMaterialsTech->displayMaterialsTech; } else { if (isset($node->eventMaterialsTech->materialsTech)) { // display label not defined, build from materialsTech $materials = []; foreach ($node->xpath('eventMaterialsTech/materialsTech') as $materialsTech) { if ($terms = $materialsTech->xpath('termMaterialsTech/term')) { foreach ($terms as $term) { $label = null; $attributes = $term->attributes(); if (isset($attributes->label)) { // Musketti $label = $attributes->label; } else { if (isset($materialsTech->extentMaterialsTech)) { // Siiri $label = $materialsTech->extentMaterialsTech; } } if ($label) { $term = "{$term} ({$label})"; } $materials[] = $term; } } } } } $places = []; $place = isset($node->eventPlace->displayPlace) ? (string) $node->eventPlace->displayPlace : ''; if (!$place) { if (isset($node->eventPlace->place->namePlaceSet)) { $eventPlace = []; foreach ($node->eventPlace->place->namePlaceSet as $namePlaceSet) { if (trim((string) $namePlaceSet->appellationValue) != '') { $eventPlace[] = isset($namePlaceSet) ? trim((string) $namePlaceSet->appellationValue) : ''; } } if ($eventPlace) { $places[] = implode(', ', $eventPlace); } } if (isset($node->eventPlace->place->partOfPlace)) { foreach ($node->eventPlace->place->partOfPlace as $partOfPlace) { $partOfPlaceName = []; while (isset($partOfPlace->namePlaceSet)) { $appellationValue = trim((string) $partOfPlace->namePlaceSet->appellationValue); if ($appellationValue !== '') { $partOfPlaceName[] = $appellationValue; } $partOfPlace = $partOfPlace->partOfPlace; } if ($partOfPlaceName) { $places[] = implode(', ', $partOfPlaceName); } } } } else { $places[] = $place; } $actors = []; if (isset($node->eventActor)) { foreach ($node->eventActor as $actor) { $appellationValue = isset($actor->actorInRole->actor->nameActorSet->appellationValue) ? trim($actor->actorInRole->actor->nameActorSet->appellationValue) : ''; if ($appellationValue !== '') { $role = isset($actor->actorInRole->roleActor->term) ? $actor->actorInRole->roleActor->term : ''; $actors[] = ['name' => $appellationValue, 'role' => $role]; } } } $culture = isset($node->culture->term) ? (string) $node->culture->term : ''; $description = isset($node->eventDescriptionSet->descriptiveNoteValue) ? (string) $node->eventDescriptionSet->descriptiveNoteValue : ''; $event = ['type' => $type, 'name' => $name, 'date' => $date, 'method' => $method, 'materials' => $materials, 'places' => $places, 'actors' => $actors, 'culture' => $culture, 'description' => $description]; $events[$type][] = $event; } return $events; }
/** * Place Hold * * Attempts to place a hold or recall on a particular item and returns * an array with result details. * * @param array $holdDetails An array of item and patron data * * @return mixed An array of data on the request including * whether or not it was successful and a system message (if available) */ public function placeHold($holdDetails) { // Simulate failure: if (rand() % 2) { return array("success" => false, "sysMessage" => 'Demonstrating failure; keep trying and ' . 'it will work eventually.'); } if (!isset($this->session->holds)) { $this->session->holds = new ArrayObject(); } $lastHold = count($this->session->holds) - 1; $nextId = $lastHold >= 0 ? $this->session->holds[$lastHold]['item_id'] + 1 : 0; // Figure out appropriate expiration date: if (!isset($holdDetails['requiredBy']) || empty($holdDetails['requiredBy'])) { $expire = strtotime("now + 30 days"); } else { try { $dateFormat = new DateConverter(); $expire = $dateFormat->convertFromDisplayDate("U", $holdDetails['requiredBy']); } catch (DateException $e) { // Hold Date is invalid return array('success' => false, 'sysMessage' => 'hold_date_invalid'); } } if ($expire <= time()) { return array('success' => false, 'sysMessage' => 'hold_date_past'); } $this->session->holds->append(array("id" => $holdDetails['id'], "location" => $holdDetails['pickUpLocation'], "expire" => date("j-M-y", $expire), "create" => date("j-M-y"), "reqnum" => sprintf("%06d", $nextId), "item_id" => $nextId)); return array('success' => true); }
/** * To Koha Date * * Turns a display date into a date format expected by Koha. * * @param string $display_date Date to be converted * * @throws ILSException * @return string $koha_date */ protected function toKohaDate($display_date) { $koha_date = ""; // Convert last interest date from format to Koha format $koha_date = $this->dateConverter->convertFromDisplayDate("Y-m-d", $display_date); $checkTime = $this->dateConverter->convertFromDisplayDate("U", $display_date); if (!is_numeric($checkTime)) { throw new DateException('Result should be numeric'); } if (time() > $checkTime) { // Hold Date is in the past throw new DateException('hold_date_past'); } return $koha_date; }
/** * Format date * * @param string $dateString Date as a string * * @return string Formatted date */ protected function formatDate($dateString) { // remove timezone from Axiell obscure dateformat $date = substr($dateString, 0, strpos("{$dateString}*", "+")); return $this->dateFormat->convertToDisplayDate("Y-m-d", $date); }
/** * Get the publication dates of the record. See also getDateSpan(). * * @return array */ public function getPublicationDates() { if (isset($this->fields['PublicationDate_xml']) && is_array($this->fields['PublicationDate_xml'])) { $dates = array(); $converter = new DateConverter(); foreach ($this->fields['PublicationDate_xml'] as $current) { if (isset($current['month']) && isset($current['year'])) { if (!isset($current['day'])) { $current['day'] = 1; } $dates[] = $converter->convertToDisplayDate('m-d-Y', "{$current['month']}-{$current['day']}-{$current['year']}"); } else { if (isset($current['year'])) { $dates[] = $current['year']; } } } if (!empty($dates)) { return $dates; } } return isset($this->fields['PublicationDate']) ? $this->fields['PublicationDate'] : array(); }
/** * Getting a default required date based on hold settings. * * @param array $checkHolds Hold settings returned by the ILS driver's * checkFunction method. * * @return string A formatted default required date */ public function getDefaultRequiredDate($checkHolds) { $formatDate = new DateConverter(); $dateArray = isset($checkHolds['defaultRequiredDate']) ? explode(":", $checkHolds['defaultRequiredDate']) : array(0, 1, 0); list($d, $m, $y) = $dateArray; $nextMonth = mktime(0, 0, 0, date("m") + $m, date("d") + $d, date("Y") + $y); return $formatDate->convertToDisplayDate("U", $nextMonth); }
/** * Parse a date. * * @param string $date Date to parse * * @return string */ public function parseDate($date) { if ($date == null || $date == "") { return ""; } else { if (preg_match("/^[0-9]{8}\$/", $date) === 1) { // 20120725 return $this->dateConverter->convertToDisplayDate('Ynd', $date); } else { if (preg_match("/^[0-9]+\\/[A-Za-z]{3}\\/[0-9]{4}\$/", $date) === 1) { // 13/jan/2012 return $this->dateConverter->convertToDisplayDate('d/M/Y', $date); } else { if (preg_match("/^[0-9]+\\/[0-9]+\\/[0-9]{4}\$/", $date) === 1) { // 13/7/2012 return $this->dateConverter->convertToDisplayDate('d/m/Y', $date); } else { throw new \Exception("Invalid date: {$date}"); } } } } }
/** * Place ILL Request * * Attempts to place an ILL request on a particular item and returns * an array with result details * * @param array $details An array of item and patron data * * @return mixed An array of data on the request including * whether or not it was successful and a system message (if available) */ public function placeILLRequest($details) { if (!$this->ILLRequests) { return ['success' => false, 'sysMessage' => 'ILL requests are disabled.']; } // Simulate failure: if ($this->isFailing(__METHOD__, 50)) { return ['success' => false, 'sysMessage' => 'Demonstrating failure; keep trying and ' . 'it will work eventually.']; } $session = $this->getSession(); if (!isset($session->ILLRequests)) { $session->ILLRequests = new ArrayObject(); } $lastRequest = count($session->ILLRequests) - 1; $nextId = $lastRequest >= 0 ? $session->ILLRequests[$lastRequest]['item_id'] + 1 : 0; // Figure out appropriate expiration date: if (!isset($details['requiredBy']) || empty($details['requiredBy'])) { $expire = strtotime('now + 30 days'); } else { try { $expire = $this->dateConverter->convertFromDisplayDate('U', $details['requiredBy']); } catch (DateException $e) { // Expiration Date is invalid return ['success' => false, 'sysMessage' => 'ill_request_date_invalid']; } } if ($expire <= time()) { return ['success' => false, 'sysMessage' => 'ill_request_date_past']; } // Verify pickup library and location $pickupLocation = ''; $pickupLocations = $this->getILLPickupLocations($details['id'], $details['pickUpLibrary'], $details['patron']); foreach ($pickupLocations as $location) { if ($location['id'] == $details['pickUpLibraryLocation']) { $pickupLocation = $location['name']; break; } } if (!$pickupLocation) { return ['success' => false, 'sysMessage' => 'ill_request_place_fail_missing']; } $session->ILLRequests->append(['id' => $details['id'], 'source' => $this->getRecordSource(), 'location' => $pickupLocation, 'expire' => $this->dateConverter->convertToDisplayDate('U', $expire), 'create' => $this->dateConverter->convertToDisplayDate('U', time()), 'processed' => rand() % 3 == 0 ? $this->dateConverter->convertToDisplayDate('U', $expire) : '', 'reqnum' => sprintf('%06d', $nextId), 'item_id' => $nextId]); return ['success' => true]; }
/** * Use a record driver to assign metadata to the current row. Return the * current object to allow fluent interface. * * @param \VuFind\RecordDriver\AbstractBase $driver The record driver * @param \VuFind\Date\Converter $converter Date converter * * @return \VuFind\Db\Row\Resource */ public function assignMetadata($driver, \VuFind\Date\Converter $converter) { // Grab title -- we have to have something in this field! $this->title = $driver->tryMethod('getSortTitle'); if (empty($this->title)) { $this->title = $driver->getBreadcrumb(); } // Try to find an author; if not available, just leave the default null: $author = $driver->tryMethod('getPrimaryAuthor'); if (!empty($author)) { $this->author = $author; } // Try to find a year; if not available, just leave the default null: $dates = $driver->tryMethod('getPublicationDates'); if (isset($dates[0]) && strlen($dates[0]) > 4) { try { $year = $converter->convertFromDisplayDate('Y', $dates[0]); } catch (DateException $e) { // If conversion fails, don't store a date: $year = ''; } } else { $year = isset($dates[0]) ? $dates[0] : ''; } if (!empty($year)) { $this->year = intval($year); } return $this; }
/** * Returns an array with status information for provided item. * * @param array $item Array with DAIA item data * * @return array */ protected function getItemStatus($item) { $availability = false; $status = ''; // status cannot be null as this will crash the translator $duedate = null; $serviceLink = ''; $queue = ''; $item_notes = []; $item_limitation_types = []; $services = []; if (isset($item['available'])) { // check if item is loanable or presentation foreach ($item['available'] as $available) { if (isset($available['service']) && in_array($available['service'], ['loan', 'presentation'])) { $services['available'][] = $available['service']; } // attribute service can be set once or not if (isset($available['service']) && in_array($available['service'], ['loan', 'presentation', 'openaccess'])) { // set item available if service is loan, presentation or // openaccess $availability = true; if ($available['service'] == 'loan' && isset($available['href'])) { // save the link to the ils if we have a href for loan // service $serviceLink = $available['href']; } } // use limitation element for status string if (isset($available['limitation'])) { $item_notes = array_merge($item_notes, $this->getItemLimitationContent($available['limitation'])); $item_limitation_types = array_merge($item_limitation_types, $this->getItemLimitationTypes($available['limitation'])); } // log messages for debugging if (isset($available['message'])) { $this->logMessages($available['message'], 'item->available'); } } } if (isset($item['unavailable'])) { foreach ($item['unavailable'] as $unavailable) { if (isset($unavailable['service']) && in_array($unavailable['service'], ['loan', 'presentation'])) { $services['unavailable'][] = $unavailable['service']; } // attribute service can be set once or not if (isset($unavailable['service']) && in_array($unavailable['service'], ['loan', 'presentation', 'openaccess'])) { if ($unavailable['service'] == 'loan' && isset($unavailable['href'])) { //save the link to the ils if we have a href for loan service $serviceLink = $unavailable['href']; } // use limitation element for status string if (isset($unavailable['limitation'])) { $item_notes = array_merge($item_notes, $this->getItemLimitationContent($unavailable['limitation'])); $item_limitation_types = array_merge($item_limitation_types, $this->getItemLimitationTypes($unavailable['limitation'])); } } // attribute expected is mandatory for unavailable element if (!empty($unavailable['expected'])) { try { $duedate = $this->dateConverter->convertToDisplayDate('Y-m-d', $unavailable['expected']); } catch (\Exception $e) { $this->debug('Date conversion failed: ' . $e->getMessage()); $duedate = null; } } // attribute queue can be set if (isset($unavailable['queue'])) { $queue = $unavailable['queue']; } // log messages for debugging if (isset($unavailable['message'])) { $this->logMessages($unavailable['message'], 'item->unavailable'); } } } /*'returnDate' => '', // false if not recently returned(?)*/ if (!empty($serviceLink)) { $return['ilslink'] = $serviceLink; } $return['item_notes'] = $item_notes; $return['status'] = $this->getStatusString($item); $return['availability'] = $availability; $return['duedate'] = $duedate; $return['requests_placed'] = $queue; $return['services'] = $this->getAvailableItemServices($services); // In this DAIA driver implementation addLink and is_holdable are assumed // Boolean as patron based availability requires either a patron-id or -type. // This should be handled in a custom DAIA driver $return['addLink'] = $this->checkIsRecallable($item); $return['is_holdable'] = $this->checkIsRecallable($item); $return['holdtype'] = $this->getHoldType($item); // Check if we the item is available for storage retrieval request if it is // not holdable. $return['addStorageRetrievalRequestLink'] = !$return['is_holdable'] ? $this->checkIsStorageRetrievalRequest($item) : false; // add a custom Field to allow passing custom DAIA data to the frontend in // order to use it for more precise display of availability $return['customData'] = $this->getCustomData($item); $return['limitation_types'] = $item_limitation_types; return $return; }