1 | <?php |
||
40 | abstract class AbstractFacetRenderer implements FacetRenderer |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * @var Search |
||
45 | */ |
||
46 | protected $search; |
||
47 | |||
48 | /** |
||
49 | * The name of the facet being rendered |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $facetName; |
||
54 | |||
55 | /** |
||
56 | * The facet to render. |
||
57 | * |
||
58 | * @var Facet |
||
59 | */ |
||
60 | protected $facet; |
||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $facetConfiguration; |
||
66 | |||
67 | /** |
||
68 | * Configuration |
||
69 | * |
||
70 | * @var TypoScriptConfiguration |
||
71 | */ |
||
72 | protected $solrConfiguration; |
||
73 | |||
74 | /** |
||
75 | * Template |
||
76 | * |
||
77 | * @var Template |
||
78 | */ |
||
79 | protected $template = null; |
||
80 | |||
81 | /** |
||
82 | * Link target page id. |
||
83 | * |
||
84 | * @var int |
||
85 | */ |
||
86 | protected $linkTargetPageId = 0; |
||
87 | |||
88 | /** |
||
89 | * Query link builder |
||
90 | * |
||
91 | * @var LinkBuilder |
||
92 | */ |
||
93 | protected $queryLinkBuilder; |
||
94 | |||
95 | /** |
||
96 | * Constructor. |
||
97 | * |
||
98 | * @param Facet $facet The facet to render. |
||
99 | */ |
||
100 | 18 | public function __construct(Facet $facet) |
|
101 | { |
||
102 | 18 | $this->search = GeneralUtility::makeInstance(Search::class); |
|
103 | |||
104 | 18 | $this->facet = $facet; |
|
105 | 18 | $this->facetName = $facet->getName(); |
|
106 | |||
107 | 18 | $this->solrConfiguration = Util::getSolrConfiguration(); |
|
108 | 18 | $this->facetConfiguration = $this->solrConfiguration->getSearchFacetingFacetByName($this->facetName); |
|
109 | |||
110 | 18 | $this->linkTargetPageId = $GLOBALS['TSFE']->id; |
|
111 | |||
112 | 18 | $this->queryLinkBuilder = GeneralUtility::makeInstance(LinkBuilder::class, $this->search->getQuery()); |
|
113 | 18 | } |
|
114 | |||
115 | /** |
||
116 | * Renders the complete facet. |
||
117 | * |
||
118 | * @return string Facet markup. |
||
119 | */ |
||
120 | 18 | public function renderFacet() |
|
121 | { |
||
122 | // TODO must check whether $this->template is set |
||
123 | |||
124 | 18 | $facetContent = ''; |
|
125 | |||
126 | 18 | $showEmptyFacets = $this->solrConfiguration->getSearchFacetingShowEmptyFacetsByName($this->facetName); |
|
127 | |||
128 | // if the facet doesn't provide any options, don't render it unless |
||
129 | // it is configured to be rendered nevertheless |
||
130 | 18 | if (!$this->facet->isEmpty() || $showEmptyFacets) { |
|
131 | 18 | $facetTemplate = clone $this->template; |
|
132 | 18 | $facetTemplate->workOnSubpart('single_facet'); |
|
133 | |||
134 | 18 | $facetOptions = $this->renderFacetOptions(); |
|
135 | 18 | $facetTemplate->addSubpart('single_facet_option', $facetOptions); |
|
136 | |||
137 | 18 | $facet = $this->getFacetProperties(); |
|
138 | |||
139 | // remove properties irrelevant for rendering in the template engine |
||
140 | unset( |
||
141 | 18 | $facet['renderingInstruction'], |
|
142 | $facet['renderingInstruction.'], |
||
143 | 18 | $facet[$facet['type'] . '.'] |
|
144 | ); |
||
145 | |||
146 | 18 | $facetTemplate->addVariable('facet', $facet); |
|
147 | 18 | $facetContent = $facetTemplate->render(); |
|
148 | 18 | } |
|
149 | |||
150 | 18 | return $facetContent; |
|
151 | } |
||
152 | |||
153 | /** |
||
154 | * Renders a numeric range facet by providing a slider |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | abstract protected function renderFacetOptions(); |
||
159 | |||
160 | /** |
||
161 | * (non-PHPdoc) |
||
162 | * @see \ApacheSolrForTypo3\Solr\Facet\FacetRenderer::getFacetProperties() |
||
163 | */ |
||
164 | 18 | public function getFacetProperties() |
|
189 | |||
190 | /** |
||
191 | * (non-PHPdoc) |
||
192 | * @see \ApacheSolrForTypo3\Solr\Facet\FacetRenderer::getFacetOptions() |
||
193 | */ |
||
194 | 18 | public function getFacetOptions() |
|
198 | |||
199 | /** |
||
200 | * (non-PHPdoc) |
||
201 | * @see \ApacheSolrForTypo3\Solr\Facet\FacetRenderer::getFacetOptionsCount() |
||
202 | */ |
||
203 | 18 | public function getFacetOptionsCount() |
|
207 | |||
208 | /** |
||
209 | * (non-PHPdoc) |
||
210 | * @see \ApacheSolrForTypo3\Solr\Facet\FacetRenderer::setTemplate() |
||
211 | * @param Template $template |
||
212 | */ |
||
213 | 18 | public function setTemplate(Template $template) |
|
217 | |||
218 | /** |
||
219 | * (non-PHPdoc) |
||
220 | * @see \ApacheSolrForTypo3\Solr\Facet\FacetRenderer::setLinkTargetPageId() |
||
221 | * @param int $linkTargetPageId |
||
222 | */ |
||
223 | 18 | public function setLinkTargetPageId($linkTargetPageId) |
|
228 | |||
229 | /** |
||
230 | * Builds the URL to reset all options of a facet - removing all its applied |
||
231 | * filters from a result set. |
||
232 | * |
||
233 | * @return string Url to remove a facet |
||
234 | */ |
||
235 | 18 | protected function buildResetFacetUrl() |
|
261 | } |
||
262 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: