mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\DataTables\Column;
|
||
|
|
||
|
use Omines\DataTablesBundle\Column\AbstractColumn;
|
||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||
|
|
||
|
class PrettyBoolColumn extends AbstractColumn
|
||
|
{
|
||
|
|
||
|
protected $translator;
|
||
|
|
||
|
public function __construct(TranslatorInterface $translator)
|
||
|
{
|
||
|
$this->translator = $translator;
|
||
|
}
|
||
|
|
||
|
public function normalize($value): ?bool
|
||
|
{
|
||
|
if (null === $value) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
return (bool) $value;
|
||
|
}
|
||
|
|
||
|
public function render($value, $context)
|
||
|
{
|
||
|
if ($value === true) {
|
||
|
return '<span class="badge bg-success"><i class="fa-solid fa-circle-check fa-fw"></i> '
|
||
|
. $this->translator->trans('bool.true')
|
||
|
. '</span>';
|
||
|
}
|
||
|
|
||
|
if ($value === false) {
|
||
|
return '<span class="badge bg-danger"><i class="fa-solid fa-circle-xmark fa-fw"></i> '
|
||
|
. $this->translator->trans('bool.false')
|
||
|
. '</span>';
|
||
|
}
|
||
|
|
||
|
if ($value === null) {
|
||
|
return '<span class="badge bg-secondary>"<i class="fa-solid fa-circle-question fa-fw"></i> '
|
||
|
. $this->translator->trans('bool.unknown')
|
||
|
. '</span>';
|
||
|
}
|
||
|
|
||
|
throw new \RuntimeException('Unexpected value!');
|
||
|
}
|
||
|
}
|