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