1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Ui\Table\Column;
6:
7: use Atk4\Data\Field;
8: use Atk4\Data\Model;
9: use Atk4\Ui\Table;
10:
11: /**
12: * If field have values without a relation like a status or a coded state of a process, example:
13: * Machine state:
14: * 0 => off
15: * 1 => powerup
16: * 2 => on
17: * 3 => resetting
18: * 4 => error.
19: *
20: * we don't need a table to define this, cause are defined in project
21: *
22: * using KeyValue Column you can show this values without using DB Relations
23: * need to be defined in field like this:
24: *
25: * $this->addField('course_payment_status', [
26: * 'caption' => __('Payment Status'),
27: * 'default' => 0,
28: * 'values' => [
29: * __('not invoiceable'),
30: * __('ready to invoice'),
31: * __('invoiced'),
32: * __('paid'),
33: * ],
34: * 'ui' => [
35: * 'form' => [Form\Control\Dropdown::class],
36: * 'table' => ['KeyValue'],
37: * ],
38: * ]);
39: */
40: class KeyValue extends Table\Column
41: {
42: public array $values;
43:
44: #[\Override]
45: public function getHtmlTags(Model $row, ?Field $field): array
46: {
47: $key = $field->get($row);
48: $value = $field->values[$key] ?? '';
49:
50: return [$field->shortName => $value];
51: }
52: }
53: