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

refs #21044 [finc] adapt icon mapping by configuration

* more robust constructor of record view helper
* code styles
* use beautifier: "vendor/bin/phpcbf --standard=devops/codecheck/rules/phpcs.xml module/finc/src/finc/View/Helper/Root/Record.php"
parent 84460898
No related merge requests found
......@@ -76,7 +76,7 @@ class Record extends \VuFind\View\Helper\Root\Record
protected $resolverConfig;
/**
* mapping for facets on style based icons
* Mapping for facets on style based icons
*
* @var \Zend\Config\Config
*/
......@@ -99,8 +99,8 @@ class Record extends \VuFind\View\Helper\Root\Record
/**
* Handling for array of entry keys
*
* true => concatenate keys for mapping
* false => use first key only for mapping
* True => concatenate keys for mapping
* False => use first key only for mapping
*
* @var string
*/
......@@ -109,12 +109,12 @@ class Record extends \VuFind\View\Helper\Root\Record
/**
* Constructor
*
* @param \Zend\Config\Config $config VuFind configuration
* @param \Zend\View\Helper\Url $helper URL helper
* @param \VuFind\Auth\Manager $manager AuthManager
* @param mixed $rewrite
* @param mixed $resolverConfig
*
* @param \Zend\Config\Config $config VuFind configuration
* @param \Zend\View\Helper\Url $helper URL helper
* @param \VuFind\Auth\Manager $manager AuthManager
* @param mixed $rewrite Ebl rewrite service for VuFind
* @param mixed $resolverConfig Resolver.ini
* @param mixed $iconConfig iconMapping.ini
*/
public function __construct(
$config,
......@@ -122,31 +122,40 @@ class Record extends \VuFind\View\Helper\Root\Record
\VuFind\Auth\Manager $manager,
$rewrite,
$resolverConfig,
$iconConfig
$iconConfig = null
) {
parent::__construct($config);
$this->url = $helper;
$this->manager = $manager;
$this->rewrite = $rewrite;
$this->resolverConfig = $resolverConfig;
$this->iconConfig = $iconConfig;
$this->iconMappingType = $this->iconConfig->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;
if ($iconConfig) {
$this->iconConfig = $iconConfig;
$this->iconMappingType = $this->iconConfig
->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.
*
* @param string $tpl Define alternative template for record icon. Default: record-icon.phtml
* @param bool $addText Return additional access / format. Default: true
* @param string $tpl Template for record icon, default: record-icon.phtml
* @param bool $addText Return additional access / format. Default: true
*
* @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();
$iconClass = $this->getRecordIconClass($iconType);
return $this->renderTemplate($tpl . '.phtml', ['iconClass' => $iconClass])
......@@ -162,18 +171,24 @@ class Record extends \VuFind\View\Helper\Root\Record
*/
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
*
* @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
*/
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) {
$iconType = $this->getRecordIconType();
}
......@@ -181,27 +196,36 @@ class Record extends \VuFind\View\Helper\Root\Record
$iconClass = $this->getRecordIconClass($iconType);
}
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();
switch ($recordType) {
case 'lido':
return "object";
case 'missing':
case 'marcfincpda':
return $recordType;
default:
$types = explode('_', $this->iconMappingType);
$recordType = '';
foreach ($types as $type) {
$recordTypes = $this->driver->tryMethod("get{$type}") ?? ['default'];
$recordTypes = $this->concatKeysForIconMapping ? implode('', $recordTypes) : $recordTypes[0] ?? 'default';
$recordType .= strtolower(str_replace([' ','-',','], '', $recordTypes));
}
return $recordType;
switch ($recordType)
{
case 'lido':
return "object";
case 'missing':
case 'marcfincpda':
return $recordType;
default:
$types = explode('_', $this->iconMappingType);
$recordType = '';
foreach ($types as $type) {
$recordTypes = $this->driver->tryMethod("get{$type}") ?? ['default'];
$recordTypes = $this->concatKeysForIconMapping ?
implode('', $recordTypes) : $recordTypes[0] ?? 'default';
$recordType .= strtolower(str_replace([' ','-',','], '', $recordTypes));
}
return $recordType;
}
}
......@@ -212,8 +236,7 @@ class Record extends \VuFind\View\Helper\Root\Record
*/
public function showStyleBasedIcons()
{
return isset($this->config->Content->showStyleBasedIcons) ?
$this->config->Content->showStyleBasedIcons : false;
return $this->config->Content->showStyleBasedIcons ?? false;
}
/**
......@@ -230,7 +253,8 @@ class Record extends \VuFind\View\Helper\Root\Record
$type == 'author'
? $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) ?? '');
}
......@@ -279,9 +303,9 @@ class Record extends \VuFind\View\Helper\Root\Record
public function removeAuthorDates($author)
{
$match = [];
$regex =
'/^(\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';
$regex
= '/^(\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';
if (preg_match($regex, $author, $match)) {
$author = (isset($match[1])) ? trim($match[1]) : $author;
}
......@@ -339,13 +363,16 @@ class Record extends \VuFind\View\Helper\Root\Record
if (0 != preg_match(
'/' . addcslashes($r['remove'], '/') . '/i',
trim($link['url'])
)) {
)
) {
unset($link);
return;
}
}
// 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 (isset($r['function']) && is_callable($r['function'])) {
$link['url'] = $r['function']($link['url']);
......@@ -483,18 +510,10 @@ class Record extends \VuFind\View\Helper\Root\Record
$onlineEditions = [];
$recordLinkHelper = $this->getView()->plugin('recordLink');
foreach ($this->driver->tryMethod('getAdditionals') as $add) {
if (
isset($add['identifier'])
&&
(
in_array($add['identifier'], $online_keys)
||
(
isset($add['note'])
&&
in_array($add['note'], $online_keys)
)
)
if (isset($add['identifier'])
&& (in_array($add['identifier'], $online_keys)
|| (isset($add['note'])
&& in_array($add['note'], $online_keys)))
) {
if (isset($add['id'])) {
$link = $recordLinkHelper->getTabUrl($add['id'], 'Holdings');
......@@ -517,6 +536,11 @@ class Record extends \VuFind\View\Helper\Root\Record
return $onlineEditions;
}
/**
* Get advanced query params
*
* @return array
*/
public function getAdvancedSearchQueryParams()
{
$queryParams = [];
......@@ -530,7 +554,8 @@ class Record extends \VuFind\View\Helper\Root\Record
$queryParams['type0'][] = 'ISN';
}
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';
}
if (!empty($queryParams)) {
......@@ -544,11 +569,12 @@ class Record extends \VuFind\View\Helper\Root\Record
/**
* 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 $default The default size of the cover
* @param string $link The link for the anchor
*
* @deprecated used for VF7 ajaxcovers, remove on upgrade
*
* @return array
*/
public function getCoverDetails($context, $default, $link = false)
......@@ -570,11 +596,12 @@ class Record extends \VuFind\View\Helper\Root\Record
}
if ($details['size'] === false) {
// 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(
'record/cover.phtml', $details
'record/cover.phtml',
$details
);
}
return $details;
......@@ -583,10 +610,11 @@ class Record extends \VuFind\View\Helper\Root\Record
/**
* 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
* default).
*
* @deprecated used for VF7 ajaxcovers, remove on upgrade
*
* @return string|bool
*/
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