|
1
|
|
|
<?php namespace Distilleries\Expendable\States; |
|
2
|
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Contracts\StateDisplayerContract; |
|
4
|
|
|
use Illuminate\Contracts\View\Factory; |
|
5
|
|
|
|
|
6
|
|
|
class StateDisplayer implements StateDisplayerContract { |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
protected $states = []; |
|
10
|
|
|
protected $class = ''; |
|
11
|
|
|
protected $view; |
|
12
|
|
|
public $config; |
|
13
|
|
|
|
|
14
|
288 |
|
public function __construct(Factory $view, array $config) |
|
15
|
|
|
{ |
|
16
|
288 |
|
$this->view = $view; |
|
17
|
288 |
|
$this->config = $config; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string $class |
|
22
|
|
|
*/ |
|
23
|
284 |
|
public function setClass($class) |
|
24
|
|
|
{ |
|
25
|
284 |
|
$this->class = $class; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
29
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
30
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $state |
|
34
|
|
|
*/ |
|
35
|
224 |
|
public function setState($state) |
|
36
|
|
|
{ |
|
37
|
224 |
|
$this->states[] = $state; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $states |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setStates($states) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->states = $states; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
52
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
53
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
224 |
|
public function getRenderStateMenu($template = 'expendable::admin.form.state.menu') |
|
57
|
|
|
{ |
|
58
|
224 |
|
return $this->view->make($template, [ |
|
59
|
224 |
|
'states' => $this->getTableState(), |
|
60
|
224 |
|
'action' => '\\' . $this->class . '@' |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
66
|
|
|
|
|
67
|
224 |
|
protected function getTableState() |
|
68
|
|
|
{ |
|
69
|
224 |
|
$table = []; |
|
70
|
224 |
|
$config = $this->config['state']; |
|
71
|
|
|
|
|
72
|
224 |
|
foreach ($this->states as $state) |
|
73
|
|
|
{ |
|
74
|
|
|
|
|
75
|
224 |
|
if (in_array($state, array_keys($config))) |
|
76
|
|
|
{ |
|
77
|
224 |
|
$table[] = $config[$state]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$table = array_sort($table, function($value) |
|
82
|
|
|
{ |
|
83
|
224 |
|
return $value['position']; |
|
84
|
224 |
|
}); |
|
85
|
|
|
|
|
86
|
224 |
|
return $table; |
|
87
|
|
|
} |
|
88
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..