Skip to content

Commit

Permalink
Add TOC from Obalkyknih.cz
Browse files Browse the repository at this point in the history
  • Loading branch information
xmorave2 committed May 21, 2024
1 parent 788ddc1 commit 197589f
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,8 @@ noCoverAvailableImage = images/noCover2.gif
; the description tab.
;summaries = Syndetics:MySyndeticsId,SyndeticsPlus:MySyndeticsId

; You can select from Syndetics or SyndeticsPlus to load Tables of Contents
;toc = Syndetics:MySyndeticsId,SyndeticsPlus:MySyndeticsId
; You can select from Syndetics, SyndeticsPlus or ObalkyKnih to load Tables of Contents
;toc = Syndetics:MySyndeticsId,SyndeticsPlus:MySyndeticsId,ObalkyKnih

; You can select from Syndetics or SyndeticsPlus
;authorNotes = Syndetics:MySyndeticsId,SyndeticsPlus:MySyndeticsId
Expand Down
3 changes: 1 addition & 2 deletions module/VuFind/src/VuFind/Content/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ protected function getIsbnObject($isbn)
*
* @param string $isbn ISBN to use for lookup
*
* @return array
* @return array|string
*/
public function loadByIsbn($isbn)
{
$results = [];
if (!($isbnObj = $this->getIsbnObject($isbn))) {
return $results;
}

// Fetch from provider
$providers = explode(',', $this->providers);
foreach ($providers as $provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function __invoke(
}

$service = $container->get(\VuFind\Content\ObalkyKnihService::class);
$covers = new $requestedName($service);
return $covers;
return new $requestedName($service);
}
}
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Content/ObalkyKnihService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function getHttpClient(string $url = null)
*/
protected function createCacheKey(array $ids)
{
$key = $ids['recordid'];
$key = $ids['recordid'] ?? '';
$key = !empty($key) ? $key
: (isset($ids['isbn']) ? $ids['isbn']->get13() : null);
$key = !empty($key) ? $key : sha1(json_encode($ids));
Expand Down
80 changes: 80 additions & 0 deletions module/VuFind/src/VuFind/Content/TOC/ObalkyKnih.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* Obalky knih TOC content loader.
*
* PHP version 8
*
* Copyright (C) Moravian Library 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Content
* @author Josef Moravec <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/

declare(strict_types=1);

namespace VuFind\Content\TOC;

use VuFind\Content\ObalkyKnihService;

/**
* Class ObalkyKnih
*
* @category VuFind
* @package Content
* @author Josef Moravec <[email protected]>
* @license https://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class ObalkyKnih extends \VuFind\Content\AbstractBase
{
/**
* Constructor
*
* @param ObalkyKnihService $service Service for getting metadata from obalkyknih.cz
*/
public function __construct(protected ObalkyKnihService $service)
{
}

/**
* This method is responsible for generating fake TOC data for testing
* purposes.
*
* @param string $key API key
* @param \VuFindCode\ISBN $isbnObj ISBN object
*
* @throws \Exception
* @return array|string Returns html string with preview image and link to TOC PDF file
*/
public function loadByIsbn($key, \VuFindCode\ISBN $isbnObj)
{
$ids = [
'isbn' => $isbnObj,
];
$data = $this->service->getData($ids);
$toc = '';
if (isset($data->toc_thumbnail_url)) {
$toc = "<p></p><a href='" . htmlspecialchars($data->toc_pdf_url)
. "' target='_blank' ><img src='"
. htmlspecialchars($data->toc_thumbnail_url) . "'></a></p>";
}
return $toc;
}
}
2 changes: 2 additions & 0 deletions module/VuFind/src/VuFind/Content/TOC/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
*/
protected $aliases = [
'demo' => Demo::class,
'obalkyknih' => ObalkyKnih::class,
'syndetics' => Syndetics::class,
'syndeticsplus' => SyndeticsPlus::class,
];
Expand All @@ -58,6 +59,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
*/
protected $factories = [
Demo::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
ObalkyKnih::class => \VuFind\Content\ObalkyKnihContentFactory::class,
Syndetics::class => \VuFind\Content\AbstractSyndeticsFactory::class,
SyndeticsPlus::class => \VuFind\Content\AbstractSyndeticsFactory::class,
];
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/RecordTab/AbstractContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function isActive()
/**
* Get content for ISBN.
*
* @return array
* @return array|string
*/
public function getContent()
{
Expand Down

0 comments on commit 197589f

Please sign in to comment.