Skip to content

Commit

Permalink
Add record tab for displaying channels. (#4165)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Jan 27, 2025
1 parent 6311aa5 commit e186d90
Show file tree
Hide file tree
Showing 13 changed files with 583 additions and 69 deletions.
5 changes: 5 additions & 0 deletions config/vufind/RecordTabs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tabs[HierarchyTree] = HierarchyTree
tabs[Map] = Map
tabs[Versions] = Versions
tabs[Similar] = SimilarItemsCarousel
;tabs[Channels] = Channels
tabs[Details] = StaffViewArray
defaultTab = null
;backgroundLoadedTabs[] = UserComments
Expand All @@ -86,6 +87,7 @@ tabs[HierarchyTree] = HierarchyTree
tabs[Map] = Map
tabs[Versions] = Versions
tabs[Similar] = SimilarItemsCarousel
;tabs[Channels] = Channels
tabs[Details] = StaffViewArray
defaultTab = null
;backgroundLoadedTabs[] = UserComments
Expand All @@ -106,6 +108,7 @@ tabs[HierarchyTree] = HierarchyTree
tabs[Map] = Map
tabs[Versions] = Versions
tabs[Similar] = SimilarItemsCarousel
;tabs[Channels] = Channels
tabs[Details] = StaffViewMARC
defaultTab = null

Expand All @@ -120,6 +123,7 @@ tabs[Preview] = preview
tabs[HierarchyTree] = HierarchyTree
tabs[Versions] = Versions
tabs[Similar] = SimilarItemsCarousel
;tabs[Channels] = Channels
tabs[Details] = StaffViewOverdrive
defaultTab = null

Expand All @@ -130,6 +134,7 @@ tabs[UserComments] = UserComments
tabs[Reviews] = Reviews
tabs[Excerpt] = Excerpt
tabs[Preview] = preview
;tabs[Channels] = Channels
tabs[Details] = StaffViewArray
defaultTab = null

Expand Down
10 changes: 10 additions & 0 deletions config/vufind/channels.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ default_home_source = "Solr"
; Should we cache channel results on the Channels/Home screen?
cache_home_channels = true

; This section controls behavior of the Channels record tab.
[RecordTab]
; What text should display in the tab itself?
label = "Channels"

; This section controls which providers are used for Solr searches/records.
; Providers may be followed by a colon and the name of a configuration section
; to use. If no configuration section is provided, the default of
Expand Down Expand Up @@ -64,6 +69,11 @@ home[] = "facets:provider.facets.home"
record[] = "similaritems"
record[] = "facets"
;record[] = "alphabrowse"
; Providers to use in the Channels tab on the record page when it is enabled.
; The code will fall back to record settings above if recordTab is empty/omitted.
;recordTab[] = "similaritems"
;recordTab[] = "facets"
;recordTab[] = "alphabrowse"
; Providers to use for search-based channels (order matters!)
search[] = "facets"
search[] = "similaritems"
Expand Down
1 change: 1 addition & 0 deletions languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ channel_expand = "Explore related channels"
channel_explore = "Explore Channels"
channel_search = "Show items as search results"
channel_searchbox_label = "Search for more channels:"
Channels = "Channels"
Check Hold = "Check Hold"
Check Recall = "Check Recall"
check_profile = "Check user information."
Expand Down
94 changes: 27 additions & 67 deletions module/VuFind/src/VuFind/ChannelProvider/ChannelLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,72 +49,24 @@
*/
class ChannelLoader
{
/**
* Cache manager
*
* @var CacheManager
*/
protected $cacheManager;

/**
* Channel manager
*
* @var ChannelManager
*/
protected $channelManager;

/**
* Channel configuration
*
* @var Config
*/
protected $config;

/**
* Record loader
*
* @var RecordLoader
*/
protected $recordLoader;

/**
* Search runner
*
* @var SearchRunner
*/
protected $searchRunner;

/**
* Current locale (used for caching)
*
* @var string
*/
protected $locale;

/**
* Constructor
*
* @param Config $config Channels configuration
* @param CacheManager $cache Cache manager
* @param ChannelManager $cm Channel manager
* @param SearchRunner $runner Search runner
* @param RecordLoader $loader Record loader
* @param string $locale Current locale (used for caching)
* @param Config $config Channels configuration
* @param CacheManager $cacheManager Cache manager
* @param ChannelManager $channelManager Channel manager
* @param SearchRunner $searchRunner Search runner
* @param RecordLoader $recordLoader Record loader
* @param string $locale Current locale (used for caching)
*/
public function __construct(
Config $config,
CacheManager $cache,
ChannelManager $cm,
SearchRunner $runner,
RecordLoader $loader,
string $locale = ''
protected Config $config,
protected CacheManager $cacheManager,
protected ChannelManager $channelManager,
protected SearchRunner $searchRunner,
protected RecordLoader $recordLoader,
protected string $locale = ''
) {
$this->config = $config;
$this->cacheManager = $cache;
$this->channelManager = $cm;
$this->searchRunner = $runner;
$this->recordLoader = $loader;
$this->locale = $locale;
}

/**
Expand Down Expand Up @@ -165,7 +117,7 @@ protected function getChannelsFromResults($providers, Results $results, $token)
* if the channelProvider GET parameter is set).
*
* @param string $source Search backend ID
* @param array $configSection Configuration section to load ID list from
* @param string $configSection Configuration section to load ID list from
* @param string $activeId Currently selected channel ID (if any; used
* when making an AJAX request for a single additional channel)
*
Expand Down Expand Up @@ -262,24 +214,32 @@ public function getHomeContext(
/**
* Generates channels for a record.
*
* @param string $recordId Record ID to load
* @param string $token Channel token (optional, used for AJAX fetching)
* @param string $activeChannel Channel being requested (optional, used w/ token)
* @param string $source Search backend to use
* @param string $recordId Record ID to load
* @param string $token Channel token (optional, used for AJAX fetching)
* @param string $activeChannel Channel being requested (optional, used w/ token)
* @param string $source Search backend to use
* @param array $configSections Prioritized list of configuration sections to check
*
* @return array
*/
public function getRecordContext(
$recordId,
$token = null,
$activeChannel = null,
$source = DEFAULT_SEARCH_BACKEND
$source = DEFAULT_SEARCH_BACKEND,
array $configSections = ['record']
) {
// Load record:
$driver = $this->recordLoader->load($recordId, $source);

// Load appropriate channel objects:
$providers = $this->getChannelProviders($source, 'record', $activeChannel);
$providers = [];
foreach ($configSections as $section) {
$providers = $this->getChannelProviders($source, $section, $activeChannel);
if (!empty($providers)) {
break;
}
}

// Collect details:
$channels = [];
Expand Down
102 changes: 102 additions & 0 deletions module/VuFind/src/VuFind/RecordTab/Channels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* Channels tab
*
* PHP version 8
*
* Copyright (C) Villanova University 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 RecordTabs
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_tabs Wiki
*/

namespace VuFind\RecordTab;

use VuFind\ChannelProvider\ChannelLoader;

/**
* Channels tab
*
* @category VuFind
* @package RecordTabs
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_tabs Wiki
*/
class Channels extends AbstractBase
{
/**
* Config sections in channels.ini to use for loading channel settings.
*
* @var array
*/
protected array $configSections = ['recordTab', 'record'];

/**
* Constructor
*
* @param ChannelLoader $loader Channel loader
* @param array $options Config settings
*/
public function __construct(protected ChannelLoader $loader, protected array $options = [])
{
}

/**
* Get the on-screen description for this tab.
*
* @return string
*/
public function getDescription()
{
return $this->options['label'] ?? 'Channels';
}

/**
* Can this tab be loaded via AJAX?
*
* @return bool
*/
public function supportsAjax()
{
// Due to heavy Javascript in channels, the tab cannot be AJAX-loaded:
return false;
}

/**
* Return context variables used for rendering the block's template.
*
* @return array
*/
public function getContext()
{
$request = $this->getRequest() ?: null;
$query = $request?->getQuery();
$driver = $this->getRecordDriver();
$context = ['displaySearchBox' => false];
return $context + $this->loader->getRecordContext(
$driver->getUniqueID(),
$query?->get('channelToken'),
$query?->get('channelProvider'),
$driver->getSearchBackendIdentifier(),
$this->configSections
);
}
}
76 changes: 76 additions & 0 deletions module/VuFind/src/VuFind/RecordTab/ChannelsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Factory for building the Channels tab.
*
* PHP version 8
*
* Copyright (C) Villanova University 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 RecordTabs
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/

namespace VuFind\RecordTab;

use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerExceptionInterface as ContainerException;
use Psr\Container\ContainerInterface;
use VuFind\ChannelProvider\ChannelLoader;

/**
* Factory for building the Channels tab.
*
* @category VuFind
* @package RecordTabs
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class ChannelsFactory implements \Laminas\ServiceManager\Factory\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&\Throwable if any other error occurs
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(
ContainerInterface $container,
$requestedName,
?array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$config = $container->get(\VuFind\Config\PluginManager::class)->get('channels')->toArray();
return new $requestedName($container->get(ChannelLoader::class), $config['RecordTab'] ?? []);
}
}
Loading

0 comments on commit e186d90

Please sign in to comment.