Merge lp:~henrik-lochmann/goobi-presentation/bug-855608 into lp:~slub.team/goobi-presentation/old-bzr-trunk

Proposed by Henrik Lochmann
Status: Merged
Approved by: Sebastian Meyer
Approved revision: 102
Merged at revision: 119
Proposed branch: lp:~henrik-lochmann/goobi-presentation/bug-855608
Merge into: lp:~slub.team/goobi-presentation/old-bzr-trunk
Diff against target: 441 lines (+323/-5) (has conflicts)
8 files modified
dlf/common/class.tx_dlf_indexing.php (+44/-0)
dlf/hooks/class.tx_dlf_tceforms.php (+45/-0)
dlf/plugins/pageview/class.tx_dlf_pageview.php (+3/-2)
dlf/plugins/search/class.tx_dlf_search.php (+120/-2)
dlf/plugins/search/flexform.xml (+35/-0)
dlf/plugins/search/locallang.xml (+16/-0)
dlf/plugins/search/setup.txt (+10/-1)
dlf/plugins/search/tx_dlf_search_extended.js (+50/-0)
Text conflict in dlf/plugins/search/flexform.xml
Text conflict in dlf/plugins/search/locallang.xml
To merge this branch: bzr merge lp:~henrik-lochmann/goobi-presentation/bug-855608
Reviewer Review Type Date Requested Status
Sebastian Meyer Approve
Review via email: mp+123280@code.launchpad.net

Description of the change

- implementation of advanced search feature (Bug #855608)

To post a comment you must log in.
101. By Henrik Lochmann

- code comments and t3jquery dependency

102. By Henrik Lochmann

- trunk fix
- jquery loading improved

Revision history for this message
Sebastian Meyer (sebastian-meyer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dlf/common/class.tx_dlf_indexing.php'
2--- dlf/common/class.tx_dlf_indexing.php 2012-09-07 10:55:51 +0000
3+++ dlf/common/class.tx_dlf_indexing.php 2012-09-07 14:53:18 +0000
4@@ -358,6 +358,50 @@
5 }
6
7 /**
8+ * Returns the dynamic index field title for the given index metadata.
9+ *
10+ * @param string $index_name the "index_name" to request the index field title
11+ *
12+ * @return string the index field title for the passed "index_name"
13+ */
14+ public static function getIndexField($pid, $core = 0, $index_name) {
15+
16+ if (empty($index_name)) {
17+
18+ return $index_name;
19+
20+ }
21+
22+ if (!self::solrConnect($core, $pid)) {
23+
24+ if (TYPO3_DLOG) {
25+
26+ t3lib_div::devLog('[tx_dlf_indexing->getIndexField(] Could not connect to Apache Solr server', $this->extKey, SYSLOG_SEVERITY_ERROR);
27+
28+ return $index_name;
29+
30+ }
31+
32+ }
33+
34+
35+ if (substr($index_name, -8) !== '_sorting') {
36+
37+ $suffix = (in_array($index_name, self::$fields['tokenized']) ? 't' : 'u');
38+
39+ $suffix .= (in_array($index_name, self::$fields['stored']) ? 's' : 'u');
40+
41+ $suffix .= (in_array($index_name, self::$fields['indexed']) ? 'i' : 'u');
42+
43+ $index_name .= '_'.$suffix;
44+
45+ }
46+
47+ return $index_name;
48+
49+ }
50+
51+ /**
52 * Load indexing configuration
53 *
54 * @access protected
55
56=== modified file 'dlf/common/class.tx_dlf_solr.php'
57=== modified file 'dlf/hooks/class.tx_dlf_tceforms.php'
58--- dlf/hooks/class.tx_dlf_tceforms.php 2012-08-22 19:22:29 +0000
59+++ dlf/hooks/class.tx_dlf_tceforms.php 2012-09-07 14:53:18 +0000
60@@ -91,6 +91,51 @@
61 }
62
63 }
64+
65+ public function itemsProcFunc_extendedSearchList(&$params, &$pObj) {
66+
67+ if ($params['row']['pi_flexform']) {
68+
69+ $pi_flexform = t3lib_div::xml2array($params['row']['pi_flexform']);
70+
71+ $pages = $pi_flexform['data']['sDEF']['lDEF']['pages']['vDEF'];
72+
73+ // There is a strange behavior where the uid from the flexform is prepended by the table's name and appended by its title.
74+ // i.e. instead of "18" it reads "pages_18|Title"
75+ if (!t3lib_div::testInt($pages)) {
76+
77+ $_parts = explode('|', $pages);
78+
79+ $pages = array_pop(explode('_', $_parts[0]));
80+
81+ }
82+
83+ if ($pages > 0) {
84+
85+ $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
86+ 'label,index_name',
87+ 'tx_dlf_metadata',
88+ 'indexed=1 AND pid='.intval($pages).' AND (sys_language_uid IN (-1,0) OR l18n_parent=0)'.tx_dlf_helper::whereClause('tx_dlf_metadata'),
89+ '',
90+ 'sorting',
91+ ''
92+ );
93+
94+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
95+
96+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_row($result)) {
97+
98+ $params['items'][] = $resArray;
99+
100+ }
101+
102+ }
103+
104+ }
105+
106+ }
107+
108+ }
109
110 /**
111 * Helper to get flexform's items array for plugin "tx_dlf_search"
112
113=== modified file 'dlf/plugins/pageview/class.tx_dlf_pageview.php'
114--- dlf/plugins/pageview/class.tx_dlf_pageview.php 2012-09-06 16:28:39 +0000
115+++ dlf/plugins/pageview/class.tx_dlf_pageview.php 2012-09-07 14:53:18 +0000
116@@ -237,9 +237,10 @@
117
118 }
119
120+ // !!!ATTENTION PLEASE: THE ID WITHIN THE SCRIPT ELEMENT IS IMPORTANT ANDSHOULD STAY IN FUTURE RELEASES!!!
121 $viewer .= '
122- <script type="text/javascript">
123- /* <![CDATA[ */
124+ <script id="tx-dlf-initViewer" type="text/javascript">
125+ ///* <![CDATA[ */
126 dlfViewer = new Viewer();
127 '.implode("\n", $addImages).'
128 dlfViewer.run();
129
130=== modified file 'dlf/plugins/search/class.tx_dlf_search.php'
131--- dlf/plugins/search/class.tx_dlf_search.php 2012-09-06 14:41:02 +0000
132+++ dlf/plugins/search/class.tx_dlf_search.php 2012-09-07 14:53:18 +0000
133@@ -210,7 +210,125 @@
134 return $this->cObj->HMENU($TSconfig);
135
136 }
137-
138+
139+ /**
140+ * Returns the extended search form and adds the JS files necessary for extended search.
141+ *
142+ * @access protected
143+ *
144+ * @return string the extended search form HTML content or an empty string if extended search is not desired or not possible
145+ */
146+ protected function addExtendedSearch($template) {
147+
148+ if (!$this->ensureJquery()) {
149+
150+ return '';
151+
152+ }
153+
154+ // Add JS for client side query construction.
155+ $GLOBALS['TSFE']->additionalHeaderData[$this->prefixId.'_search_extended'] = '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'plugins/search/tx_dlf_search_extended.js"></script>';
156+
157+ // Quit without doing anything if no fields for extended search are selected.
158+ if (empty($this->conf['extSearchSlotCount']) || empty($this->conf['extSearchFields'])) {
159+
160+ return '';
161+
162+ }
163+
164+ $searchFields = t3lib_div::trimExplode(',', $this->conf['extSearchFields'], TRUE);
165+
166+ if (array_count_values($searchFields) == 0) {
167+
168+ t3lib_div::devLog('[tx_dlf_search.addExtendedSearch] empty array', 'dlf', t3lib_div::SYSLOG_SEVERITY_INFO);
169+
170+ return '';
171+
172+ }
173+
174+ $operatorOptions = '';
175+
176+ foreach (array("AND", "OR", "NOT") as $operator) {
177+
178+ $operatorOptions .= '<option value="'.$operator.'" '.$this->conf['extendedSearch.']['operator.']['option.']['parameters'].'>'.$this->pi_getLL('tt_content.pi_flexform.extSearch.operator.'.$operator).'</option>';
179+
180+ }
181+
182+ $fieldSelectorOptions = '';
183+
184+ // create field selector options
185+ foreach ($searchFields as $searchField) {
186+
187+ $fieldSelectorOptions .= '<option value="'.tx_dlf_indexing::getIndexField($this->conf['pages'], $this->conf['solrcore'], $searchField).'" '.$this->conf['extendedSearch.']['fieldSelector.']['option.']['parameters'].'>'.tx_dlf_helper::translate($searchField, 'tx_dlf_metadata', $this->conf['pages']).'</option>';
188+
189+ }
190+
191+ // create content
192+ $result = '';
193+
194+ $markerArray = array();
195+
196+ for ($i = 0; $i < $this->conf['extSearchSlotCount']; $i++) {
197+
198+ if ($i == 0) {
199+
200+ $markerArray['###EXT_SEARCH_OPERATOR###'] = $this->conf['extendedSearch.']['operator.']['first'];
201+
202+ } else {
203+
204+ $markerArray['###EXT_SEARCH_OPERATOR###'] = '<select name="tx_dlf[operator_'.$i.']" '.$this->conf['extendedSearch.']['operator.']['select.']['parameters'].'>'.$operatorOptions.'</select>';
205+
206+ }
207+
208+ $markerArray['###EXT_SEARCH_FIELD_SELECTOR###'] = '<select name="tx_dlf[fieldSelector_'.$i.']" '.$this->conf['extendedSearch.']['fieldSelector.']['select.']['parameters'].'>'.$fieldSelectorOptions.'</select>';
209+
210+ $markerArray['###EXT_SEARCH_FIELD_INPUT###'] = '<input type="text" name="tx_dlf[field_'.$i.']" '.$this->conf['extendedSearch.']['field.']['parameters'].'>';
211+
212+ $result .= $this->cObj->substituteMarkerArray($template, $markerArray);
213+
214+ }
215+
216+ return $result;
217+
218+ }
219+
220+ /**
221+ * Tries to load t3jquery extension and returns success.
222+ *
223+ * @access protected
224+ *
225+ * @return boolean TRUE on success or FALSE on error
226+ */
227+ private function ensureJquery() {
228+
229+ if (T3JQUERY === TRUE) {
230+
231+ return TRUE;
232+
233+ }
234+
235+ // Ensure extension "t3jquery" is available.
236+ if (t3lib_extMgm::isLoaded('t3jquery')) {
237+
238+ require_once(t3lib_extMgm::extPath('t3jquery').'class.tx_t3jquery.php');
239+
240+ }
241+
242+ // Is "t3jquery" loaded?
243+ if (T3JQUERY === TRUE) {
244+
245+ tx_t3jquery::addJqJS();
246+
247+ return TRUE;
248+
249+ } else {
250+
251+ return FALSE;
252+
253+ }
254+
255+ }
256+
257 /**
258 * Creates an array for a HMENU entry of a facet value.
259 *
260@@ -357,7 +475,7 @@
261 );
262
263 // Display search form.
264- $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
265+ $content .= $this->cObj->substituteSubpart($this->cObj->substituteMarkerArray($this->template, $markerArray), '###EXT_SEARCH_ENTRY###', $this->addExtendedSearch($this->cObj->getSubpart($this->template, '###EXT_SEARCH_ENTRY###')));
266
267 return $this->pi_wrapInBaseClass($content);
268
269
270=== modified file 'dlf/plugins/search/flexform.xml'
271--- dlf/plugins/search/flexform.xml 2012-09-06 09:17:11 +0000
272+++ dlf/plugins/search/flexform.xml 2012-09-07 14:53:18 +0000
273@@ -54,6 +54,7 @@
274 </config>
275 </TCEforms>
276 </limit>
277+<<<<<<< TREE
278 <searchIn>
279 <TCEforms>
280 <exclude>1</exclude>
281@@ -84,6 +85,40 @@
282 </config>
283 </TCEforms>
284 </searchIn>
285+=======
286+ <extSearchSlotCount>
287+ <TCEforms>
288+ <displayCond>FIELD:pages:REQ:true</displayCond>
289+ <exclude>1</exclude>
290+ <label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.extSearch.slotCount</label>
291+ <config>
292+ <type>input</type>
293+ <eval>num,int</eval>
294+ <range>
295+ <lower>-1</lower>
296+ <upper>10</upper>
297+ </range>
298+ <default>0</default>
299+ </config>
300+ </TCEforms>
301+ </extSearchSlotCount>
302+ <extSearchFields>
303+ <TCEforms>
304+ <displayCond>FIELD:pages:REQ:true</displayCond>
305+ <exclude>1</exclude>
306+ <label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.extSearch.fields</label>
307+ <config>
308+ <type>select</type>
309+ <items type="array"></items>
310+ <itemsProcFunc>tx_dlf_tceforms->itemsProcFunc_extendedSearchList</itemsProcFunc>
311+ <size>5</size>
312+ <autoSizeMax>15</autoSizeMax>
313+ <maxitems>1024</maxitems>
314+ <minitems>0</minitems>
315+ </config>
316+ </TCEforms>
317+ </extSearchFields>
318+>>>>>>> MERGE-SOURCE
319 <facets>
320 <TCEforms>
321 <displayCond>FIELD:pages:REQ:true</displayCond>
322
323=== modified file 'dlf/plugins/search/locallang.xml'
324--- dlf/plugins/search/locallang.xml 2012-09-06 09:17:11 +0000
325+++ dlf/plugins/search/locallang.xml 2012-09-07 14:53:18 +0000
326@@ -9,11 +9,19 @@
327 <label index="tt_content.pi_flexform.sheet_general">Options</label>
328 <label index="tt_content.pi_flexform.solrcore">Solr Core</label>
329 <label index="tt_content.pi_flexform.limit">Maximum results</label>
330+<<<<<<< TREE
331 <label index="tt_content.pi_flexform.searchIn">Allow searching in current document or collection?</label>
332 <label index="tt_content.pi_flexform.searchIn.none">none</label>
333 <label index="tt_content.pi_flexform.searchIn.document">document only</label>
334 <label index="tt_content.pi_flexform.searchIn.collection">collection only</label>
335 <label index="tt_content.pi_flexform.searchIn.all">both</label>
336+=======
337+ <label index="tt_content.pi_flexform.extSearch.slotCount">Number of search slots</label>
338+ <label index="tt_content.pi_flexform.extSearch.fields">Show these fields in extended search</label>
339+ <label index="tt_content.pi_flexform.extSearch.operator.AND">and</label>
340+ <label index="tt_content.pi_flexform.extSearch.operator.OR">or</label>
341+ <label index="tt_content.pi_flexform.extSearch.operator.NOT">not</label>
342+>>>>>>> MERGE-SOURCE
343 <label index="tt_content.pi_flexform.facets">Show these facets</label>
344 <label index="tt_content.pi_flexform.limitFacets">Maximum facet values</label>
345 <label index="tt_content.pi_flexform.targetPid">Target page (with "DLF: List View" plugin)</label>
346@@ -30,11 +38,19 @@
347 <label index="tt_content.pi_flexform.sheet_general">Einstellungen</label>
348 <label index="tt_content.pi_flexform.solrcore">Solr Kern</label>
349 <label index="tt_content.pi_flexform.limit">Maximale Ergebnismenge</label>
350+<<<<<<< TREE
351 <label index="tt_content.pi_flexform.searchIn">Erlaube Suche in aktuellem Dokument oder Kollektion?</label>
352 <label index="tt_content.pi_flexform.searchIn.none">nein</label>
353 <label index="tt_content.pi_flexform.searchIn.document">nur Dokument</label>
354 <label index="tt_content.pi_flexform.searchIn.collection">nur Kollektion</label>
355 <label index="tt_content.pi_flexform.searchIn.all">beides</label>
356+=======
357+ <label index="tt_content.pi_flexform.extSearch.slotCount">Anzahl an Suchfeldern</label>
358+ <label index="tt_content.pi_flexform.extSearch.fields">Diese Felder in der erweiterten Suche anzeigen</label>
359+ <label index="tt_content.pi_flexform.extSearch.operator.AND">und</label>
360+ <label index="tt_content.pi_flexform.extSearch.operator.OR">oder</label>
361+ <label index="tt_content.pi_flexform.extSearch.operator.NOT">nicht</label>
362+>>>>>>> MERGE-SOURCE
363 <label index="tt_content.pi_flexform.facets">Diese Facetten anzeigen</label>
364 <label index="tt_content.pi_flexform.limitFacets">Maximale Facettenwerte</label>
365 <label index="tt_content.pi_flexform.targetPid">Zielseite (mit Plugin "DLF: Listenansicht")</label>
366
367=== modified file 'dlf/plugins/search/setup.txt'
368--- dlf/plugins/search/setup.txt 2012-08-24 13:15:53 +0000
369+++ dlf/plugins/search/setup.txt 2012-09-07 14:53:18 +0000
370@@ -32,4 +32,13 @@
371 CUR < .NO
372 CUR.wrapItemAndSub = <li class="tx-dlf-search-cur">|</li>
373 }
374-}
375\ No newline at end of file
376+}
377+
378+plugin.tx_dlf_search.extendedSearch {
379+ operator.first = <span class="span1" style="padding: 0 2px;">&nbsp;</span>
380+ operator.select.parameters = class="span1"
381+ #operator.option.parameters =
382+ fieldSelector.select.parameters = class="span2"
383+ #fieldSelector.option.parameters =
384+ field.parameters = class="span5"
385+}
386
387=== added file 'dlf/plugins/search/tx_dlf_search_extended.js'
388--- dlf/plugins/search/tx_dlf_search_extended.js 1970-01-01 00:00:00 +0000
389+++ dlf/plugins/search/tx_dlf_search_extended.js 2012-09-07 14:53:18 +0000
390@@ -0,0 +1,50 @@
391+$(
392+ function() {
393+ var parentForms = $('input[name^="tx_dlf[field"]').parents('form');
394+ if (parentForms.length == 0) {
395+ return;
396+ }
397+
398+ var extendedSearchForm = parentForms.get(0);
399+ if (extendedSearchForm == null) {
400+ return;
401+ }
402+
403+ var queryInput = $(extendedSearchForm).find('input[name="tx_dlf[query]"]');
404+ if (queryInput == null) {
405+ return;
406+ }
407+
408+ $(extendedSearchForm).submit(function() {
409+ var query = "";
410+
411+ var filledSearchFields = $(extendedSearchForm).find('input[name^="tx_dlf[field"][value!=""]');
412+ filledSearchFields.each(function(index, element){
413+ var indexer = /[a-z]+_([0-9]+)/g;
414+ var match = indexer.exec(element.name);
415+ if (match == null) {
416+ return false;
417+ }
418+
419+ var fieldIndex = match[1];
420+
421+ // get operator
422+ var operator = $('select[name="tx_dlf[operator_' + fieldIndex + ']"]').val();
423+ if (index > 0 || operator == "NOT") {
424+ if (!query) {
425+ query = "*";
426+ }
427+
428+ query += " " + operator;
429+ }
430+
431+ // get search field selector
432+ var fieldSelector = $('select[name="tx_dlf[fieldSelector_' + fieldIndex + ']"]').val();
433+ query += " " + fieldSelector + ":" + element.value;
434+ });
435+
436+ $(queryInput).val(query.replace(/^\s\s*/, '').replace(/\s\s*$/, ''));
437+ return true;
438+ });
439+ }
440+);
441\ No newline at end of file

Subscribers

People subscribed via source and target branches