1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\ContentObject; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2011-2015 Ingo Renner <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* A content object (cObj) to turn comma separated strings into an array to be |
31
|
|
|
* used in a multi value field in a Solr document. |
32
|
|
|
* |
33
|
|
|
* Example usage: |
34
|
|
|
* |
35
|
|
|
* keywords = SOLR_MULTIVALUE # supports stdWrap |
36
|
|
|
* keywords { |
37
|
|
|
* field = tags # a comma separated field. instead of field you can also use "value" |
38
|
|
|
* separator = , # comma is the default value |
39
|
|
|
* removeEmptyValues = 1 # a flag to remove empty strings from the list, on by default. |
40
|
|
|
* removeDuplicateValues = 1 # a flag to remove duplicate strings from the list, off by default. |
41
|
|
|
* } |
42
|
|
|
* |
43
|
|
|
* @author Ingo Renner <[email protected]> |
44
|
|
|
*/ |
45
|
|
|
class Multivalue |
46
|
|
|
{ |
47
|
|
|
const CONTENT_OBJECT_NAME = 'SOLR_MULTIVALUE'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Executes the SOLR_MULTIVALUE content object. |
51
|
|
|
* |
52
|
|
|
* Turns a list of values into an array that can then be used to fill |
53
|
|
|
* multivalued fields in a Solr document. The array is returned in |
54
|
|
|
* serialized form as content objects are expected to return strings. |
55
|
|
|
* |
56
|
|
|
* @param string $name content object name 'SOLR_MULTIVALUE' |
57
|
|
|
* @param array $configuration for the content object, expects keys 'separator' and 'field' |
58
|
|
|
* @param string $TyposcriptKey not used |
59
|
|
|
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject parent cObj |
60
|
|
|
* @return string serialized array representation of the given list |
61
|
|
|
*/ |
62
|
2 |
|
public function cObjGetSingleExt( |
63
|
|
|
/** @noinspection PhpUnusedParameterInspection */ $name, |
|
|
|
|
64
|
|
|
array $configuration, |
65
|
|
|
/** @noinspection PhpUnusedParameterInspection */ $TyposcriptKey, |
|
|
|
|
66
|
|
|
$contentObject |
67
|
|
|
) { |
68
|
2 |
|
$data = ''; |
69
|
2 |
|
if (isset($configuration['value'])) { |
70
|
1 |
|
$data = $configuration['value']; |
71
|
1 |
|
unset($configuration['value']); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
if (!empty($configuration)) { |
75
|
2 |
|
$data = $contentObject->stdWrap($data, $configuration); |
76
|
|
|
} |
77
|
|
|
|
78
|
2 |
|
if (!array_key_exists('separator', $configuration)) { |
79
|
|
|
$configuration['separator'] = ','; |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
$removeEmptyValues = true; |
83
|
2 |
|
if (isset($configuration['removeEmptyValues']) && $configuration['removeEmptyValues'] == 0) { |
84
|
|
|
$removeEmptyValues = false; |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
$listAsArray = GeneralUtility::trimExplode( |
88
|
2 |
|
$configuration['separator'], |
89
|
|
|
$data, |
90
|
2 |
|
$removeEmptyValues |
91
|
|
|
); |
92
|
|
|
|
93
|
2 |
|
if (!empty($configuration['removeDuplicateValues'])) { |
94
|
|
|
$listAsArray = array_unique($listAsArray); |
95
|
|
|
} |
96
|
|
|
|
97
|
2 |
|
return serialize($listAsArray); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.