Skip to content
Snippets Groups Projects
Commit d3080df4 authored by Demian Katz's avatar Demian Katz
Browse files

Refactor view option configuration to trait.

parent 44280e63
No related merge requests found
<?php
/**
* Trait for setting up view options. Designed to be included in a subclass of
* \VuFind\Search\Base\Options.
*
* PHP version 5
*
* Copyright (C) Villanova University 2017.
*
* 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 Search
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
namespace VuFind\Search\Options;
/**
* Trait for setting up view options. Designed to be included in a subclass of
* \VuFind\Search\Base\Options.
*
* @category VuFind
* @package Search
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
trait ViewOptionsTrait
{
/**
* Set up the view options.
*
* @param \Zend\Config\Config $searchSettings Search settings.
*
* @return void
*/
public function initViewOptions(\Zend\Config\Config $searchSettings)
{
if (isset($searchSettings->General->default_view)) {
$this->defaultView = $searchSettings->General->default_view;
}
// Load view preferences (or defaults if none in .ini file):
if (isset($searchSettings->Views)) {
foreach ($searchSettings->Views as $key => $value) {
$this->viewOptions[$key] = $value;
}
} elseif (isset($searchSettings->General->default_view)) {
$this->viewOptions = [$this->defaultView => $this->defaultView];
} else {
$this->viewOptions = ['list' => 'List'];
}
}
}
...@@ -38,6 +38,8 @@ namespace VuFind\Search\Solr; ...@@ -38,6 +38,8 @@ namespace VuFind\Search\Solr;
*/ */
class Options extends \VuFind\Search\Base\Options class Options extends \VuFind\Search\Base\Options
{ {
use \VuFind\Search\Options\ViewOptionsTrait;
/** /**
* Available sort options for facets * Available sort options for facets
* *
...@@ -102,9 +104,6 @@ class Options extends \VuFind\Search\Base\Options ...@@ -102,9 +104,6 @@ class Options extends \VuFind\Search\Base\Options
if (isset($searchSettings->RSS->sort)) { if (isset($searchSettings->RSS->sort)) {
$this->rssSort = $searchSettings->RSS->sort; $this->rssSort = $searchSettings->RSS->sort;
} }
if (isset($searchSettings->General->default_view)) {
$this->defaultView = $searchSettings->General->default_view;
}
if (isset($searchSettings->General->default_handler)) { if (isset($searchSettings->General->default_handler)) {
$this->defaultHandler = $searchSettings->General->default_handler; $this->defaultHandler = $searchSettings->General->default_handler;
} }
...@@ -142,16 +141,10 @@ class Options extends \VuFind\Search\Base\Options ...@@ -142,16 +141,10 @@ class Options extends \VuFind\Search\Base\Options
'callnumber-sort' => 'sort_callnumber', 'author' => 'sort_author', 'callnumber-sort' => 'sort_callnumber', 'author' => 'sort_author',
'title' => 'sort_title']; 'title' => 'sort_title'];
} }
// Load view preferences (or defaults if none in .ini file):
if (isset($searchSettings->Views)) { // Set up views
foreach ($searchSettings->Views as $key => $value) { $this->initViewOptions($searchSettings);
$this->viewOptions[$key] = $value;
}
} elseif (isset($searchSettings->General->default_view)) {
$this->viewOptions = [$this->defaultView => $this->defaultView];
} else {
$this->viewOptions = ['list' => 'List'];
}
// Load list view for result (controls AJAX embedding vs. linking) // Load list view for result (controls AJAX embedding vs. linking)
if (isset($searchSettings->List->view)) { if (isset($searchSettings->List->view)) {
$this->listviewOption = $searchSettings->List->view; $this->listviewOption = $searchSettings->List->view;
......
...@@ -38,6 +38,8 @@ namespace VuFind\Search\Summon; ...@@ -38,6 +38,8 @@ namespace VuFind\Search\Summon;
*/ */
class Options extends \VuFind\Search\Base\Options class Options extends \VuFind\Search\Base\Options
{ {
use \VuFind\Search\Options\ViewOptionsTrait;
/** /**
* Maximum number of topic recommendations to show (false for none) * Maximum number of topic recommendations to show (false for none)
* *
...@@ -98,9 +100,6 @@ class Options extends \VuFind\Search\Base\Options ...@@ -98,9 +100,6 @@ class Options extends \VuFind\Search\Base\Options
} }
// Load search preferences: // Load search preferences:
if (isset($searchSettings->General->default_view)) {
$this->defaultView = $searchSettings->General->default_view;
}
if (isset($searchSettings->General->retain_filters_by_default)) { if (isset($searchSettings->General->retain_filters_by_default)) {
$this->retainFiltersByDefault $this->retainFiltersByDefault
= $searchSettings->General->retain_filters_by_default; = $searchSettings->General->retain_filters_by_default;
...@@ -148,16 +147,9 @@ class Options extends \VuFind\Search\Base\Options ...@@ -148,16 +147,9 @@ class Options extends \VuFind\Search\Base\Options
= $searchSettings->General->empty_search_relevance_override; = $searchSettings->General->empty_search_relevance_override;
} }
// Load view preferences (or defaults if none in .ini file): // Set up views
if (isset($searchSettings->Views)) { $this->initViewOptions($searchSettings);
foreach ($searchSettings->Views as $key => $value) {
$this->viewOptions[$key] = $value;
}
} elseif (isset($searchSettings->General->default_view)) {
$this->viewOptions = [$this->defaultView => $this->defaultView];
} else {
$this->viewOptions = ['list' => 'List'];
}
// Load list view for result (controls AJAX embedding vs. linking) // Load list view for result (controls AJAX embedding vs. linking)
if (isset($searchSettings->List->view)) { if (isset($searchSettings->List->view)) {
$this->listviewOption = $searchSettings->List->view; $this->listviewOption = $searchSettings->List->view;
......
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