|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Table\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Yaro\Jarboe\Table\CRUD; |
|
6
|
|
|
|
|
7
|
|
|
abstract class AbstractAction implements ActionInterface |
|
8
|
|
|
{ |
|
9
|
|
|
protected $ident; |
|
10
|
|
|
protected $checkClosure; |
|
11
|
|
|
protected $renderClosure = false; |
|
12
|
|
|
private $crud; |
|
13
|
|
|
private $tooltip = null; |
|
14
|
|
|
private $tooltipPosition = ActionInterface::TOOLTIP_POSITION_TOP; |
|
15
|
|
|
|
|
16
|
113 |
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->checkClosure = function () { |
|
19
|
36 |
|
return true; |
|
20
|
|
|
}; |
|
21
|
113 |
|
} |
|
22
|
|
|
|
|
23
|
113 |
|
public static function make() |
|
24
|
|
|
{ |
|
25
|
113 |
|
return new static(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
81 |
|
public function setCrud(CRUD $crud) |
|
29
|
|
|
{ |
|
30
|
81 |
|
$this->crud = $crud; |
|
31
|
81 |
|
} |
|
32
|
|
|
|
|
33
|
24 |
|
public function crud(): CRUD |
|
34
|
|
|
{ |
|
35
|
24 |
|
return $this->crud; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
49 |
|
public function identifier() |
|
39
|
|
|
{ |
|
40
|
49 |
|
return $this->ident ?: static::class; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
14 |
|
public function check(\Closure $closure = null) |
|
44
|
|
|
{ |
|
45
|
14 |
|
$this->checkClosure = $closure; |
|
46
|
|
|
|
|
47
|
14 |
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
44 |
|
public function isAllowed($model = null) |
|
51
|
|
|
{ |
|
52
|
44 |
|
$closure = $this->checkClosure; |
|
53
|
|
|
|
|
54
|
44 |
|
return is_callable($closure) ? call_user_func_array($closure, [$model]) : false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
6 |
|
public function renderCheck(\Closure $closure = null) |
|
58
|
|
|
{ |
|
59
|
6 |
|
$this->renderClosure = $closure; |
|
60
|
|
|
|
|
61
|
6 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
13 |
|
public function shouldRender($model = null) |
|
65
|
|
|
{ |
|
66
|
13 |
|
$closure = $this->renderClosure; |
|
67
|
13 |
|
if ($closure === false) { |
|
68
|
13 |
|
return $this->isAllowed($model); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
6 |
|
return is_callable($closure) ? call_user_func_array($closure, [$model]) : false; |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
5 |
|
public function tooltip(string $tooltip, string $position = ActionInterface::TOOLTIP_POSITION_TOP): ActionInterface |
|
75
|
|
|
{ |
|
76
|
5 |
|
$this->tooltip = $tooltip; |
|
77
|
5 |
|
$this->tooltipPosition = $position; |
|
78
|
|
|
|
|
79
|
5 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
5 |
|
public function getTooltip() |
|
83
|
|
|
{ |
|
84
|
5 |
|
return $this->tooltip; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
5 |
|
public function getTooltipPosition(): string |
|
88
|
|
|
{ |
|
89
|
5 |
|
switch ($this->tooltipPosition) { |
|
90
|
5 |
|
case self::TOOLTIP_POSITION_TOP: |
|
91
|
5 |
|
case self::TOOLTIP_POSITION_RIGHT: |
|
92
|
5 |
|
case self::TOOLTIP_POSITION_BOTTOM: |
|
93
|
5 |
|
case self::TOOLTIP_POSITION_LEFT: |
|
94
|
5 |
|
return $this->tooltipPosition; |
|
95
|
|
|
|
|
96
|
|
|
default: |
|
97
|
5 |
|
return self::TOOLTIP_POSITION_TOP; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|