-
Notifications
You must be signed in to change notification settings - Fork 9
/
LuceneFacetsBlockPlugin.inc.php
179 lines (149 loc) · 3.67 KB
/
LuceneFacetsBlockPlugin.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* @file LuceneFacetsBlockPlugin.inc.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class LuceneFacetsBlockPlugin
* @ingroup plugins_generic_lucene
*
* @brief Lucene plugin, faceting block component
*/
import('lib.pkp.classes.plugins.BlockPlugin');
class LuceneFacetsBlockPlugin extends BlockPlugin {
/** @var LucenePlugin */
var $_lucenePlugin;
/**
* Constructor
* @param $lucenePlugin string
*/
function __construct($lucenePlugin) {
$this->_lucenePlugin = $lucenePlugin;
parent::__construct();
}
//
// Implement template methods from Plugin.
//
/**
* @see Plugin::getHideManagement()
*/
function getHideManagement() {
return true;
}
/**
* @see Plugin::getName()
*/
function getName() {
return 'LuceneFacetsBlockPlugin';
}
/**
* @see Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.lucene.faceting.facetBlockTitle');
}
/**
* @see Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.lucene.description');
}
/**
* @see Plugin::getPluginPath()
*/
function getPluginPath() {
$plugin = $this->_getLucenePlugin();
return $plugin->getPluginPath();
}
/**
* @copydoc PKPPlugin::getTemplatePath
*/
function getTemplatePath($inCore = false) {
$plugin = $this->_getLucenePlugin();
return $plugin->getTemplatePath($inCore);
}
/**
* @copydoc BlockPlugin::getSeq()
*/
function getSeq($contextId = null) {
// Identify the position of the faceting block.
$seq = parent::getSeq($contextId);
// If nothing has been configured then use the first
// position. This is ok as we'll only display facets
// in a search results context where they have a high
// relevance by default.
if (!is_numeric($seq)) $seq = 0;
return $seq;
}
//
// Implement template methods from LazyLoadPlugin
//
/**
* @copydoc LazyLoadPlugin::getEnabled()
*/
function getEnabled($contextId = null) {
$plugin = $this->_getLucenePlugin();
return $plugin->getEnabled($contextId);
}
//
// Implement template methods from BlockPlugin
//
/**
* @see BlockPlugin::getBlockContext()
*/
function getBlockContext($contextId = NULL) {
$blockContext = parent::getBlockContext($contextId);
// Place the block on the left by default
// where navigation will usually be expected
// by the user.
if (!in_array($blockContext, $this->getSupportedContexts())) {
$blockContext = BLOCK_CONTEXT_SIDEBAR;
}
return $blockContext;
}
/**
* @see BlockPlugin::getBlockTemplateFilename()
*/
function getBlockTemplateFilename() {
// Return the facets template.
return 'facetsBlock.tpl';
}
/**
* @see BlockPlugin::getContents()
*/
function getContents($templateMgr, $request = null) {
// Get facets from the parent plug-in.
$plugin = $this->_getLucenePlugin();
$facets = $plugin->getFacets();
// Check whether we got any facets to display.
$hasFacets = false;
if (is_array($facets)) {
foreach($facets as $facetCategory => $facetList) {
if (count($facetList) > 0) {
$hasFacets = true;
break;
}
}
}
// Do not display the block if we got no facets.
if (!$hasFacets) return '';
$templateMgr->assign('facets', $facets);
$templateMgr->addJavaScript(
'luceneAccordion',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/LuceneAccordion.js'
);
return parent::getContents($templateMgr, $request);
}
//
// Private helper methods
//
/**
* Get the lucene plugin object
* @return LucenePlugin
*/
function _getLucenePlugin() {
return $this->_lucenePlugin;
}
}