|
1
|
|
|
<?php |
|
2
|
|
|
namespace Serverfireteam\Panel; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Routing\Controller; |
|
5
|
|
|
|
|
6
|
|
|
class CrudController extends Controller |
|
7
|
|
|
{ |
|
8
|
|
|
const ID_COLUMN = 'id'; |
|
9
|
|
|
|
|
10
|
|
|
public $grid; |
|
11
|
|
|
public $entity; |
|
12
|
|
|
public $set; |
|
13
|
|
|
public $edit; |
|
14
|
|
|
public $filter; |
|
15
|
|
|
protected $lang; |
|
16
|
|
|
public $helper_message; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(\Lang $lang) |
|
19
|
|
|
{ |
|
20
|
|
|
// $this->entity = $params['entity']; |
|
21
|
|
|
$route = \App::make('route'); |
|
22
|
|
|
$this->lang = $lang; |
|
23
|
|
|
$this->route = $route; |
|
|
|
|
|
|
24
|
|
|
$routeParamters = $route::current()->parameters(); |
|
25
|
|
|
$this->setEntity($routeParamters['entity']); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $entity name of the entity |
|
30
|
|
|
*/ |
|
31
|
|
|
public function all($entity) |
|
32
|
|
|
{ |
|
33
|
|
|
//$this->addStylesToGrid(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $entity name of the entity |
|
38
|
|
|
*/ |
|
39
|
|
|
public function edit($entity) |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getEntity() { |
|
45
|
|
|
return $this->entity; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setEntity($entity) { |
|
49
|
|
|
$this->entity = $entity; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getEntityModel() { |
|
53
|
|
|
|
|
54
|
|
|
$entity = $this->getEntity(); |
|
55
|
|
|
|
|
56
|
|
|
$appHelper = new libs\AppHelper; |
|
57
|
|
|
|
|
58
|
|
|
if ( in_array($entity, Link::getMainUrls()) ) { |
|
59
|
|
|
$modelClass = 'Serverfireteam\\Panel\\'.$entity; |
|
60
|
|
|
} else { |
|
61
|
|
|
$modelClass = $appHelper->getNameSpace().$this->getEntity(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return new $modelClass; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function addStylesToGrid($orderByColumn = self::ID_COLUMN, $paginateCount = 10) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->grid->edit('edit', trans('panel::fields.edit'), 'show|modify|delete'); |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
if ($orderByColumn === self::ID_COLUMN) { |
|
73
|
|
|
$orderByColumn = $this->getEntityModel()->getKeyName(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->grid->orderBy($orderByColumn, 'desc'); |
|
77
|
|
|
$this->grid->paginate($paginateCount); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function addHelperMessage($message) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->helper_message = $message; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function returnView() |
|
86
|
|
|
{ |
|
87
|
|
|
$configs = \Serverfireteam\Panel\Link::returnUrls(); |
|
88
|
|
|
|
|
89
|
|
|
if (!isset($configs) || $configs == null) { |
|
90
|
|
|
throw new \Exception('NO URL is set yet !'); |
|
91
|
|
|
} else if (!in_array($this->entity, $configs)) { |
|
92
|
|
|
throw new \Exception('This url is not set yet!'); |
|
93
|
|
|
} else { |
|
94
|
|
|
return \View::make('panelViews::all', array( |
|
95
|
|
|
'grid' => $this->grid, |
|
96
|
|
|
'filter' => $this->filter, |
|
97
|
|
|
'title' => $this->entity , |
|
98
|
|
|
'current_entity' => $this->entity, |
|
99
|
|
|
'import_message' => (\Session::has('import_message')) ? \Session::get('import_message') : '' |
|
100
|
|
|
)); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function returnEditView() |
|
105
|
|
|
{ |
|
106
|
|
|
$configs = \Serverfireteam\Panel\Link::returnUrls(); |
|
107
|
|
|
|
|
108
|
|
|
if (!isset($configs) || $configs == null) { |
|
109
|
|
|
throw new \Exception('NO URL is set yet !'); |
|
110
|
|
|
} else if (!in_array($this->entity, $configs)) { |
|
111
|
|
|
throw new \Exception('This url is not set yet !'); |
|
112
|
|
|
} else { |
|
113
|
|
|
return \View::make('panelViews::edit', array('title' => $this->entity, |
|
114
|
|
|
'edit' => $this->edit, |
|
115
|
|
|
'helper_message' => $this->helper_message)); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function finalizeFilter() { |
|
120
|
|
|
$lang = \App::make('lang'); |
|
|
|
|
|
|
121
|
|
|
$this->filter->submit($this->lang->get('panel::fields.search')); |
|
122
|
|
|
$this->filter->reset($this->lang->get('panel::fields.reset')); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.