1
|
|
|
<?php namespace Mascame\Artificer\Controllers; |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use Illuminate\Database\Eloquent\Collection; |
5
|
|
|
use Illuminate\Support\Facades\Input; |
6
|
|
|
use Mascame\Artificer\Fields\FieldFactory; |
7
|
|
|
use Mascame\Formality\Parser\Parser; |
8
|
|
|
use View; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class BaseModelController extends BaseController |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The Eloquent model instance |
16
|
|
|
* @var \Eloquent |
17
|
|
|
*/ |
18
|
|
|
protected $model; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
parent::__construct(); |
26
|
|
|
|
27
|
|
|
$this->model = $this->modelObject->model; |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param $data |
32
|
|
|
*/ |
33
|
|
|
protected function handleData($data) |
34
|
|
|
{ |
35
|
|
|
$this->data = $data; |
36
|
|
|
|
37
|
|
|
$this->getFields($data); |
38
|
|
|
|
39
|
|
|
View::share('data', $this->data); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param $data |
44
|
|
|
* @return null |
45
|
|
|
*/ |
46
|
|
|
protected function getFields($data) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
if ($this->fields) return $this->fields; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var $data Collection |
52
|
|
|
*/ |
53
|
|
|
$modelFields = $this->modelObject->getOption('fields'); |
54
|
|
|
$types = config('admin.fields.types'); |
55
|
|
|
$fields = []; |
56
|
|
|
|
57
|
|
|
foreach ($this->modelObject->columns as $column) { |
58
|
|
|
$options = []; |
59
|
|
|
|
60
|
|
|
if (isset($modelFields[$column])) $options = $modelFields[$column]; |
61
|
|
|
|
62
|
|
|
$fields[$column] = $options; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$fieldFactory = new FieldFactory(new Parser($types), $types, $fields, config('admin.fields.classmap')); |
66
|
|
|
$this->fields = $fieldFactory->makeFields(); |
67
|
|
|
|
68
|
|
|
View::share('fields', $this->fields); |
69
|
|
|
|
70
|
|
|
return $this->fields; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
protected function getSort() |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
|
|
'column' => Input::get('sort_by', 'id'), |
80
|
|
|
'direction' => Input::get('direction', 'asc'), |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $items |
86
|
|
|
* @return null |
87
|
|
|
*/ |
88
|
|
|
public static function getCurrentModelId($items) |
89
|
|
|
{ |
90
|
|
|
return (isset($items->id)) ? $items->id : null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param $modelName |
95
|
|
|
* @param null $data |
96
|
|
|
* @param $sort |
97
|
|
|
*/ |
98
|
|
|
protected function all($modelName, $data = null, $sort) |
99
|
|
|
{ |
100
|
|
|
$this->handleData($data); |
101
|
|
|
|
102
|
|
|
return View::make($this->getView('all')) |
103
|
|
|
->with('items', $this->data) |
104
|
|
|
->with('sort', $sort); |
105
|
|
|
} |
106
|
|
|
} |
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..