adrema/app/Form/Presenters/GroupPresenter.php

36 lines
581 B
PHP
Raw Permalink Normal View History

2024-02-09 23:22:49 +01:00
<?php
namespace App\Form\Presenters;
2024-04-18 01:03:30 +02:00
use App\Form\Fields\GroupField;
2024-02-09 23:22:49 +01:00
use App\Group;
class GroupPresenter extends Presenter
{
2024-04-18 01:03:30 +02:00
private GroupField $field;
public function field(GroupField $field): self
{
$this->field = $field;
return $this;
}
2024-02-09 23:22:49 +01:00
/**
* @param ?int $value
*/
public function present($value): string
{
2024-04-18 01:03:30 +02:00
if ($value === -1) {
return $this->field->emptyOptionValue;
}
2024-02-09 23:22:49 +01:00
if (!$value) {
return '';
}
return Group::find($value)?->display() ?: '';
}
}