1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Widget\Controller; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ResultPaginateController |
22
|
|
|
* |
23
|
|
|
* @author Frans Saris <[email protected]> |
24
|
|
|
* @author Timo Hund <[email protected]> |
25
|
|
|
* @package ApacheSolrForTypo3\Solr\ViewHelpers\Widget\Controller |
26
|
|
|
*/ |
27
|
|
|
class ResultPaginateController extends AbstractPaginateWidgetController |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var SearchResultSet |
32
|
|
|
*/ |
33
|
|
|
protected $resultSet; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function initializeAction() |
39
|
|
|
{ |
40
|
|
|
parent::initializeAction(); |
41
|
|
|
|
42
|
|
|
$this->resultSet = $this->widgetConfiguration['resultSet']; |
43
|
|
|
$this->configuration['itemsPerPage'] = $this->getItemsPerPage(); |
44
|
|
|
|
45
|
|
|
$this->numberOfPages = (int)ceil($this->resultSet->getUsedSearch()->getNumberOfResults() / $this->configuration['itemsPerPage']); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Determines the number of results per page. When nothing is configured 10 will be returned. |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
|
|
protected function getItemsPerPage() |
54
|
|
|
{ |
55
|
|
|
$perPage = (int)$this->resultSet->getUsedSearch()->getQuery()->getResultsPerPage(); |
56
|
|
|
return $perPage > 0 ? $perPage : 10; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext $controllerContext |
61
|
|
|
* @return \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext |
62
|
|
|
*/ |
63
|
|
|
protected function setActiveSearchResultSet($controllerContext) { |
64
|
|
|
$controllerContext->setSearchResultSet($this->resultSet); |
65
|
|
|
return $controllerContext; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function indexAction() |
72
|
|
|
{ |
73
|
|
|
// set current page |
74
|
|
|
$this->currentPage = $this->resultSet->getUsedPage(); |
75
|
|
|
if ($this->currentPage < 1) { |
76
|
|
|
$this->currentPage = 1; |
77
|
|
|
} |
78
|
|
|
$this->view->assign('contentArguments', [$this->widgetConfiguration['as'] => $this->resultSet->getSearchResults(), 'pagination' => $this->buildPagination()]); |
79
|
|
|
$this->view->assign('configuration', $this->configuration); |
80
|
27 |
|
$this->view->assign('resultSet', $this->resultSet); |
81
|
|
|
if (!empty($this->templatePath)) { |
82
|
27 |
|
$this->view->setTemplatePathAndFilename($this->templatePath); |
|
|
|
|
83
|
|
|
} |
84
|
27 |
|
} |
85
|
|
|
} |
86
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: