Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visibility of Recent Document, Document Types and Years in Browsing configurable #1129

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions application/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ plugins.export.publist.stylesheetDirectory = 'publist'
; BROWSING SETTINGS
browsing.disableEmptyCollections = 1
browsing.series.sortByTitle = 0
browsing.showLatestDocuments = 1
browsing.showDocumentTypes = 1
browsing.showYears = 1

; SERIES SETTINGS
; If series.sortByTitle is enabled (1) the sort_order will be ignored and series
Expand Down
34 changes: 34 additions & 0 deletions modules/solrsearch/controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,33 @@ public function indexAction()
$collectionRoles = new Solrsearch_Model_CollectionRoles();
$this->view->collectionRoles = $collectionRoles->getAllVisible();
$this->view->showSeriesBrowsing = $this->seriesUtil->hasDisplayableSeries();

$config = $this->getConfig();

if (isset($config->browsing->showLatestDocuments)) {
$this->view->showLatestDocuments = filter_var($config->browsing->showLatestDocuments, FILTER_VALIDATE_BOOLEAN);
}
if (isset($config->browsing->showDocumentTypes)) {
$this->view->showDocumentTypes = filter_var($config->browsing->showDocumentTypes, FILTER_VALIDATE_BOOLEAN);
}
if (isset($config->browsing->showYears)) {
$this->view->showYears = filter_var($config->browsing->showYears, FILTER_VALIDATE_BOOLEAN);
}
}

public function doctypesAction()
{
$config = $this->getConfig();

if (
isset($config->browsing->showDocumentTypes) &&
! filter_var($config->browsing->showDocumentTypes, FILTER_VALIDATE_BOOLEAN)
) {
$this->_helper->Redirector->redirectTo(
'index'
);
}

$facetname = 'doctype';
$query = new Opus\Search\Util\Query(Opus\Search\Util\Query::FACET_ONLY);
$query->setFacetField($facetname);
Expand All @@ -83,6 +106,17 @@ public function doctypesAction()

public function yearsAction()
{
$config = $this->getConfig();

if (
isset($config->browsing->showYears) &&
! filter_var($config->browsing->showYears, FILTER_VALIDATE_BOOLEAN)
) {
$this->_helper->Redirector->redirectTo(
'index'
);
}

$facetname = 'year';

$query = new Opus\Search\Util\Query(Opus\Search\Util\Query::FACET_ONLY);
Expand Down
6 changes: 6 additions & 0 deletions modules/solrsearch/views/scripts/browse/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@

<div class="content">
<ul class="nav browsing">
<?PHP if ($this->showLatestDocuments) : ?>
<li>
<a href="<?= $this->url(['module' => 'solrsearch', 'controller' => 'index', 'action' => 'search', 'searchtype' => 'latest'], null, true) ?>"><?= htmlspecialchars($this->translate('latest_documents_title')) ?></a>&nbsp;
<a href="<?= $this->url(['module' => 'rss', 'controller' => 'index', 'action' => 'index'], null, true) ?>" class="rss" type="application/rss+xml">
<img src="<?= $this->layoutPath() ?>/img/feed_small.png" width="12" height="12" alt="<?= $this->translate('rss_icon') ?>" title="<?= $this->translate('rss_title') ?>" />
</a>
</li>
<?PHP endif ?>
<?PHP if ($this->showDocumentTypes) : ?>
<li>
<a href="<?= $this->url(['module' => 'solrsearch', 'controller' => 'browse', 'action' => 'doctypes'], null, true) ?>"><?= htmlspecialchars($this->translate('search_index_doctype_browsing')) ?></a>
</li>
<?PHP endif ?>
<?PHP if ($this->showYears) : ?>
<li>
<a href="<?= $this->url(['module' => 'solrsearch', 'controller' => 'browse', 'action' => 'years'], null, true) ?>"><?= htmlspecialchars($this->translate('search_index_year_browsing')) ?></a>
</li>
<?PHP endif ?>
<?php if ($this->showSeriesBrowsing) : ?>
<li>
<a href="<?= $this->url(['module' => 'solrsearch', 'controller' => 'browse', 'action' => 'series'], null, true) ?>"><?= htmlspecialchars($this->translate('search_index_series_browsing')) ?></a>
Expand Down
77 changes: 74 additions & 3 deletions tests/modules/solrsearch/controllers/BrowseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,42 @@ public function testIndexAction()
{
$this->dispatch('/solrsearch/browse');
$this->assertResponseCode(200);

$this->assertXpath('//a[contains(@href, "solrsearch/index/search/searchtype/latest")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/doctypes")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/years")]');
}

public function testDoctypesAction()
public function testShowDoctypesDisabled()
{
$this->adjustConfiguration([
'browsing' => ['showDocumentTypes' => 0],
]);

$this->dispatch('/solrsearch/browse');
$this->assertResponseCode(200);

$this->assertXpath('//a[contains(@href, "solrsearch/index/search/searchtype/latest")]');
$this->assertNotXpath('//a[contains(@href, "solrsearch/browse/doctypes")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/years")]');
}

public function testDoctypesActionEnabled()
{
$this->dispatch('/solrsearch/browse/doctypes');
$this->assertResponseCode(200);

$this->assertXpath('//div[@id = "content" and contains(@class, "solrsearch_browse_doctypes")]');
}

public function testDoctypesActionDisabled()
{
$this->adjustConfiguration([
'browsing' => ['showDocumentTypes' => 0],
]);

$this->dispatch('/solrsearch/browse/doctypes');
$this->assertRedirect('/solrsearch/browse/index');
}

public function testSeriesAction()
Expand Down Expand Up @@ -278,13 +308,54 @@ public function testUnavailableServiceReturnsHttpCode503()
$this->assertResponseCode(503);
}

public function testBrowsingByYear()
public function testYearsActionEnabled()
{
$this->markTestIncomplete();
$this->dispatch('/solrsearch/browse/years');
$this->assertResponseCode(200);

$this->assertXpath('//div[@id = "content" and contains(@class, "solrsearch_browse_years")]');
}

public function testYearsActionDisabled()
{
$this->adjustConfiguration([
'browsing' => ['showYears' => 0],
]);

$this->dispatch('/solrsearch/browse/years');
$this->assertRedirect('/solrsearch/browse/index');
}

public function testBrowsingByYearWithInvertedYearFacetConfigured()
{
$this->markTestIncomplete();
}

public function testShowYearsDisabled()
{
$this->adjustConfiguration([
'browsing' => ['showYears' => 0],
]);

$this->dispatch('/solrsearch/browse');
$this->assertResponseCode(200);

$this->assertXpath('//a[contains(@href, "solrsearch/index/search/searchtype/latest")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/doctypes")]');
$this->assertNotXpath('//a[contains(@href, "solrsearch/browse/years")]');
}

public function testShowLatestDocumentsDisabled()
{
$this->adjustConfiguration([
'browsing' => ['showLatestDocuments' => 0],
]);

$this->dispatch('/solrsearch/browse');
$this->assertResponseCode(200);

$this->assertNotXpath('//a[contains(@href, "solrsearch/index/search/searchtype/latest")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/doctypes")]');
$this->assertXpath('//a[contains(@href, "solrsearch/browse/years")]');
}
}