1
|
|
|
<?php namespace Mascame\Artificer\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Auth; |
5
|
|
|
use Illuminate\Support\Facades\Input; |
6
|
|
|
use Mascame\Artificer\Artificer; |
7
|
|
|
use Mascame\Artificer\Fields\FieldWrapper; |
8
|
|
|
use Mascame\Artificer\Model\Model; |
9
|
|
|
use View; |
10
|
|
|
use Illuminate\Routing\Controller as Controller; |
11
|
|
|
use Mascame\Artificer\Options\AdminOption; |
12
|
|
|
use Mascame\Artificer\Permit; |
13
|
|
|
|
14
|
|
|
// Todo: Make some models forbidden for some users |
15
|
|
|
|
16
|
|
|
class BaseController extends Controller |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public $fields; |
20
|
|
|
public $data; |
21
|
|
|
public $options; |
22
|
|
|
|
23
|
|
|
public static $routes; |
24
|
|
|
|
25
|
|
|
public $theme; |
26
|
|
|
public $standalone; |
27
|
|
|
public $menu = array(); |
28
|
|
|
protected $master_layout = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Model |
32
|
|
|
*/ |
33
|
|
|
public $modelObject = null; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
$this->theme = AdminOption::get('theme') . '::'; |
39
|
|
|
$this->master_layout = 'base'; |
40
|
|
|
|
41
|
|
|
// Todo: Do Sth with this |
42
|
|
|
if (UserController::check() || true) { |
43
|
|
|
$this->options = AdminOption::all(); |
44
|
|
|
|
45
|
|
|
$this->modelObject = Artificer::getModel(); |
46
|
|
|
|
47
|
|
|
if ($this->isStandAlone()) { |
48
|
|
|
$this->master_layout = 'standalone'; |
49
|
|
|
$this->standalone = true; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->shareMainViewData(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function shareMainViewData() |
57
|
|
|
{ |
58
|
|
|
View::share('main_title', AdminOption::get('title')); |
59
|
|
|
View::share('menu', $this->getMenu()); |
60
|
|
|
View::share('theme', $this->theme); |
61
|
|
|
View::share('layout', $this->theme . '.' . $this->master_layout); |
62
|
|
|
View::share('fields', array()); |
63
|
|
|
View::share('standalone', $this->standalone); |
64
|
|
|
View::share('icon', AdminOption::get('icons')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
public function isStandAlone() |
71
|
|
|
{ |
72
|
|
|
return (\Request::ajax() || Input::has('_standalone')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function getMenu() |
79
|
|
|
{ |
80
|
|
|
if ( ! empty($this->menu)) return $this->menu; |
81
|
|
|
|
82
|
|
|
$menu = AdminOption::get('menu'); |
83
|
|
|
|
84
|
|
|
foreach ($menu as $key => $menuItem) { |
85
|
|
|
// Todo: Permit is absolete or not? |
86
|
|
|
if (Permit\MenuPermit::access($key) || true) { |
87
|
|
|
$this->menu[] = $menuItem; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $this->menu; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $view |
96
|
|
|
*/ |
97
|
|
|
public function getView($view) |
98
|
|
|
{ |
99
|
|
|
return $this->theme . $view; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |