‪TYPO3CMS  ‪main
RatingViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
28 class ‪RatingViewHelper extends AbstractViewHelper
29 {
30  use CompileWithRenderStatic;
31 
32  public function ‪initializeArguments(): void
33  {
34  $this->registerArgument('row', 'array', '', true);
35  $this->registerArgument('firstRow', 'array', '', true);
36  $this->registerArgument('sortOrder', 'string', '', true);
37  }
38 
39  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
40  {
41  $row = $arguments['row'];
42  $firstRow = $arguments['firstRow'];
43 
44  $default = ' ';
45  switch ($arguments['sortOrder']) {
46  case 'rank_count':
47  return $row['order_val'] . ' ' . ‪LocalizationUtility::translate('result.ratingMatches', 'IndexedSearch');
48  case 'rank_first':
49  return ceil(‪MathUtility::forceIntegerInRange(255 - $row['order_val'], 1, 255) / 255 * 100) . '%';
50  case 'rank_flag':
51  if ($firstRow['order_val2'] ?? 0) {
52  // (3 MSB bit, 224 is highest value of order_val1 currently)
53  $base = $row['order_val1'] * 256;
54  // 15-3 MSB = 12
55  $freqNumber = $row['order_val2'] / $firstRow['order_val2'] * 2 ** 12;
56  $total = ‪MathUtility::forceIntegerInRange($base + $freqNumber, 0, 32767);
57  return ceil(log($total) / log(32767) * 100) . '%';
58  }
59  return $default;
60  case 'rank_freq':
61  $max = 10000;
62  $total = ‪MathUtility::forceIntegerInRange($row['order_val'], 0, $max);
63  return ceil(log($total) / log($max) * 100) . '%';
64  case 'crdate':
65  $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
66  return $cObj->calcAge(‪$GLOBALS['EXEC_TIME'] - $row['item_crdate']);
67  case 'mtime':
68  $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
69  return $cObj->calcAge(‪$GLOBALS['EXEC_TIME'] - $row['item_mtime']);
70  default:
71  return $default;
72  }
73  }
74 
75 }
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:35
‪TYPO3\CMS\IndexedSearch\ViewHelpers\SearchResult\RatingViewHelper
Definition: RatingViewHelper.php:29
‪TYPO3\CMS\IndexedSearch\ViewHelpers\SearchResult\RatingViewHelper\initializeArguments
‪initializeArguments()
Definition: RatingViewHelper.php:31
‪TYPO3\CMS\IndexedSearch\ViewHelpers\SearchResult\RatingViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RatingViewHelper.php:38
‪TYPO3\CMS\IndexedSearch\ViewHelpers\SearchResult
Definition: RatingViewHelper.php:18
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, Locale|string $languageKey=null)
Definition: LocalizationUtility.php:47
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52