TYPO3 CMS  TYPO3_6-2
PageBrowsingViewHelper.php
Go to the documentation of this file.
1 <?php
3 
25 
29  protected $prefixId = 'tx_indexedsearch';
30 
41  public function render($maximumNumberOfResultPages, $numberOfResults, $resultsPerPage, $currentPage = 0, $freeIndexUid = NULL) {
42  if ($resultsPerPage <= 0) {
43  $resultsPerPage = 10;
44  }
45  $pageCount = (int)ceil($numberOfResults / $resultsPerPage);
46  // only show the result browser if more than one page is needed
47  if ($pageCount === 1) {
48  return '';
49  }
50 
51  // Check if $currentPage is in range
52  $currentPage = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($currentPage, 0, $pageCount - 1);
53 
54  $content = '';
55  // prev page
56  // show on all pages after the 1st one
57  if ($currentPage > 0) {
58  $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.previous', 'IndexedSearch');
59  $content .= '<li>' . $this->makecurrentPageSelector_link($label, $currentPage - 1, $freeIndexUid) . '</li>';
60  }
61  // Check if $maximumNumberOfResultPages is in range
62  $maximumNumberOfResultPages = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, $pageCount, 10);
63  // Assume $currentPage is in the middle and calculate the index limits of the result page listing
64  $minPage = $currentPage - (int)floor($maximumNumberOfResultPages / 2);
65  $maxPage = $minPage + $maximumNumberOfResultPages - 1;
66  // Check if the indexes are within the page limits
67  if ($minPage < 0) {
68  $maxPage -= $minPage;
69  $minPage = 0;
70  } elseif ($maxPage >= $pageCount) {
71  $minPage -= $maxPage - $pageCount + 1;
72  $maxPage = $pageCount - 1;
73  }
74  $pageLabel = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.page', 'IndexedSearch');
75  for ($a = $minPage; $a <= $maxPage; $a++) {
76  $label = trim($pageLabel . ' ' . ($a + 1));
77  $label = $this->makecurrentPageSelector_link($label, $a, $freeIndexUid);
78  if ($a === $currentPage) {
79  $content .= '<li class="tx-indexedsearch-browselist-currentPage"><strong>' . $label . '</strong></li>';
80  } else {
81  $content .= '<li>' . $label . '</li>';
82  }
83  }
84  // next link
85  if ($currentPage < $pageCount - 1) {
86  $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.next', 'IndexedSearch');
87  $content .= '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage + 1), $freeIndexUid) . '</li>';
88  }
89  return '<ul class="tx-indexedsearch-browsebox">' . $content . '</ul>';
90  }
91 
102  public function makecurrentPageSelector_link($str, $p, $freeIndexUid) {
103  $onclick = 'document.getElementById(\'' . $this->prefixId . '_pointer\').value=\'' . $p . '\';';
104  if ($freeIndexUid !== NULL) {
105  $onclick .= 'document.getElementById(\'' . $this->prefixId . '_freeIndexUid\').value=\'' . rawurlencode($freeIndexUid) . '\';';
106  }
107  $onclick .= 'document.getElementById(\'' . $this->prefixId . '\').submit();return false;';
108  return '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . $str . '</a>';
109  }
110 
111 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
render($maximumNumberOfResultPages, $numberOfResults, $resultsPerPage, $currentPage=0, $freeIndexUid=NULL)
static translate($key, $extensionName, $arguments=NULL)