|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Grid\Row; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
|
8
|
|
|
use AbterPhp\Framework\Grid\Action\IAction; |
|
9
|
|
|
use AbterPhp\Framework\Grid\Cell\Cell; |
|
10
|
|
|
use AbterPhp\Framework\Grid\Collection\Cells; |
|
11
|
|
|
use AbterPhp\Framework\Grid\Component\Actions; |
|
12
|
|
|
use AbterPhp\Framework\Html\Attribute; |
|
13
|
|
|
use AbterPhp\Framework\Html\Helper\Tag as TagHelper; |
|
14
|
|
|
use AbterPhp\Framework\Html\INode; |
|
15
|
|
|
use AbterPhp\Framework\Html\Tag; |
|
16
|
|
|
use Opulence\Orm\IEntity; |
|
17
|
|
|
|
|
18
|
|
|
// @phan-suppress-current-line PhanUnreferencedUseNormal |
|
19
|
|
|
|
|
20
|
|
|
class Row extends Tag implements IRow |
|
21
|
|
|
{ |
|
22
|
|
|
protected const DEFAULT_TAG = Html5::TAG_TR; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Cells */ |
|
25
|
|
|
protected Cells $cells; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Actions */ |
|
28
|
|
|
protected Actions $actions; |
|
29
|
|
|
|
|
30
|
|
|
/** @var Cell */ |
|
31
|
|
|
protected Cell $actionCell; |
|
32
|
|
|
|
|
33
|
|
|
/** @var IEntity */ |
|
34
|
|
|
protected IEntity $entity; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Row constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param Cells $cells |
|
40
|
|
|
* @param Actions|null $actions |
|
41
|
|
|
* @param string[] $intents |
|
42
|
|
|
* @param array<string,Attribute>|null $attributes |
|
43
|
|
|
* @param string|null $tag |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
Cells $cells, |
|
47
|
|
|
?Actions $actions = null, |
|
48
|
|
|
array $intents = [], |
|
49
|
|
|
?array $attributes = null, |
|
50
|
|
|
?string $tag = null |
|
51
|
|
|
) { |
|
52
|
|
|
parent::__construct(null, $intents, $attributes, $tag); |
|
53
|
|
|
|
|
54
|
|
|
$this->cells = $cells; |
|
55
|
|
|
$this->actions = $actions ?? new Actions(); |
|
56
|
|
|
|
|
57
|
|
|
if ($actions) { |
|
58
|
|
|
$this->actionCell = new Cell($this->actions, Cell::GROUP_ACTIONS, [Cell::INTENT_ACTIONS]); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return Cells |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getCells(): Cells |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->cells; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return IEntity |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getEntity(): IEntity |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->entity; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param IEntity $entity |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setEntity(IEntity $entity): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->entity = $entity; |
|
84
|
|
|
|
|
85
|
|
|
foreach ($this->actions as $action) { |
|
86
|
|
|
assert($action instanceof IAction); |
|
87
|
|
|
$action->setEntity($entity); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return INode[] |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getExtendedNodes(): array |
|
95
|
|
|
{ |
|
96
|
|
|
$nodes = [$this->cells]; |
|
97
|
|
|
if ($this->actionCell) { |
|
98
|
|
|
$nodes[] = $this->actionCell; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return array_merge($nodes, $this->getNodes()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return INode[] |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getNodes(): array |
|
108
|
|
|
{ |
|
109
|
|
|
return []; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
public function __toString(): string |
|
116
|
|
|
{ |
|
117
|
|
|
$content = (string)$this->cells; |
|
118
|
|
|
|
|
119
|
|
|
if ($this->actionCell) { |
|
120
|
|
|
$content .= $this->actionCell; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return TagHelper::toString($this->tag, $content, $this->attributes); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|