1
|
|
|
<?php namespace Anomaly\Streams\Platform\Field\Table; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; |
4
|
|
|
use Anomaly\Streams\Platform\Ui\Table\TableBuilder; |
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class FieldTableBuilder |
9
|
|
|
* |
10
|
|
|
* @link http://pyrocms.com/ |
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
12
|
|
|
* @author Ryan Thompson <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class FieldTableBuilder extends TableBuilder |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The locked flag. |
19
|
|
|
* |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $locked = false; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The related stream instance. |
26
|
|
|
* |
27
|
|
|
* @var null|StreamInterface |
28
|
|
|
*/ |
29
|
|
|
protected $stream = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The stream namespace. |
33
|
|
|
* |
34
|
|
|
* @var null|string |
35
|
|
|
*/ |
36
|
|
|
protected $namespace = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The table model. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $model = 'Anomaly\Streams\Platform\Field\FieldModel'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The table filters. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $filters = [ |
51
|
|
|
'search' => [ |
52
|
|
|
'columns' => [ |
53
|
|
|
'name', |
54
|
|
|
'slug', |
55
|
|
|
], |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The table columns. |
61
|
|
|
* |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
protected $columns = [ |
65
|
|
|
[ |
66
|
|
|
'heading' => 'streams::field.name.name', |
67
|
|
|
'value' => 'entry.name', |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'heading' => 'streams::field.slug.name', |
71
|
|
|
'value' => 'entry.slug', |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
'heading' => 'streams::field.type.name', |
75
|
|
|
'wrapper' => '{value}::addon.name', |
76
|
|
|
'value' => 'entry.type', |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* The table buttons. |
82
|
|
|
* |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
protected $buttons = [ |
86
|
|
|
'edit', |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* The table actions. |
91
|
|
|
* |
92
|
|
|
* @var array |
93
|
|
|
*/ |
94
|
|
|
protected $actions = [ |
95
|
|
|
'prompt', |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* The table options. |
100
|
|
|
* |
101
|
|
|
* @var array |
102
|
|
|
*/ |
103
|
|
|
protected $options = [ |
104
|
|
|
'order_by' => [ |
105
|
|
|
'slug' => 'ASC', |
106
|
|
|
], |
107
|
|
|
]; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Limit to the stream's namespace. |
111
|
|
|
* |
112
|
|
|
* @param Builder $query |
113
|
|
|
*/ |
114
|
|
|
public function onQuerying(Builder $query) |
115
|
|
|
{ |
116
|
|
|
$query->where('namespace', $this->getStream() ? $this->getStreamNamespace() : $this->getNamespace()); |
117
|
|
|
|
118
|
|
|
if (($locked = $this->getLocked()) !== null) { |
119
|
|
|
$query->where('locked', $locked); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get the lock flag. |
125
|
|
|
* |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function getLocked() |
129
|
|
|
{ |
130
|
|
|
return $this->locked; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Set the lock flag. |
135
|
|
|
* |
136
|
|
|
* @param $locked |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function setLocked($locked) |
140
|
|
|
{ |
141
|
|
|
$this->locked = $locked; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the stream. |
148
|
|
|
* |
149
|
|
|
* @return StreamInterface|null |
150
|
|
|
*/ |
151
|
|
|
public function getStream() |
152
|
|
|
{ |
153
|
|
|
return $this->stream; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Return the related stream's namespace. |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
protected function getStreamNamespace() |
162
|
|
|
{ |
163
|
|
|
$stream = $this->getStream(); |
164
|
|
|
|
165
|
|
|
return $stream->getNamespace(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Set the stream. |
170
|
|
|
* |
171
|
|
|
* @param StreamInterface $stream |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function setStream(StreamInterface $stream) |
175
|
|
|
{ |
176
|
|
|
$this->stream = $stream; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get the namespace. |
183
|
|
|
* |
184
|
|
|
* @return null|string |
185
|
|
|
*/ |
186
|
|
|
public function getNamespace() |
187
|
|
|
{ |
188
|
|
|
return $this->namespace; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set the namespace. |
193
|
|
|
* |
194
|
|
|
* @param $namespace |
195
|
|
|
* @return $this |
196
|
|
|
*/ |
197
|
|
|
public function setNamespace($namespace) |
198
|
|
|
{ |
199
|
|
|
$this->namespace = $namespace; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|