From 60124708b8e3f404ff94a743811a70549af0a2ac Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 25 May 2016 10:10:41 -0400 Subject: [PATCH] Refactored getCover() - aimed for greater clarity and potential code reuse - added getCoverDetails() to optionally expose more details. --- .../src/VuFind/View/Helper/Root/Record.php | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index b5485bae2f6..fac87a7a824 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -415,33 +415,63 @@ class Record extends AbstractHelper * @return string */ public function getCover($context, $default, $link = false) + { + $details = $this->getCoverDetails($context, $default, $link); + return $details['html']; + } + + /** + * Get the rendered cover plus some useful parameters. + * + * @param string $context Context of code being genarated + * @param string $default The default size of the cover + * @param string $link The link for the anchor + * + * @return array + */ + public function getCoverDetails($context, $default, $link = false) + { + $details = compact('link', 'context') + [ + 'driver' => $this->driver, 'cover' => false, 'size' => false + ]; + $preferredSize = $this->getCoverSize($context, $default); + if (empty($preferredSize)) { // covers disabled entirely + $details['html'] = ''; + } else { + // Find best option if more than one size is defined (e.g. small:medium) + foreach (explode(':', $preferredSize) as $size) { + if ($details['cover'] = $this->getThumbnail($size)) { + $details['size'] = $size; + break; + } + } + + $details['html'] = $this->contextHelper->renderInContext( + 'record/cover.phtml', $details + ); + } + return $details; + } + + /** + * Get the configured thumbnail size for record lists + * + * @param string $context Context of code being genarated + * @param string $default The default size of the cover + * + * @return string + */ + protected function getCoverSize($context, $default = 'medium') { if (isset($this->config->Content->coversize) && !$this->config->Content->coversize ) { // covers disabled entirely - $preferredSize = false; - } else { - // check for context-specific overrides - $preferredSize = isset($this->config->Content->coversize[$context]) - ? $this->config->Content->coversize[$context] : $default; - } - if (empty($preferredSize)) { - return ''; - } - - // Find best option if more than one size is defined (e.g. small:medium) - $cover = false; // assume invalid until good size found below - foreach (explode(':', $preferredSize) as $size) { - if ($cover = $this->getThumbnail($size)) { - break; - } + return false; } - - $driver = $this->driver; // for convenient use in compact() - return $this->contextHelper->renderInContext( - 'record/cover.phtml', compact('cover', 'link', 'context', 'driver') - ); + // check for context-specific overrides + return isset($this->config->Content->coversize[$context]) + ? $this->config->Content->coversize[$context] : $default; } /** -- GitLab