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