1
|
|
|
<?php namespace Mascame\Artificer; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Mascame\Artificer\Fields\FieldWrapper; |
5
|
|
|
use Mascame\Artificer\Http\Controllers\BaseController; |
6
|
|
|
use Mascame\Artificer\Http\Controllers\BaseModelController; |
7
|
|
|
use Mascame\Artificer\Model\Model; |
8
|
|
|
|
9
|
|
|
class Artificer |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Returns the current user's action. |
14
|
|
|
* |
15
|
|
|
* @return null|string |
16
|
|
|
*/ |
17
|
|
|
public static function getCurrentAction() |
18
|
|
|
{ |
19
|
|
|
switch (\Route::currentRouteName()) { |
20
|
|
|
case 'admin.model.create': |
21
|
|
|
return 'create'; |
22
|
|
|
case 'admin.model.edit': |
23
|
|
|
return 'edit'; |
24
|
|
|
case 'admin.model.show': |
25
|
|
|
return 'show'; |
26
|
|
|
case 'admin.model.all': |
27
|
|
|
case 'admin.model.filter': |
28
|
|
|
return 'list'; |
29
|
|
|
default: |
30
|
|
|
return null; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return Model |
36
|
|
|
*/ |
37
|
|
|
public static function getModel() |
38
|
|
|
{ |
39
|
|
|
return App::make('ArtificerModel'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \Mascame\Artificer\Plugin\Manager |
44
|
|
|
*/ |
45
|
|
|
public static function pluginManager() |
46
|
|
|
{ |
47
|
|
|
return App::make('ArtificerPluginManager'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \Mascame\Artificer\Widget\Manager |
52
|
|
|
*/ |
53
|
|
|
public static function widgetManager() |
54
|
|
|
{ |
55
|
|
|
return App::make('ArtificerWidgetManager'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function assets() |
59
|
|
|
{ |
60
|
|
|
$widgets = ''; |
61
|
|
|
|
62
|
|
|
foreach (FieldWrapper::$widgets as $widget) { |
63
|
|
|
$widgets .= $widget->output(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $widgets; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function getCurrentModelId($items) |
70
|
|
|
{ |
71
|
|
|
return BaseModelController::getCurrentModelId($items); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public static function addMenu($options) |
76
|
|
|
{ |
77
|
|
|
return config(['admin.menu' => array_merge(self::getMenu(), $options)]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected static function getMenu() |
81
|
|
|
{ |
82
|
|
|
return config('admin.menu'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected static function getProviders() |
86
|
|
|
{ |
87
|
|
|
return config('admin.providers'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Use it only for third party Service Providers |
92
|
|
|
* (Your main Service provider must be already declared for this to work) |
93
|
|
|
* |
94
|
|
|
* @param $provider |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public static function addServiceProvider($provider) |
98
|
|
|
{ |
99
|
|
|
return config(['admin.providers' => array_merge(self::getProviders(), [$provider])]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param $plugin |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
// public static function getPlugin($plugin) |
108
|
|
|
// { |
109
|
|
|
// return with(App::make('ArtificerPluginManager'))->make($plugin); |
110
|
|
|
// } |
111
|
|
|
|
112
|
|
|
// Todo is it used anywhere? |
113
|
|
|
// public static function store($filepath = null, $content, $overide = false) |
114
|
|
|
// { |
115
|
|
|
// if (!$filepath) { |
116
|
|
|
// $pathinfo = pathinfo($filepath); |
117
|
|
|
// $filepath = $pathinfo['dirname']; |
118
|
|
|
// } |
119
|
|
|
// |
120
|
|
|
// $path = explode('/', $filepath); |
121
|
|
|
// array_pop($path); |
122
|
|
|
// $path = join('/', $path); |
123
|
|
|
// |
124
|
|
|
// if (!file_exists($path)) { |
125
|
|
|
// \File::makeDirectory($path, 0777, true, true); |
126
|
|
|
// } |
127
|
|
|
// |
128
|
|
|
// if (!file_exists($filepath) || $overide) { |
129
|
|
|
// return \File::put($filepath, $content); |
130
|
|
|
// } |
131
|
|
|
// |
132
|
|
|
// return false; |
133
|
|
|
// } |
134
|
|
|
} |