Skip to content
Snippets Groups Projects
Commit 0e726052 authored by Demian Katz's avatar Demian Katz Committed by GitHub
Browse files

ContentBlock plugin mechanism (#1170)

- Resolves VUFIND-1241.
parent 8b960d5c
Branches
Tags
No related merge requests found
Showing
with 1005 additions and 56 deletions
...@@ -225,13 +225,20 @@ orFacets = * ...@@ -225,13 +225,20 @@ orFacets = *
; below, no facets will be translated. ; below, no facets will be translated.
translated_facets[] = ContentType translated_facets[] = ContentType
; These facets will be displayed on the Home Page. If this section is omitted, ; This section controls the behavior of the Summon/Home screen.
[HomePage]
; Content blocks can be selected from the list in searches.ini.
content[] = FacetList:Summon
;content[] = Channels:Summon
; These facets will be displayed on the Home Page when FacetList is turned on in
; the content setting of the [HomePage] section above. If this section is omitted,
; the [Advanced_Facets] section will be used instead. ; the [Advanced_Facets] section will be used instead.
[HomePage_Facets] [HomePage_Facets]
Language = "Language" Language = "Language"
ContentType = "Format" ContentType = "Format"
; These settings affect the way the [HomePage] facets are displayed ; These settings affect the way the [HomePage_Facets] are displayed.
; NOTE: To make changes take effect immediately, you may need to clear VuFind's ; NOTE: To make changes take effect immediately, you may need to clear VuFind's
; cache after changing this section. ; cache after changing this section.
[HomePage_Facet_Settings] [HomePage_Facet_Settings]
......
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
; The order of sections in this file will control the display order of search ; The order of sections in this file will control the display order of search
; results on screen. ; results on screen.
; This section controls the behavior of the Combined/Home screen.
[HomePage]
; Content blocks can be selected from the list in searches.ini.
content[] = IlsStatusMonitor
; This section controls how columns will be formatted ; This section controls how columns will be formatted
[Layout] [Layout]
; This is the maximum number of columns to use. ; This is the maximum number of columns to use.
......
...@@ -189,15 +189,16 @@ translated_facets[] = callnumber-first:CallNumberFirst ...@@ -189,15 +189,16 @@ translated_facets[] = callnumber-first:CallNumberFirst
;delimited_facets[] = author_id_str ;delimited_facets[] = author_id_str
;delimited_facets[] = "author_id_str|:::" ;delimited_facets[] = "author_id_str|:::"
; These facets will be displayed on the Home Page. If this section is omitted, ; These facets will be displayed on the Home Page when FacetList is turned on in
; the [Advanced] section will be used instead. ; the content setting of the [HomePage] section of searches.ini. If this section
; is omitted, the [Advanced] section will be used instead.
[HomePage] [HomePage]
callnumber-first = "Call Number" callnumber-first = "Call Number"
language = Language language = Language
format = Format format = Format
;hierarchy_top_title = Collections ;hierarchy_top_title = Collections
; These settings affect the way the [HomePage] facets are displayed ; These settings affect the way the [HomePage] facets are displayed.
; NOTE: To make changes take effect immediately, you may need to clear VuFind's ; NOTE: To make changes take effect immediately, you may need to clear VuFind's
; cache after changing this section. ; cache after changing this section.
[HomePage_Settings] [HomePage_Settings]
......
...@@ -643,3 +643,20 @@ view=full ...@@ -643,3 +643,20 @@ view=full
;params = "qf=title,title_short,callnumber-label,topic,language,author,publishDate mintf=1 mindf=1"; ;params = "qf=title,title_short,callnumber-label,topic,language,author,publishDate mintf=1 mindf=1";
; This setting can be used to limit the maximum number of suggestions. Default is 5. ; This setting can be used to limit the maximum number of suggestions. Default is 5.
;count = 5 ;count = 5
; This section controls the behavior of the Search/Home screen.
[HomePage]
; Content blocks can be selected from the list below:
;
; Channels:[source] - Display the homepage channels for the specified [source].
; [source] defaults to Solr.
;
; FacetList:[source]:[column size] - Display a list of facet values
; drawn from the [source] backend, with a maximum of [column size] values per
; column. [source] defaults to Solr and [column size] defaults to 10.
;
; IlsStatusMonitor:[target] - Performs an AJAX health check of the ILS and
; prepends a warning message to the HTML element identified by the jQuery selector
; provided in [target] (which defaults to .searchHomeContent.
content[] = IlsStatusMonitor
content[] = FacetList
...@@ -302,6 +302,8 @@ $config = [ ...@@ -302,6 +302,8 @@ $config = [
'VuFind\Content\Reviews\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'VuFind\Content\Reviews\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Content\Summaries\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'VuFind\Content\Summaries\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Content\TOC\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'VuFind\Content\TOC\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\ContentBlock\BlockLoader' => 'VuFind\ContentBlock\BlockLoaderFactory',
'VuFind\ContentBlock\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Cookie\CookieManager' => 'VuFind\Cookie\CookieManagerFactory', 'VuFind\Cookie\CookieManager' => 'VuFind\Cookie\CookieManagerFactory',
'VuFind\Cover\Router' => 'VuFind\Cover\RouterFactory', 'VuFind\Cover\Router' => 'VuFind\Cover\RouterFactory',
'VuFind\Crypt\HMAC' => 'VuFind\Crypt\HMACFactory', 'VuFind\Crypt\HMAC' => 'VuFind\Crypt\HMACFactory',
...@@ -475,6 +477,7 @@ $config = [ ...@@ -475,6 +477,7 @@ $config = [
'content_reviews' => [ /* see VuFind\Content\Reviews\PluginManager for defaults */ ], 'content_reviews' => [ /* see VuFind\Content\Reviews\PluginManager for defaults */ ],
'content_summaries' => [ /* see VuFind\Content\Summaries\PluginManager for defaults */ ], 'content_summaries' => [ /* see VuFind\Content\Summaries\PluginManager for defaults */ ],
'content_toc' => [ /* see VuFind\Content\TOC\PluginManager for defaults */ ], 'content_toc' => [ /* see VuFind\Content\TOC\PluginManager for defaults */ ],
'contentblock' => [ /* see VuFind\ContentBlock\PluginManager for defaults */ ],
'db_row' => [ /* see VuFind\Db\Row\PluginManager for defaults */ ], 'db_row' => [ /* see VuFind\Db\Row\PluginManager for defaults */ ],
'db_table' => [ /* see VuFind\Db\Table\PluginManager for defaults */ ], 'db_table' => [ /* see VuFind\Db\Table\PluginManager for defaults */ ],
'hierarchy_driver' => [ /* see VuFind\Hierarchy\Driver\PluginManager for defaults */ ], 'hierarchy_driver' => [ /* see VuFind\Hierarchy\Driver\PluginManager for defaults */ ],
......
<?php
/**
* Abstract base content block.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
/**
* Abstract base content block.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class AbstractBase implements ContentBlockInterface
{
/**
* Configuration
*
* @var string
*/
protected $config = '';
/**
* Store the configuration of the content block.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
$this->config = $settings;
}
/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext()
{
// Expose the block object directly by default.
return ['block' => $this];
}
}
<?php
/**
* Content block loader
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use VuFind\Config\PluginManager as ConfigManager;
use VuFind\ContentBlock\PluginManager as BlockManager;
use VuFind\Search\Base\Options;
use VuFind\Search\Options\PluginManager as OptionsManager;
use Zend\Config\Config;
/**
* Content block plugin manager
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class BlockLoader
{
/**
* Options manager.
*
* @var OptionsManager
*/
protected $optionsManager;
/**
* Config manager.
*
* @var ConfigManager
*/
protected $configManager;
/**
* Block manager.
*
* @var BlockManager
*/
protected $blockManager;
/**
* Constructor
*
* @param OptionsManager $om Options manager
* @param ConfigManager $cm Config manager
* @param BlockManager $bm Block manager
*/
public function __construct(OptionsManager $om, ConfigManager $cm,
BlockManager $bm
) {
$this->optionsManager = $om;
$this->configManager = $cm;
$this->blockManager = $bm;
}
/**
* Fetch blocks using a search class ID.
*
* @param string $searchClassId Search class ID
*
* @return array
*/
public function getFromSearchClassId($searchClassId)
{
$options = $this->optionsManager->get($searchClassId);
return $this->getFromOptions($options);
}
/**
* Fetch blocks using an Options object.
*
* @param Options $options Options object
*
* @return array
*/
public function getFromOptions(Options $options)
{
return $this->getFromConfig($options->getSearchIni());
}
/**
* Fetch blocks using a configuration name
*
* @param string $name Configuration name
* @param string $section Section to load from object
* @param string $setting Setting to load from section
*
* @return array
*/
public function getFromConfig($name, $section = 'HomePage',
$setting = 'content'
) {
$config = $this->configManager->get($name);
return $this->getFromConfigObject($config, $section, $setting);
}
/**
* Fetch blocks using Config object.
*
* @param Config $config Configuration object
* @param string $section Section to load from object
* @param string $setting Setting to load from section
*
* @return array
*/
public function getFromConfigObject(Config $config, $section = 'HomePage',
$setting = 'content'
) {
$blocks = [];
if (isset($config->$section->$setting)) {
foreach ($config->$section->$setting as $current) {
$parts = explode(':', $current, 2);
$block = $this->blockManager->get($parts[0]);
$block->setConfig($parts[1] ?? null);
$blocks[] = $block;
}
}
return $blocks;
}
}
<?php
/**
* BlockLoader factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* BlockLoader factory.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class BlockLoaderFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
return new $requestedName(
$container->get('VuFind\Search\Options\PluginManager'),
$container->get('VuFind\Config\PluginManager'),
$container->get('VuFind\ContentBlock\PluginManager')
);
}
}
<?php
/**
* Channels content block.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use VuFind\ChannelProvider\ChannelLoader;
use Zend\Http\PhpEnvironment\Request;
/**
* Channels content block.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class Channels implements ContentBlockInterface
{
/**
* Request object
*
* @var Request
*/
protected $request;
/**
* Channel loader
*
* @var ChannelLoader
*/
protected $loader;
/**
* Data source (null to use default found in channels.ini)
*
* @var string
*/
protected $source = null;
/**
* Constructor
*
* @param Request $request Request object
* @param ChannelLoader $loader Channel loader
*/
public function __construct(Request $request, ChannelLoader $loader)
{
$this->request = $request;
$this->loader = $loader;
}
/**
* Store the configuration of the content block.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
if (!empty($settings)) {
$this->source = $settings;
}
}
/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext()
{
$activeChannel = $this->request->getQuery()->get('channelProvider');
$token = $this->request->getQuery()->get('channelToken');
return $this->loader->getHomeContext($token, $activeChannel, $this->source);
}
}
<?php
/**
* Channels factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* Channels factory.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class ChannelsFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
return new $requestedName(
$container->get('Request'),
$container->get('VuFind\ChannelProvider\ChannelLoader')
);
}
}
<?php
/**
* Content block interface
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
/**
* Content block interface
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
interface ContentBlockInterface
{
/**
* Store the configuration of the content block.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings);
/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext();
}
<?php
/**
* FacetList content block.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use VuFind\Config\PluginManager as ConfigManager;
use VuFind\Search\FacetCache\PluginManager as FacetCacheManager;
use Zend\Config\Config;
/**
* FacetList content block.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class FacetList implements ContentBlockInterface
{
/**
* Number of values to put in each column of results.
*
* @var int
*/
protected $columnSize = 10;
/**
* Search class ID to use for retrieving facets.
*
* @var string
*/
protected $searchClassId = 'Solr';
/**
* Configuration manager
*
* @var ConfigManager
*/
protected $configManager;
/**
* Facet cache plugin manager
*
* @var FacetCacheManager
*/
protected $facetCacheManager;
/**
* Constructor
*
* @param FacetCacheManager $fcm Facet cache plugin manager
* @param ConfigManager $cm Configuration manager
*/
public function __construct(FacetCacheManager $fcm, ConfigManager $cm)
{
$this->facetCacheManager = $fcm;
$this->configManager = $cm;
}
/**
* Get an array of hierarchical facets
*
* @param Config $facetConfig Facet configuration object.
*
* @return array Facets
*/
protected function getHierarchicalFacets($facetConfig)
{
return isset($facetConfig->SpecialFacets->hierarchical)
? $facetConfig->SpecialFacets->hierarchical->toArray()
: [];
}
/**
* Get hierarchical facet sort settings
*
* @param Config $facetConfig Facet configuration object.
*
* @return array Array of sort settings keyed by facet
*/
protected function getHierarchicalFacetSortSettings($facetConfig)
{
return isset($facetConfig->SpecialFacets->hierarchicalFacetSortOptions)
? $facetConfig->SpecialFacets->hierarchicalFacetSortOptions->toArray()
: [];
}
/**
* Store the configuration of the content block.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
$parts = explode(':', $settings);
$this->searchClassId = empty($parts[0]) ? $this->searchClassId : $parts[0];
$this->columnSize = $parts[1] ?? $this->columnSize;
}
/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext()
{
$facetCache = $this->facetCacheManager->get($this->searchClassId);
$results = $facetCache->getResults();
$facetConfig = $this->configManager
->get($results->getOptions()->getFacetsIni());
return [
'searchClassId' => $this->searchClassId,
'columnSize' => $this->columnSize,
'facetList' => $facetCache->getList('HomePage'),
'hierarchicalFacets' => $this->getHierarchicalFacets($facetConfig),
'hierarchicalFacetSortOptions' =>
$this->getHierarchicalFacetSortSettings($facetConfig),
'results' => $results,
];
}
}
<?php
/**
* FacetList content block factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* FacetList content block factory.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class FacetListFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$fcpm = $container->get('VuFind\Search\FacetCache\PluginManager');
$cm = $container->get('VuFind\Config\PluginManager');
return new $requestedName($fcpm, $cm);
}
}
<?php
/**
* ILS status monitor content block.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
/**
* Abstract base content block.
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class IlsStatusMonitor implements ContentBlockInterface
{
/**
* Target selector for status message.
*
* @var string
*/
protected $target = '.searchHomeContent';
/**
* Store the configuration of the content block.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
$this->target = empty($settings) ? $this->target : $settings;
}
/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext()
{
// Expose the block object directly by default.
return ['target' => $this->target];
}
}
<?php
/**
* Content block plugin manager
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 ContentBlock
* @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:recommendation_modules Wiki
*/
namespace VuFind\ContentBlock;
/**
* Content block plugin manager
*
* @category VuFind
* @package ContentBlock
* @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:recommendation_modules Wiki
*/
class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
{
/**
* Default plugin aliases.
*
* @var array
*/
protected $aliases = [
'channels' => 'VuFind\ContentBlock\Channels',
'facetlist' => 'VuFind\ContentBlock\FacetList',
'ilsstatusmonitor' => 'VuFind\ContentBlock\IlsStatusMonitor',
];
/**
* Default plugin factories.
*
* @var array
*/
protected $factories = [
'VuFind\ContentBlock\Channels' => 'VuFind\ContentBlock\ChannelsFactory',
'VuFind\ContentBlock\FacetList' => 'VuFind\ContentBlock\FacetListFactory',
'VuFind\ContentBlock\IlsStatusMonitor' =>
'Zend\ServiceManager\Factory\InvokableFactory',
];
/**
* Constructor
*
* Make sure plugins are properly initialized.
*
* @param mixed $configOrContainerInstance Configuration or container instance
* @param array $v3config If $configOrContainerInstance is a
* container, this value will be passed to the parent constructor.
*/
public function __construct($configOrContainerInstance = null,
array $v3config = []
) {
// These objects are not meant to be shared -- every time we retrieve one,
// we are building a brand new object.
$this->sharedByDefault = false;
parent::__construct($configOrContainerInstance, $v3config);
}
/**
* Return the name of the base class or interface that plug-ins must conform
* to.
*
* @return string
*/
protected function getExpectedInterface()
{
return 'VuFind\ContentBlock\ContentBlockInterface';
}
}
...@@ -249,7 +249,9 @@ class AbstractSearch extends AbstractBase ...@@ -249,7 +249,9 @@ class AbstractSearch extends AbstractBase
*/ */
public function homeAction() public function homeAction()
{ {
return $this->createViewModel(); $blocks = $this->serviceLocator->get('VuFind\ContentBlock\BlockLoader')
->getFromSearchClassId($this->searchClassId);
return $this->createViewModel(compact('blocks'));
} }
/** /**
......
...@@ -53,6 +53,20 @@ class CombinedController extends AbstractSearch ...@@ -53,6 +53,20 @@ class CombinedController extends AbstractSearch
parent::__construct($sm); parent::__construct($sm);
} }
/**
* Home action
*
* @return mixed
*/
public function homeAction()
{
// We need to load blocks differently in this controller since it
// doesn't follow the usual configuration pattern.
$blocks = $this->serviceLocator->get('VuFind\ContentBlock\BlockLoader')
->getFromConfig('combined');
return $this->createViewModel(compact('blocks'));
}
/** /**
* Single result action (used for AJAX) * Single result action (used for AJAX)
* *
...@@ -304,6 +318,7 @@ class CombinedController extends AbstractSearch ...@@ -304,6 +318,7 @@ class CombinedController extends AbstractSearch
protected function getTabConfig($config) protected function getTabConfig($config)
{ {
// Strip out non-tab sections of the configuration: // Strip out non-tab sections of the configuration:
unset($config['HomePage']);
unset($config['Layout']); unset($config['Layout']);
unset($config['RecommendationModules']); unset($config['RecommendationModules']);
......
...@@ -262,26 +262,6 @@ class SearchController extends AbstractSearch ...@@ -262,26 +262,6 @@ class SearchController extends AbstractSearch
return $this->createViewModel($lastSearches); return $this->createViewModel($lastSearches);
} }
/**
* Home action
*
* @return mixed
*/
public function homeAction()
{
$facetCache = $this->serviceLocator
->get('VuFind\Search\FacetCache\PluginManager')->get('Solr');
return $this->createViewModel(
[
'results' => $facetCache->getResults(),
'facetList' => $facetCache->getList('HomePage'),
'hierarchicalFacets' => $this->getHierarchicalFacets(),
'hierarchicalFacetSortOptions'
=> $this->getHierarchicalFacetSortSettings()
]
);
}
/** /**
* New item search form * New item search form
* *
...@@ -597,17 +577,4 @@ class SearchController extends AbstractSearch ...@@ -597,17 +577,4 @@ class SearchController extends AbstractSearch
? $facetConfig->SpecialFacets->hierarchical->toArray() ? $facetConfig->SpecialFacets->hierarchical->toArray()
: []; : [];
} }
/**
* Get hierarchical facet sort settings
*
* @return array Array of sort settings keyed by facet
*/
protected function getHierarchicalFacetSortSettings()
{
$facetConfig = $this->getConfig('facets');
return isset($facetConfig->SpecialFacets->hierarchicalFacetSortOptions)
? $facetConfig->SpecialFacets->hierarchicalFacetSortOptions->toArray()
: [];
}
} }
...@@ -123,23 +123,6 @@ class SummonController extends AbstractSearch ...@@ -123,23 +123,6 @@ class SummonController extends AbstractSearch
return $view; return $view;
} }
/**
* Home action
*
* @return mixed
*/
public function homeAction()
{
$facetCache = $this->serviceLocator
->get('VuFind\Search\FacetCache\PluginManager')->get('Summon');
return $this->createViewModel(
[
'results' => $facetCache->getResults(),
'facetList' => $facetCache->getList('HomePage'),
]
);
}
/** /**
* Search action -- call standard results action * Search action -- call standard results action
* *
......
<?php
/**
* ContentBlock view helper
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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 View_Helpers
* @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 Wiki
*/
namespace VuFind\View\Helper\Root;
/**
* ContentBlock view helper
*
* @category VuFind
* @package View_Helpers
* @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 Wiki
*/
class ContentBlock extends AbstractClassBasedTemplateRenderer
{
/**
* Render the output of a ContentBlock plugin.
*
* @param \VuFind\ContentBlock\ContentBlockInterface $block The ContentBlock
* object to render
*
* @return string
*/
public function __invoke($block)
{
$template = 'ContentBlock/%s.phtml';
$className = get_class($block);
$context = $block->getContext();
return $this->renderClassTemplate($template, $className, $context);
}
}
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