diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini index 1bb8e427320a4a7086751e6fb1cb6973af3a20e9..ba17886b5a3a1224d95a800c89f425940fd09f84 100644 --- a/local/config/vufind/config.ini +++ b/local/config/vufind/config.ini @@ -1343,7 +1343,7 @@ treeSearchLimit = 100 ; children (default = false). This is an alternative to the full collections support ; (see the [Collections] section), so only one of them should be enabled ; at a time e.g. unless custom record drivers are used. -;simpleContainerLinks = true +simpleContainerLinks = true ; This section will be used to configure the feedback module. ; Set "tab_enabled" to true in order to enable the feedback module. diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 4248962d3e543500888816db5e48ef40696bedf1..46a56a4a33bf9481a68b828cb8e6624b32422af9 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -85,6 +85,21 @@ $config = [ 'redi' => 'finc\Resolver\Driver\Factory::getRedi' ], ], + 'hierarchy_treedataformatter' => [ + 'invokables' => [ + 'json' => 'finc\Hierarchy\TreeDataFormatter\NoCollections', + ], + ], + 'hierarchy_treedatasource' => [ + 'factories' => [ + 'solr' => 'finc\Hierarchy\TreeDataSource\Factory::getSolr', + ], + ], + 'hierarchy_treerenderer' => [ + 'factories' => [ + 'jstree' => 'finc\Hierarchy\TreeRenderer\Factory::getJSTree' + ], + ], ], 'recorddriver_tabs' => [ 'finc\RecordDriver\SolrDefault' => [ diff --git a/module/finc/src/finc/Hierarchy/TreeDataFormatter/NoCollections.php b/module/finc/src/finc/Hierarchy/TreeDataFormatter/NoCollections.php new file mode 100644 index 0000000000000000000000000000000000000000..ba75a1748a945da9bc34b71e63065828da0171bd --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeDataFormatter/NoCollections.php @@ -0,0 +1,46 @@ +<?php +/** + * Hierarchy Tree Data Formatter (JSON) + * + * PHP version 5 + * + * Copyright (C) Villanova University 2015. + * + * 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 HierarchyTree_DataFormatter + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +namespace finc\Hierarchy\TreeDataFormatter; + +/** + * Hierarchy Tree Data Formatter (JSON) + * + * @category VuFind + * @package HierarchyTree_DataFormatter + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +class NoCollections extends \VuFind\Hierarchy\TreeDataFormatter\Json +{ + protected function isCollection($fields) + { + //always return false to ensure Record-Links only + return false; + } +} diff --git a/module/finc/src/finc/Hierarchy/TreeDataSource/Factory.php b/module/finc/src/finc/Hierarchy/TreeDataSource/Factory.php new file mode 100644 index 0000000000000000000000000000000000000000..8ff9aabaf7d9d6081bae5583870adc2bb3df3725 --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeDataSource/Factory.php @@ -0,0 +1,72 @@ +<?php +/** + * Hierarchy Data Source Factory Class + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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 HierarchyTree_DataSource + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +namespace finc\Hierarchy\TreeDataSource; +use Zend\ServiceManager\ServiceManager; + +/** + * Hierarchy Data Source Factory Class + * + * This is identical to the VuFind equivalent ensuring the correct namespace + * to load \de_15\Hierarchy\TreeDataSource\Solr + * + * @category VuFind + * @package HierarchyTree_DataSource + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + * + * @codeCoverageIgnore + */ +class Factory +{ + /** + * Factory for Solr driver. + * + * @param ServiceManager $sm Service manager. + * + * @return Solr + */ + public static function getSolr(ServiceManager $sm) + { + $cacheDir = $sm->getServiceLocator()->get('VuFind\CacheManager') + ->getCacheDir(false); + $hierarchyFilters = $sm->getServiceLocator()->get('VuFind\Config') + ->get('HierarchyDefault'); + $filters = isset($hierarchyFilters->HierarchyTree->filterQueries) + ? $hierarchyFilters->HierarchyTree->filterQueries->toArray() + : []; + $solr = $sm->getServiceLocator()->get('VuFind\Search\BackendManager') + ->get('Solr')->getConnector(); + $formatterManager = $sm->getServiceLocator() + ->get('VuFind\HierarchyTreeDataFormatterPluginManager'); + return new Solr( + $solr, $formatterManager, rtrim($cacheDir, '/') . '/hierarchy', + $filters + ); + } +} diff --git a/module/finc/src/finc/Hierarchy/TreeDataSource/Solr.php b/module/finc/src/finc/Hierarchy/TreeDataSource/Solr.php new file mode 100644 index 0000000000000000000000000000000000000000..819315d867dbe8e82b59e7d1c26005499520536b --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeDataSource/Solr.php @@ -0,0 +1,109 @@ +<?php +/** + * Hierarchy Tree Data Source (Solr) + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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 HierarchyTree_DataSource + * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +namespace finc\Hierarchy\TreeDataSource; +use VuFind\Hierarchy\TreeDataSource\Solr as VuFindBase; +use VuFindSearch\Query\Query; +use VuFindSearch\Backend\Solr\Connector; +use VuFindSearch\ParamBag; +use VuFind\RecordDriver\AbstractBase as RecordDriver; + +/** + * Hierarchy Tree Data Source (Solr) + * + * This extends the base helper class to enable additional configuration of the answer set. + * + * @category VuFind + * @package HierarchyTree_DataSource + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +class Solr extends VuFindBase +{ + /** + * @var RecordDriver + */ + protected $recordDriver; + + /** + * Search Solr. + * + * @param string $q Search query + * @param int $rows Max rows to retrieve (default = int max / 2 since Solr + * may choke with higher values) + * + * @return array + */ + protected function searchSolr($q, $rows = 1073741823) + { + $filters = $this->filters; + if ($this->isTopElementQuery($q) || (isset($this->recordDriver) && $this->recordDriver->isCollection())) { + $filters[] = "format:DigitalCollection"; + } + $params = new ParamBag( + [ + 'q' => [$q], + 'fq' => $filters, + 'hl' => ['false'], + 'fl' => ['title,id,hierarchy_parent_id,hierarchy_top_id,' + . 'is_hierarchy_id,hierarchy_sequence,title_in_hierarchy,recordtype'], + 'wt' => ['json'], + 'json.nl' => ['arrarr'], + 'rows' => [$rows], // Integer max + 'start' => [0] + ] + ); + $response = $this->solrConnector->search($params); + return json_decode($response); + } + + public function setRecordDriver(RecordDriver $recordDriver) { + $this->recordDriver = $recordDriver; + } + + protected function isTopElementQuery($query) { + if (preg_match('/^hierarchy_top_id\:\"?([^\"]+)\"?$/',$query,$matches)) { + $id = $matches[1]; + $params = new ParamBag( + [ + 'q' => ["hierarchy_top_id:\"$id\" AND id:\"$id\" AND format:DigitalCollection"], + 'hl' => ['false'], + 'fl' => ['id'], + 'wt' => ['json'], + 'json.nl' => ['arrarr'], + 'rows' => [1], // Integer max + 'start' => [0] + ] + ); + $response = $this->solrConnector->search($params); + $return = json_decode($response); + return $return->response->numFound != 0; + } + return false; + } +} diff --git a/module/finc/src/finc/Hierarchy/TreeRenderer/Factory.php b/module/finc/src/finc/Hierarchy/TreeRenderer/Factory.php new file mode 100644 index 0000000000000000000000000000000000000000..2e4bf6aa4bf5dfee65a740b60c8fb3d3205134d6 --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeRenderer/Factory.php @@ -0,0 +1,59 @@ +<?php +/** + * Hierarchy Renderer Factory Class + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package HierarchyTree_Renderer + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +namespace finc\Hierarchy\TreeRenderer; +use Zend\ServiceManager\ServiceManager; + +/** + * Hierarchy Renderer Factory Class + * + * This is a factory class to build objects for rendering hierarchies. + * + * @category VuFind + * @package HierarchyTree_DataSource + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + * + * @codeCoverageIgnore + */ +class Factory +{ + /** + * Factory for JSTree renderer. + * + * @param ServiceManager $sm Service manager. + * + * @return JSTree + */ + public static function getJSTree(ServiceManager $sm) + { + return new JSTree( + $sm->getServiceLocator()->get('ControllerPluginManager')->get('Url') + ); + } +} diff --git a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php new file mode 100644 index 0000000000000000000000000000000000000000..36e45a39a81943456cf13f7aa03b8991f9c8788e --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php @@ -0,0 +1,117 @@ +<?php +/** + * Hierarchy Tree Renderer for the JS_Tree plugin + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package HierarchyTree_Renderer + * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +namespace finc\Hierarchy\TreeRenderer; + +/** + * Hierarchy Tree Renderer + * + * This is a helper class for producing hierarchy trees. + * + * @category VuFind + * @package HierarchyTree_Renderer + * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki + */ +class JSTree extends \VuFind\Hierarchy\TreeRenderer\JSTree +{ + /** + * Constructor + * + * @param \Zend\Mvc\Controller\Plugin\Url $router Router plugin for urls + */ + public function __construct(\Zend\Mvc\Controller\Plugin\Url $router) + { + parent::__construct($router); + } + + /** + * Use the router to build the appropriate URL based on context + * + * @param object $node JSON object of a node/top node + * @param string $context Record or Collection + * + * @return string + */ + protected function getContextualUrl($node, $context) + { + if ($node->type == 'collection') { + return $this->getUrlFromRouteCache('collection', $node->id); + } else { + $url = $this->getUrlFromRouteCache('record', $node->id); + return $url; + } + } + + /** + * Get the URL for a record and cache it to avoid the relatively slow routing + * calls. + * + * @param string $route Route + * @param string $id Record ID + * + * @return string URL + */ + protected function getUrlFromRouteCache($route, $id) + { + static $cache = []; + if (!isset($cache[$route])) { + if ($route == 'collection') { + $params = [ + 'id' => '__record_id__', + 'tab' => 'HierarchyTree' + ]; + $options = [ + 'query' => [ + 'recordID' => '__record_id__' + ] + ]; + $cache[$route] = $this->router->fromRoute($route, $params, $options); + } else { + $params = [ + 'id' => '__record_id__', + 'tab' => 'Description' + ]; + $cache[$route] = $this->router->fromRoute($route, $params); + } + } + return str_replace('__record_id__', $id, $cache[$route]); + } + + /** + * @return \VuFind\Hierarchy\TreeDataSource\AbstractBase + */ + public function getDataSource() + { + if (!isset($this->dataSource)) { + $this->dataSource = parent::getDataSource(); + } + $this->dataSource->setRecordDriver($this->recordDriver); + return $this->dataSource; + } +}