Files
Tony Volpe 706f089d5e add theme
2024-06-18 16:47:10 -04:00

54 lines
1.5 KiB
PHP

<?php
namespace Helpers;
class Ratings
{
public static function ratingsStars()
{
return function ($template, $context, $args, $source) {
$numberOfStars = $context->get($args);
if (!is_numeric($numberOfStars)) {
return "The value you passed to this helper is not a number.";
}
$output = "";
for ($i=1; $i <= 5; $i++) {
if ($i <= $numberOfStars) {
$output .= "<i class='bi bi-star-fill'></i>";
} else {
$output .= "<i class='bi bi-star'></i>";
}
}
return $output;
};
}
public static function numberFormatter()
{
return function ($template, $context, $args, $source) {
$totalCount = $context->get($args);
if (!is_numeric($totalCount)) {
return "The value you passed to this helper is not a number.";
}
return number_format($totalCount);
};
}
public static function currencyFormatter()
{
return function ($template, $context, $args, $source) {
$totalCount = $context->get($args);
if ($totalCount === "Free") {
return "Free";
}
if (!is_numeric($totalCount)) {
return "The value you passed to this helper is not a number.";
}
return "$" . number_format($totalCount, 2);
};
}
}