1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_table\core\Table\Columns; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_connect\core\ConnectException; |
7
|
|
|
use kalanis\kw_connect\core\Interfaces\IRow; |
8
|
|
|
use kalanis\kw_table\core\Interfaces\Form\IField; |
9
|
|
|
use kalanis\kw_table\core\Interfaces\Table\IColumn; |
10
|
|
|
use kalanis\kw_table\core\Table\AStyle; |
11
|
|
|
use kalanis\kw_table\core\Table\TSourceName; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AColumn |
16
|
|
|
* @package kalanis\kw_table\Table\Columns |
17
|
|
|
*/ |
18
|
|
|
abstract class AColumn extends AStyle implements IColumn |
19
|
|
|
{ |
20
|
|
|
use TSourceName; |
21
|
|
|
use TWrappers; |
22
|
|
|
|
23
|
|
|
/** @var string|int */ |
24
|
|
|
protected $sourceName = ''; |
25
|
|
|
protected string $filterName = ''; |
26
|
|
|
protected bool $sortable = false; |
27
|
|
|
protected ?IField $headerFilterField = null; |
28
|
|
|
protected ?IField $footerFilterField = null; |
29
|
|
|
protected ?string $headerText = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $text |
33
|
|
|
* @return $this |
34
|
|
|
*/ |
35
|
37 |
|
public function setHeaderText(?string $text) |
36
|
|
|
{ |
37
|
37 |
|
$this->headerText = $text; |
38
|
37 |
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
22 |
|
public function getHeaderText(): string |
45
|
|
|
{ |
46
|
22 |
|
return is_null($this->headerText) ? $this->getFilterName() : $this->headerText ; |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
|
public function translate(IRow $source): string |
50
|
|
|
{ |
51
|
2 |
|
return $this->formatData(strval($this->getValue($source))); |
52
|
|
|
} |
53
|
|
|
|
54
|
10 |
|
public function getFilterName(): string |
55
|
|
|
{ |
56
|
10 |
|
return empty($this->filterName) ? strval($this->getSourceName()) : $this->filterName ; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns value from row |
61
|
|
|
* @param IRow $source |
62
|
|
|
* @throws ConnectException |
63
|
|
|
* @return string|int|float|bool|null |
64
|
|
|
*/ |
65
|
39 |
|
public function getValue(IRow $source) |
66
|
|
|
{ |
67
|
39 |
|
return $this->value($source, $this->getSourceName()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param IRow $source |
72
|
|
|
* @param string|int $overrideProperty |
73
|
|
|
* @throws ConnectException |
74
|
|
|
* @return string|int|float|bool|null |
75
|
|
|
*/ |
76
|
1 |
|
public function getOverrideValue(IRow $source, $overrideProperty) |
77
|
|
|
{ |
78
|
1 |
|
return $this->value($source, $overrideProperty); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param IRow $source |
83
|
|
|
* @param string|int $property |
84
|
|
|
* @throws ConnectException |
85
|
|
|
* @return string|int|float|bool |
86
|
|
|
*/ |
87
|
24 |
|
protected function value(IRow $source, $property) |
88
|
|
|
{ |
89
|
24 |
|
return $source->getValue($property); |
90
|
|
|
} |
91
|
|
|
|
92
|
11 |
|
public function canOrder(): bool |
93
|
|
|
{ |
94
|
11 |
|
return true; |
95
|
|
|
} |
96
|
|
|
|
97
|
27 |
|
public function hasHeaderFilterField(): bool |
98
|
|
|
{ |
99
|
27 |
|
return $this->headerFilterField && $this->headerFilterField instanceof IField; |
100
|
|
|
} |
101
|
|
|
|
102
|
27 |
|
public function hasFooterFilterField(): bool |
103
|
|
|
{ |
104
|
27 |
|
return $this->footerFilterField && $this->footerFilterField instanceof IField; |
105
|
|
|
} |
106
|
|
|
|
107
|
13 |
|
public function setHeaderFiltering(?IField $field): self |
108
|
|
|
{ |
109
|
13 |
|
$this->headerFilterField = $field; |
110
|
13 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
7 |
|
public function setFooterFiltering(IField $field) |
114
|
|
|
{ |
115
|
7 |
|
$this->footerFilterField = $field; |
116
|
7 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
11 |
|
public function getHeaderFilterField(): ?IField |
120
|
|
|
{ |
121
|
11 |
|
return $this->headerFilterField; |
122
|
|
|
} |
123
|
|
|
|
124
|
7 |
|
public function getFooterFilterField(): ?IField |
125
|
|
|
{ |
126
|
7 |
|
return $this->footerFilterField; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|