Skip to content
Snippets Groups Projects
Commit 07f8882c authored by Robert Lange's avatar Robert Lange
Browse files

Merge branch 'finc' into instance/fid

parents d5f0419a 4c502ed1
No related merge requests found
...@@ -76,7 +76,7 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -76,7 +76,7 @@ class Record extends \VuFind\View\Helper\Root\Record
protected $resolverConfig; protected $resolverConfig;
/** /**
* mapping for facets on style based icons * Mapping for facets on style based icons
* *
* @var \Zend\Config\Config * @var \Zend\Config\Config
*/ */
...@@ -99,8 +99,8 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -99,8 +99,8 @@ class Record extends \VuFind\View\Helper\Root\Record
/** /**
* Handling for array of entry keys * Handling for array of entry keys
* *
* true => concatenate keys for mapping * True => concatenate keys for mapping
* false => use first key only for mapping * False => use first key only for mapping
* *
* @var string * @var string
*/ */
...@@ -109,12 +109,12 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -109,12 +109,12 @@ class Record extends \VuFind\View\Helper\Root\Record
/** /**
* Constructor * Constructor
* *
* @param \Zend\Config\Config $config VuFind configuration * @param \Zend\Config\Config $config VuFind configuration
* @param \Zend\View\Helper\Url $helper URL helper * @param \Zend\View\Helper\Url $helper URL helper
* @param \VuFind\Auth\Manager $manager AuthManager * @param \VuFind\Auth\Manager $manager AuthManager
* @param mixed $rewrite * @param mixed $rewrite Ebl rewrite service for VuFind
* @param mixed $resolverConfig * @param mixed $resolverConfig Resolver.ini
* * @param mixed $iconConfig iconMapping.ini
*/ */
public function __construct( public function __construct(
$config, $config,
...@@ -122,31 +122,40 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -122,31 +122,40 @@ class Record extends \VuFind\View\Helper\Root\Record
\VuFind\Auth\Manager $manager, \VuFind\Auth\Manager $manager,
$rewrite, $rewrite,
$resolverConfig, $resolverConfig,
$iconConfig $iconConfig = null
) { ) {
parent::__construct($config); parent::__construct($config);
$this->url = $helper; $this->url = $helper;
$this->manager = $manager; $this->manager = $manager;
$this->rewrite = $rewrite; $this->rewrite = $rewrite;
$this->resolverConfig = $resolverConfig; $this->resolverConfig = $resolverConfig;
$this->iconConfig = $iconConfig;
$this->iconMappingType = $this->iconConfig->StyleBasedIcons->type ?? 'None'; if ($iconConfig) {
$this->iconMappings = isset($this->iconConfig->StyleBasedIcons->{$this->iconMappingType}) $this->iconConfig = $iconConfig;
? $this->iconConfig->StyleBasedIcons->{$this->iconMappingType}->toArray() : []; $this->iconMappingType = $this->iconConfig
$this->concatKeysForIconMapping = $this->iconConfig->StyleBasedIcons->concatenateKeys ? true : false; ->StyleBasedIcons->type ?? 'None';
$this->iconMappings = isset(
$this->iconConfig
->StyleBasedIcons->{$this->iconMappingType}
) ? $this->iconConfig
->StyleBasedIcons->{$this->iconMappingType}->toArray() : [];
$this->concatKeysForIconMapping = $this->iconConfig
->StyleBasedIcons->concatenateKeys ? true : false;
}
} }
/** /**
* Render a (list of) record icons. * Render a (list of) record icons.
* *
* @param string $tpl Define alternative template for record icon. Default: record-icon.phtml * @param string $tpl Template for record icon, default: record-icon.phtml
* @param bool $addText Return additional access / format. Default: true * @param bool $addText Return additional access / format. Default: true
* *
* @return string * @return string
*/ */
public function getRecordIcon(string $tpl = 'record-icon', bool $addText = true): string public function getRecordIcon(
{ string $tpl = 'record-icon',
bool $addText = true
): string {
$iconType = $this->getRecordIconType(); $iconType = $this->getRecordIconType();
$iconClass = $this->getRecordIconClass($iconType); $iconClass = $this->getRecordIconClass($iconType);
return $this->renderTemplate($tpl . '.phtml', ['iconClass' => $iconClass]) return $this->renderTemplate($tpl . '.phtml', ['iconClass' => $iconClass])
...@@ -162,18 +171,24 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -162,18 +171,24 @@ class Record extends \VuFind\View\Helper\Root\Record
*/ */
public function getRecordIconClass(string $key = "default"): string public function getRecordIconClass(string $key = "default"): string
{ {
return $this->iconMappings[$key] ?? $this->iconMappings["default"] ?? "unknown"; return $this->iconMappings[$key] ??
$this->iconMappings["default"] ?? "unknown";
} }
/** /**
* Get the CSS class used to properly render an icon for given value * Get the CSS class used to properly render an icon for given value
* *
* @param string $classfile Define alternative file for icon text without * @param string|null $iconType icon type
* @param string|null $iconClass css class for icon
* @param string $classfile Define alternative file for icon text without
* *
* @return string * @return string
*/ */
public function getRecordIconText(string $iconType = null, string $iconClass = null, $classfile = 'record-icon-text'): string public function getRecordIconText(
{ string $iconType = null,
string $iconClass = null,
string $classfile = 'record-icon-text'
): string {
if (null === $iconType) { if (null === $iconType) {
$iconType = $this->getRecordIconType(); $iconType = $this->getRecordIconType();
} }
...@@ -181,27 +196,36 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -181,27 +196,36 @@ class Record extends \VuFind\View\Helper\Root\Record
$iconClass = $this->getRecordIconClass($iconType); $iconClass = $this->getRecordIconClass($iconType);
} }
return $this->renderTemplate( return $this->renderTemplate(
$classfile . '.phtml', compact('iconType', 'iconClass') $classfile . '.phtml',
compact('iconType', 'iconClass')
); );
} }
protected function getRecordIconType() { /**
* Get icon by record type
*
* @return string
*/
protected function getRecordIconType()
{
$recordType = $this->driver->getRecordType(); $recordType = $this->driver->getRecordType();
switch ($recordType) { switch ($recordType)
case 'lido': {
return "object"; case 'lido':
case 'missing': return "object";
case 'marcfincpda': case 'missing':
return $recordType; case 'marcfincpda':
default: return $recordType;
$types = explode('_', $this->iconMappingType); default:
$recordType = ''; $types = explode('_', $this->iconMappingType);
foreach ($types as $type) { $recordType = '';
$recordTypes = $this->driver->tryMethod("get{$type}") ?? ['default']; foreach ($types as $type) {
$recordTypes = $this->concatKeysForIconMapping ? implode('', $recordTypes) : $recordTypes[0] ?? 'default'; $recordTypes = $this->driver->tryMethod("get{$type}") ?? ['default'];
$recordType .= strtolower(str_replace([' ','-',','], '', $recordTypes)); $recordTypes = $this->concatKeysForIconMapping ?
} implode('', $recordTypes) : $recordTypes[0] ?? 'default';
return $recordType; $recordType .= strtolower(str_replace([' ','-',','], '', $recordTypes));
}
return $recordType;
} }
} }
...@@ -212,8 +236,7 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -212,8 +236,7 @@ class Record extends \VuFind\View\Helper\Root\Record
*/ */
public function showStyleBasedIcons() public function showStyleBasedIcons()
{ {
return isset($this->config->Content->showStyleBasedIcons) ? return $this->config->Content->showStyleBasedIcons ?? false;
$this->config->Content->showStyleBasedIcons : false;
} }
/** /**
...@@ -230,7 +253,8 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -230,7 +253,8 @@ class Record extends \VuFind\View\Helper\Root\Record
$type == 'author' $type == 'author'
? $this->removeAuthorDates($lookfor) : $lookfor ? $this->removeAuthorDates($lookfor) : $lookfor
); );
/* remove invalid new line in link templates, remove after fixed in templates or VuFind parent */ /* remove invalid new line in link templates,
remove after fixed in templates or VuFind parent */
return str_replace(["\n"], '', parent::getLink($type, $lookfor) ?? ''); return str_replace(["\n"], '', parent::getLink($type, $lookfor) ?? '');
} }
...@@ -279,9 +303,9 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -279,9 +303,9 @@ class Record extends \VuFind\View\Helper\Root\Record
public function removeAuthorDates($author) public function removeAuthorDates($author)
{ {
$match = []; $match = [];
$regex = $regex
'/^(\s|.*)\s(fl.\s|d.\s|ca.\s|\*)*\s?(\d{4})\??(\sor\s\d\d?)?\s?' = '/^(\s|.*)\s(fl.\s|d.\s|ca.\s|\*)*\s?(\d{4})\??(\sor\s\d\d?)?\s?'
. '(-|–)?\s?(ca.\s|after\s|†)?(\d{1,4})?(.|,)?$/Uu'; . '(-|–)?\s?(ca.\s|after\s|†)?(\d{1,4})?(.|,)?$/Uu';
if (preg_match($regex, $author, $match)) { if (preg_match($regex, $author, $match)) {
$author = (isset($match[1])) ? trim($match[1]) : $author; $author = (isset($match[1])) ? trim($match[1]) : $author;
} }
...@@ -339,13 +363,16 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -339,13 +363,16 @@ class Record extends \VuFind\View\Helper\Root\Record
if (0 != preg_match( if (0 != preg_match(
'/' . addcslashes($r['remove'], '/') . '/i', '/' . addcslashes($r['remove'], '/') . '/i',
trim($link['url']) trim($link['url'])
)) { )
) {
unset($link); unset($link);
return; return;
} }
} }
// is pattern set and matches so try rewrite url // is pattern set and matches so try rewrite url
if (isset($r['pattern']) && 0 != preg_match('/' . $r['pattern'] . '/i', trim($link['url']))) { if (isset($r['pattern'])
&& 0 != preg_match('/' . $r['pattern'] . '/i', trim($link['url']))
) {
// if function is set and available then perform on url // if function is set and available then perform on url
if (isset($r['function']) && is_callable($r['function'])) { if (isset($r['function']) && is_callable($r['function'])) {
$link['url'] = $r['function']($link['url']); $link['url'] = $r['function']($link['url']);
...@@ -483,18 +510,10 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -483,18 +510,10 @@ class Record extends \VuFind\View\Helper\Root\Record
$onlineEditions = []; $onlineEditions = [];
$recordLinkHelper = $this->getView()->plugin('recordLink'); $recordLinkHelper = $this->getView()->plugin('recordLink');
foreach ($this->driver->tryMethod('getAdditionals') as $add) { foreach ($this->driver->tryMethod('getAdditionals') as $add) {
if ( if (isset($add['identifier'])
isset($add['identifier']) && (in_array($add['identifier'], $online_keys)
&& || (isset($add['note'])
( && in_array($add['note'], $online_keys)))
in_array($add['identifier'], $online_keys)
||
(
isset($add['note'])
&&
in_array($add['note'], $online_keys)
)
)
) { ) {
if (isset($add['id'])) { if (isset($add['id'])) {
$link = $recordLinkHelper->getTabUrl($add['id'], 'Holdings'); $link = $recordLinkHelper->getTabUrl($add['id'], 'Holdings');
...@@ -517,6 +536,11 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -517,6 +536,11 @@ class Record extends \VuFind\View\Helper\Root\Record
return $onlineEditions; return $onlineEditions;
} }
/**
* Get advanced query params
*
* @return array
*/
public function getAdvancedSearchQueryParams() public function getAdvancedSearchQueryParams()
{ {
$queryParams = []; $queryParams = [];
...@@ -530,7 +554,8 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -530,7 +554,8 @@ class Record extends \VuFind\View\Helper\Root\Record
$queryParams['type0'][] = 'ISN'; $queryParams['type0'][] = 'ISN';
} }
if ($author = $this->driver->tryMethod('getPrimaryAuthors')) { if ($author = $this->driver->tryMethod('getPrimaryAuthors')) {
$queryParams['lookfor0'][] = is_array($author) ? current($author) : $author; $queryParams['lookfor0'][] = is_array($author) ?
current($author) : $author;
$queryParams['type0'][] = 'Author'; $queryParams['type0'][] = 'Author';
} }
if (!empty($queryParams)) { if (!empty($queryParams)) {
...@@ -544,11 +569,12 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -544,11 +569,12 @@ class Record extends \VuFind\View\Helper\Root\Record
/** /**
* Get the rendered cover plus some useful parameters. * Get the rendered cover plus some useful parameters.
* *
* @deprecated used for VF7 ajaxcovers, remove on upgrade
* @param string $context Context of code being generated * @param string $context Context of code being generated
* @param string $default The default size of the cover * @param string $default The default size of the cover
* @param string $link The link for the anchor * @param string $link The link for the anchor
* *
* @deprecated used for VF7 ajaxcovers, remove on upgrade
*
* @return array * @return array
*/ */
public function getCoverDetails($context, $default, $link = false) public function getCoverDetails($context, $default, $link = false)
...@@ -570,11 +596,12 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -570,11 +596,12 @@ class Record extends \VuFind\View\Helper\Root\Record
} }
if ($details['size'] === false) { if ($details['size'] === false) {
// we need to set a size for the ajax covers to work correctly // we need to set a size for the ajax covers to work correctly
list($details['size']) = explode(':', $preferredSize); [$details['size']] = explode(':', $preferredSize);
} }
$details['html'] = $this->contextHelper->renderInContext( $details['html'] = $this->contextHelper->renderInContext(
'record/cover.phtml', $details 'record/cover.phtml',
$details
); );
} }
return $details; return $details;
...@@ -583,10 +610,11 @@ class Record extends \VuFind\View\Helper\Root\Record ...@@ -583,10 +610,11 @@ class Record extends \VuFind\View\Helper\Root\Record
/** /**
* Generate a thumbnail URL (return false if unsupported). * Generate a thumbnail URL (return false if unsupported).
* *
* @deprecated used for VF7 ajaxcovers, remove on upgrade
* @param string $size Size of thumbnail (small, medium or large -- small is * @param string $size Size of thumbnail (small, medium or large -- small is
* default). * default).
* *
* @deprecated used for VF7 ajaxcovers, remove on upgrade
*
* @return string|bool * @return string|bool
*/ */
public function getThumbnail($size = 'small') public function getThumbnail($size = 'small')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment