diff --git a/module/VuFind/src/VuFind/Search/Options/ViewOptionsTrait.php b/module/VuFind/src/VuFind/Search/Options/ViewOptionsTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..5209d711af0b43220df208bceb597b6918c0c3a0 --- /dev/null +++ b/module/VuFind/src/VuFind/Search/Options/ViewOptionsTrait.php @@ -0,0 +1,66 @@ +<?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']; + } + } +} diff --git a/module/VuFind/src/VuFind/Search/Solr/Options.php b/module/VuFind/src/VuFind/Search/Solr/Options.php index 6855645189e91a24835f076624333cd46820ea11..cc5e1311d0117bac31f0a51ae993ccd96dfc51f0 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Options.php +++ b/module/VuFind/src/VuFind/Search/Solr/Options.php @@ -38,6 +38,8 @@ namespace VuFind\Search\Solr; */ class Options extends \VuFind\Search\Base\Options { + use \VuFind\Search\Options\ViewOptionsTrait; + /** * Available sort options for facets * @@ -102,9 +104,6 @@ class Options extends \VuFind\Search\Base\Options if (isset($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)) { $this->defaultHandler = $searchSettings->General->default_handler; } @@ -142,16 +141,10 @@ class Options extends \VuFind\Search\Base\Options 'callnumber-sort' => 'sort_callnumber', 'author' => 'sort_author', 'title' => 'sort_title']; } - // 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']; - } + + // Set up views + $this->initViewOptions($searchSettings); + // Load list view for result (controls AJAX embedding vs. linking) if (isset($searchSettings->List->view)) { $this->listviewOption = $searchSettings->List->view; diff --git a/module/VuFind/src/VuFind/Search/Summon/Options.php b/module/VuFind/src/VuFind/Search/Summon/Options.php index 9b4382871491123c5ce6e991832beed3d8bb61ba..bd1c50eff4376437c2fd60ea64a2419ba09a6dd3 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Options.php +++ b/module/VuFind/src/VuFind/Search/Summon/Options.php @@ -38,6 +38,8 @@ namespace VuFind\Search\Summon; */ class Options extends \VuFind\Search\Base\Options { + use \VuFind\Search\Options\ViewOptionsTrait; + /** * Maximum number of topic recommendations to show (false for none) * @@ -98,9 +100,6 @@ class Options extends \VuFind\Search\Base\Options } // Load search preferences: - if (isset($searchSettings->General->default_view)) { - $this->defaultView = $searchSettings->General->default_view; - } if (isset($searchSettings->General->retain_filters_by_default)) { $this->retainFiltersByDefault = $searchSettings->General->retain_filters_by_default; @@ -148,16 +147,9 @@ class Options extends \VuFind\Search\Base\Options = $searchSettings->General->empty_search_relevance_override; } - // 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']; - } + // Set up views + $this->initViewOptions($searchSettings); + // Load list view for result (controls AJAX embedding vs. linking) if (isset($searchSettings->List->view)) { $this->listviewOption = $searchSettings->List->view;