diff --git a/composer.json b/composer.json index 3a997e3f8cdda4cb2a61eac67dcd7421a78cd75b..a06974638116d3a219ac7576453ed9f2f005295f 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "extra": { "vufind": { "themes": { - "theme": ".boss" + "res\theme": ".boss" } } } diff --git a/theme/mixin.config.php b/res/theme/mixin.config.php similarity index 100% rename from theme/mixin.config.php rename to res/theme/mixin.config.php diff --git a/theme/templates/RecordTab/holdingsils.phtml b/res/theme/templates/RecordTab/holdingsils.phtml similarity index 58% rename from theme/templates/RecordTab/holdingsils.phtml rename to res/theme/templates/RecordTab/holdingsils.phtml index a66d794081698067927016208268d308c75bfa8f..f2c07b5af8259daa5c1b0916e8f01c1dcdc630c9 100644 --- a/theme/templates/RecordTab/holdingsils.phtml +++ b/res/theme/templates/RecordTab/holdingsils.phtml @@ -1,19 +1,14 @@ <!-- fid: recordTab - holdingsils --> <? $script = <<<JS $(document).ready(function() { - // var link = document; - // var target = $(link).closest('.record'); - // var recordId = target.find('.hiddenId').val(); - // var recordSource = target.find('.hiddenSource').val(); - // console.log({ - // recordId, recordSource - // }); + var recordId = $('.hiddenId').val(); + var recordSource = $('.hiddenSource').val(); // console.log({id: recordId, source: recordSource}); $.ajax({ dataType: 'json', url: VuFind.path + '/AJAX/JSON?method=getBoss', - method: 'GET'//, - // data: {id: recordId, source: recordSource} + method: 'GET', + data: {id: recordId, source: recordSource} }).done(function(response) { $('.boss').html(response.data.html); }); diff --git a/theme/templates/ajax/boss.phtml b/res/theme/templates/ajax/boss.phtml similarity index 82% rename from theme/templates/ajax/boss.phtml rename to res/theme/templates/ajax/boss.phtml index 3d54ee64503e1fa4eca5821d1051ca38d1752915..ea8cc1e3fc39a233b5cba762f0909610fd6af706 100644 --- a/theme/templates/ajax/boss.phtml +++ b/res/theme/templates/ajax/boss.phtml @@ -1,9 +1,10 @@ <!-- dbis-module: ajax - dbis --> <div> <? if (!empty($this->results)): ?> + <?=print_r($this->results);?> <div class="openurls"> <ul> - <? foreach ($this->results as $result): ?> + <? /*foreach ($this->results as $result): ?> <li> <h3><?=$result['name']?></h3> </li> @@ -13,7 +14,7 @@ <a href="<?=$db[0]->getUrl()?>" target="_blank"><?=$db[0]->getHeadline()?></a> </li> <? endforeach; ?> - <? endforeach; ?> + <? endforeach;*/ ?> </ul> </div> <? endif; ?> diff --git a/src/AjaxHandler/GetBoss.php b/src/AjaxHandler/GetBoss.php index dc86722eaced367d5a071c58bf1679ac92ed9bfb..95809993af86e99394771e9fc21081852fd55bb3 100644 --- a/src/AjaxHandler/GetBoss.php +++ b/src/AjaxHandler/GetBoss.php @@ -20,9 +20,12 @@ */ namespace finc\Boss\AjaxHandler; +use finc\ResolverLibMapper\ResolverLibMapper; use VuFind\ILS\Connection; -use finc\Dbis\Client\Client; +use finc\Boss\Client\Client as BossClient; +use VuFind\Record\Loader; use Zend\Config\Config; +use Zend\Http\PhpEnvironment\Request; use Zend\Mvc\Controller\Plugin\Params; use Zend\View\Renderer\RendererInterface; @@ -46,9 +49,30 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase /** * HTTP Service * - * @var Client + * @var BossClient */ - protected $dbisClient; + protected $bossClient; + + /** + * Request + * + * @var Request + */ + protected $request; + + /** + * Record loader + * + * @var Loader + */ + protected $recordLoader; + + /** + * Resolver Library Mapper + * + * @var ResolverLibMapper + */ + protected $rlm; /** * View renderer @@ -60,20 +84,29 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase /** * Constructor * - * @param Client $dbisClient http client + * @param BossClient $bossClient http client * @param Config $config Top-level configuration * @param Connection $ils ILS connection + * @param Loader $loader VuFind Record Loader + * @param Request $request Request + * @param ResolverLibMapper $rlm Resolver Library Mapper * @param RendererInterface $renderer view */ public function __construct( - Client $dbisClient, + BossClient $bossClient, Config $config, Connection $ils, + Loader $loader, + Request $request, + ResolverLibMapper $rlm, RendererInterface $renderer ) { + $this->bossClient = $bossClient; $this->config = $config; $this->ils = $ils; - $this->dbisClient = $dbisClient; + $this->recordLoader = $loader; + $this->request = $request; + $this->rlm = $rlm; $this->renderer = $renderer; } @@ -86,18 +119,84 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase */ public function handleRequest(Params $params) { - $bibId = 'AAAAA'; - // Stop now if the user does not have valid catalog credentials available: - if (is_array($this->ils)) { - $bibId = isset($patron['homeLibrary']) ? - $this->ils['homeLibrary'] : 'AAAAA'; - } +// if ($patron = $this->ils->patronLogin()) { +// +// // Stop now if the user does not have valid catalog credentials available: +// if ($patron && is_array($patron)) { +// // Obtain user information from ILS: +// $profile = $this->ils->getMyProfile($patron); +// $bibId = isset($profile['homeLibrary']) ? +// $profile['homeLibrary'] : 'AAAAA'; +// $this->rlm->checkLibConfig($bibId); +// } +// } - $results = $this->dbisClient->getDbisList($bibId); + // Sample BibId + $this->rlm->checkLibConfig('UBL'); + + $driver = $this->recordLoader->load( + $params->fromQuery('id'), + $params->fromQuery('source') + ); + $seq = isset($this->config->Search->sequence) ? + $this->config->Search->sequence : []; + $fields = $driver->getRawData(); + $results = false; + foreach ($seq as $data) { + if (isset($fields[$data])) { + $method = $this->config->Search->$data; + $value = $driver->tryMethod($method); + $methodName = "getRequest" . strtoupper($data); + // TODO library network value of configuration + $results = $this->bossClient->$methodName( + $value, $this->rlm->getNetworkValueUpper() + ); + if (!empty($results['data'])) { + break; + } + } + } + // default search of boss + if (empty($results)) { + $author = $driver->tryMethod('getAuthor'); + $title = $driver->tryMethod('getTitle'); + $year = $driver->tryMethod('getYear'); + $this->bossClient->getRequestQuery( + $author, $title, $year, + $this->rlm->getNetworkValueUpper() + ); + } + $isilCallNumber = $this->getISILCallNumber($results); + $network = $this->rlm->getNetworkValueLower(); $view = [ - 'results' => $results + 'isISIL' => $this->isISIL($isilCallNumber['isils'], $this->rlm->getBossValue()), + 'url' => sprintf($this->config->Search->$network, $results['param']) ]; - $html = $this->renderer->render('ajax/dbis.phtml', $view); + $html = $this->renderer->render('ajax/boss.phtml', $view); return $this->formatResponse(compact('html')); } + + private function getISILCallNumber($results) + { + $tmp = []; + $retval = []; + + foreach ($results as $result) { + foreach ($result as $holding) { + $tmp[] = $holding['isil']; + $retval[($holding['isil'])] = isset($holding['callnumber']) ? + $holding['callnumber'] : ''; + } + } + + $retval['isils'] = !empty($tmp) ? $tmp : []; + + return $retval; + } + + private function isISIL($data, $isil) + { + return preg_grep('/'.$isil.'/', $data) ? + true : false; + } } diff --git a/src/AjaxHandler/GetBossFactory.php b/src/AjaxHandler/GetBossFactory.php index 46c31ecd938c9d3b260298ce61def039c2194980..ca289e38dc3ce78683be47df5042dedefcda06a8 100644 --- a/src/AjaxHandler/GetBossFactory.php +++ b/src/AjaxHandler/GetBossFactory.php @@ -20,7 +20,7 @@ */ namespace finc\Boss\AjaxHandler; -use finc\Dbis\Client\Client as DbisClient; +use finc\Boss\Client\Client as BossClient; use Interop\Container\ContainerInterface; use Psr\Http\Client\ClientInterface; @@ -35,14 +35,15 @@ class GetBossFactory */ public function __invoke(ContainerInterface $container) { - if (!empty($options)) { - throw new \Exception('Unexpected options passed to factory.'); - } $httpClient = $container->get(ClientInterface::class); + $config = $container->get('VuFind\Config\PluginManager')->get('boss'); return new GetBoss( - new DbisClient($httpClient), - $container->get('VuFind\Config\PluginManager')->get('config'), + new BossClient($httpClient, $config), + $config, $container->get('VuFind\ILS\Connection'), + $container->get('VuFind\Record\Loader'), + $container->get('Request'), + $container->get('finc\ResolverLibMapper'), $container->get('ViewRenderer') ); } diff --git a/src/Module.php b/src/Module.php index 0baaf631065d8486c6f06641bff6df0a475dc156..580abfe4c889fadc25d5b6dfe9e6188e0ecebc92 100644 --- a/src/Module.php +++ b/src/Module.php @@ -39,7 +39,7 @@ class Module 'plugin_managers' => [ 'ajaxhandler' => [ 'factories' => [ - 'finc\Boss\AjaxHandler\GetBoss' => 'finc\Dbis\AjaxHandler\GetBossFactory' + 'finc\Boss\AjaxHandler\GetBoss' => 'finc\Boss\AjaxHandler\GetBossFactory' ], 'aliases' => [ 'getBoss' => 'finc\Boss\AjaxHandler\GetBoss'