/** * 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]; }
/** * Support method for testDates() * * @return void */ protected function runTests() { // Build an object to test with (using empty configuration to ensure default // settings): $date = new Converter(new Config([])); // Try some conversions: $this->assertEquals('11-29-1973', $date->convertToDisplayDate('U', 123456879)); $this->assertEquals('11-29-1973', $date->convertToDisplayDate('U', 123456879.1234)); $this->assertEquals('11-29-1973--16:34', $date->convertToDisplayDateAndTime('U', 123456879, '--')); $this->assertEquals('16:34 11-29-1973', $date->convertToDisplayTimeAndDate('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')); } }
/** * 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 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']]; }
/** * 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']]; }
/** * 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}"); } } } } }
/** * 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; }
/** * 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 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]; }
/** * 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); }
/** * 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; }