|
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
|
152 |
|
public function __construct(Factory $view, array $config) |
|
15
|
|
|
{ |
|
16
|
152 |
|
$this->view = $view; |
|
17
|
152 |
|
$this->config = $config; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string $class |
|
22
|
|
|
*/ |
|
23
|
150 |
|
public function setClass($class) |
|
24
|
|
|
{ |
|
25
|
150 |
|
$this->class = $class; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
29
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
30
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $state |
|
34
|
|
|
*/ |
|
35
|
120 |
|
public function setState($state) |
|
36
|
|
|
{ |
|
37
|
120 |
|
$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
|
120 |
|
public function getRenderStateMenu($template = 'expendable::admin.form.state.menu') |
|
57
|
|
|
{ |
|
58
|
120 |
|
return $this->view->make($template, [ |
|
59
|
120 |
|
'states' => $this->getTableState(), |
|
60
|
120 |
|
'action' => '\\'.$this->class.'@' |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
66
|
|
|
|
|
67
|
120 |
|
protected function getTableState() |
|
68
|
|
|
{ |
|
69
|
120 |
|
$table = []; |
|
70
|
120 |
|
$config = $this->config['state']; |
|
71
|
|
|
|
|
72
|
120 |
|
foreach ($this->states as $state) |
|
73
|
|
|
{ |
|
74
|
|
|
|
|
75
|
120 |
|
if (in_array($state, array_keys($config))) |
|
76
|
|
|
{ |
|
77
|
120 |
|
$table[] = $config[$state]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$table = array_sort($table, function($value) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
120 |
|
return $value['position']; |
|
84
|
120 |
|
}); |
|
85
|
|
|
|
|
86
|
120 |
|
return $table; |
|
87
|
|
|
} |
|
88
|
|
|
} |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.