Skip to content

Instantly share code, notes, and snippets.

@mjlassila
Last active August 29, 2015 13:55
Show Gist options
  • Save mjlassila/8782172 to your computer and use it in GitHub Desktop.
Save mjlassila/8782172 to your computer and use it in GitHub Desktop.
Vufind-Finna MarcRecord.php modifications for sorting holdings etc.
<?php
require_once 'RecordDrivers/MarcRecord.php';
/**
 * Local MarcRecord modifications.
 */
class MarcRecordLocal extends MarcRecord
{
/**
* Assign necessary Smarty variables and return a template name to
* load in order to display holdings extracted from the base record
* (i.e. URLs in MARC 856 fields) and, if necessary, the ILS driver.
* Returns null if no data is available.
*
* @param array $patron An array of patron data
*
* @return string Name of Smarty template file to display.
* @access public
*/
public function getHoldings($patron = false)
{
global $interface;
global $configArray;
// Only display OpenURL link if the option is turned on and we have
// an ISSN. We may eventually want to make this rule more flexible,
// but for now the ISSN restriction is designed to be consistent with
// the way we display items on the search results list. Actually,
// display OpenURL link for records with ISBNs too.
$hasOpenURL = ($this->openURLActive('holdings') && ($this->getCleanISSN() || $this->getCleanISBN()));
if ($hasOpenURL) {
$interface->assign('holdingsOpenURL', $this->getOpenURL());
}
// Display regular URLs unless OpenURL is present and configured to
// replace them:
if (!isset($configArray['OpenURL']['replace_other_urls'])
|| !$configArray['OpenURL']['replace_other_urls'] || !$hasOpenURL
) {
$interface->assign('holdingURLs', $this->getURLs());
}
$interface->assign('holdingLCCN', $this->getLCCN());
$interface->assign('holdingArrOCLC', $this->getOCLC());
// Load real-time data if available:
$unsortedHoldings = $this->getRealTimeHoldings($patron);
// Sold holdings to preferred order given in config.local.ini
$sortedHoldings = $this->_sortHoldings($unsortedHoldings);
$interface->assign('holdings', $sortedHoldings);
$interface->assign('history', $this->getRealTimeHistory());
// Source ID
$sourceId = $this->getSourceID();
$interface->assign('source', $sourceId);
// NDL Location Service enabled
$config = getExtraConfigArray('LocationService');
if (isset($config['General']) && isset($config[$sourceId])) {
$baseUrl = $config['General']['url'];
$lang = $interface->getLanguage();
$params = array(
'lang' => substr($lang, 0, 2),
'owner' => $config[$sourceId]['owner']
);
$url = $baseUrl . '?' . http_build_query($params);
$interface->assign('locationServiceUrl', $url);
if (isset($config['General']['modal']) && $config['General']['modal']) {
$interface->assign('locationServiceModal', true);
}
}
if ("driver" == CatalogConnection::getHoldsMode()) {
$interface->assign('driverMode', true);
if (!UserAccount::isLoggedIn()) {
$interface->assign('showLoginMsg', true);
}
}
if ("driver" == CatalogConnection::getTitleHoldsMode()) {
$interface->assign('titleDriverMode', true);
if (!UserAccount::isLoggedIn()) {
$interface->assign('showTitleLoginMsg', true);
}
}
$interface->assign("holdingTitleHold", $this->getRealTimeTitleHold($patron));
return 'RecordDrivers/Index/holdings.tpl';
}
/**
* Sorts holdings to the order set in config.ini
*
* @param string $hierarchyDriver A Hierarchy Driver Object
*
* @return string $identifier the solr field which defines collections
* @access public
*/
private function _sortHoldings($unsortedHoldings)
{
global $configArray;
$preferredOrder = false;
if ($preferredOrder === false) {
$preferredOrder = isset($configArray['Record']['preferred_order'])
? $configArray['Record']['preferred_order'] : array();
}
$sortedHoldings= array();
foreach ($unsortedHoldings as $location => $details) {
$position = array_search($location, $preferredOrder);
if ($position) {
$details['position'] = $position;
$sortedHoldings[$location] = $details;
} else {
$details['position'] = 1000;
$sortedHoldings[$location] = $details;
}
}
$sorted = array();
foreach ($sortedHoldings as $key => $row) {
$sorted[$key] = $row['position'];
}
array_multisort($sorted, SORT_ASC,$sortedHoldings);
foreach($sortedHoldings as &$location) {
unset($location['position']);
}
return $sortedHoldings;
}
}
@mjlassila
Copy link
Author

This script should not be used anymore. Insttead, use Request Group settings in Voyager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment