The GPL headers named dreipunktnull and an old address and no longer match the license of the code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace EP\EpTheme\ViewHelpers;
|
|
|
|
use EP\EpProducts\Domain\Model\Product;
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
|
|
|
class RatingViewHelper extends AbstractViewHelper
|
|
{
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected $escapeOutput = false;
|
|
|
|
public function initializeArguments()
|
|
{
|
|
parent::initializeArguments();
|
|
|
|
$this->registerArgument('product', Product::class, 'The product', true);
|
|
}
|
|
|
|
/**
|
|
* @param array $arguments
|
|
* @param \Closure $renderChildrenClosure
|
|
* @param RenderingContextInterface $renderingContext
|
|
* @return mixed
|
|
*/
|
|
public function render()
|
|
{
|
|
$product = $this->renderChildren();
|
|
if ($product === null) {
|
|
$product = $this->arguments['product'];
|
|
}
|
|
$ratingAverage = $product->getRatingAverage();
|
|
$ratingVotesCount = $product->getRatingVotesCount();
|
|
$fullStars = floor($ratingAverage);
|
|
$halfStar = ($ratingAverage - $fullStars) > 0;
|
|
$ratingAverageLabel = number_format($ratingAverage, 1, ',', '.');
|
|
$content = '';
|
|
for ($i = 1; $i <= $fullStars; $i++)
|
|
{
|
|
$content .= '<i class="fa fa-star" aria-hidden="true"></i>';
|
|
}
|
|
if ($halfStar) {
|
|
$content .= '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
|
|
}
|
|
$content .= sprintf('%s Sterne (%d)', $ratingAverageLabel, $ratingVotesCount);
|
|
return $content;
|
|
}
|
|
|
|
}
|