Issues (6)

src/IndexPage/Columns/AbstractColumn.php (1 issue)

1
<?php
2
3
4
namespace UserAdmin\IndexPage\Columns;
5
6
use Illuminate\Support\Str;
7
8
abstract class AbstractColumn
9
{
10
    public bool $sortable = false;
11
12
    public bool $html = false;
13
14
    public string $title;
15
16
    public string $field;
17
18
    abstract public static function component(): string;
19
20
    /**
21
     * AbstractColumn constructor.
22
     *
23
     * @param ...$args - (string $title, string $field, ....)
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
24
     *
25
     * @throws \Exception
26
     */
27 1
    public function __construct(...$args)
28
    {
29 1
        if (empty($args[0]) || !is_string($args[0])) {
30
            throw new \Exception('Please specify row title');
31
        }
32
33 1
        $this->title = $args[0];
34
35 1
        $this->field = (!empty($args[1]) && is_string($args[1])) ? $args[1] : Str::snake($args[1]);
36 1
    }
37
38 1
    public function sortable(bool $sortable = true): self
39
    {
40 1
        $this->sortable = $sortable;
41
42 1
        return $this;
43
    }
44
45
    public function asHtml(bool $html = true): self
46
    {
47
        $this->html = $html;
48
49
        return $this;
50
    }
51
52 1
    public function headerData(): array
53
    {
54
        return [
55 1
            'component' => static::component(),
56 1
            'sortable'  => $this->sortable,
57 1
            'title'     => $this->title,
58 1
            'field'     => $this->field,
59 1
            'html'      => $this->html,
60
        ];
61
    }
62
}
63