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
|
|
|
use Mascame\Artificer\Widget\AbstractWidget; |
9
|
|
|
use Mascame\Artificer\Widget\WidgetInterface; |
10
|
|
|
|
11
|
|
|
class Artificer |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Returns the current user's action. |
16
|
|
|
* |
17
|
|
|
* @return null|string list, edit, create, show |
18
|
|
|
*/ |
19
|
|
|
public static function getCurrentAction() |
20
|
|
|
{ |
21
|
|
|
switch (\Route::currentRouteName()) { |
22
|
|
|
case 'admin.model.create': |
23
|
|
|
return 'create'; |
24
|
|
|
case 'admin.model.edit': |
25
|
|
|
return 'edit'; |
26
|
|
|
case 'admin.model.show': |
27
|
|
|
return 'show'; |
28
|
|
|
case 'admin.model.all': |
29
|
|
|
case 'admin.model.filter': |
30
|
|
|
return 'list'; |
31
|
|
|
default: |
32
|
|
|
return null; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return Model |
38
|
|
|
*/ |
39
|
|
|
public static function getModel() |
40
|
|
|
{ |
41
|
|
|
return App::make('ArtificerModel'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return \Mascame\Artificer\Plugin\Manager |
46
|
|
|
*/ |
47
|
|
|
public static function pluginManager() |
48
|
|
|
{ |
49
|
|
|
return App::make('ArtificerPluginManager'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return \Mascame\Artificer\Widget\Manager |
54
|
|
|
*/ |
55
|
|
|
public static function widgetManager() |
56
|
|
|
{ |
57
|
|
|
return App::make('ArtificerWidgetManager'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Todo: only output assets of installed widgets |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public static function assets() |
66
|
|
|
{ |
67
|
|
|
// $assets = [ |
68
|
|
|
// 'styles' => [], |
69
|
|
|
// 'scripts' => [], |
70
|
|
|
// ]; |
71
|
|
|
// |
72
|
|
|
// /** |
73
|
|
|
// * @var $widget AbstractWidget |
74
|
|
|
// */ |
75
|
|
|
// foreach (FieldWrapper::$widgets as $widget) { |
76
|
|
|
// if ($widget->isInstalled()) { |
77
|
|
|
// $assets['styles'][] = $widget->getStyles(); |
78
|
|
|
// $assets['scripts'][] = $widget->getScripts(); |
79
|
|
|
// } |
80
|
|
|
// } |
81
|
|
|
|
82
|
|
|
\Assets::add('filename.css'); |
83
|
|
|
|
84
|
|
|
// return $assets; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
protected static function buildStyles($styles) { |
|
|
|
|
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected static function buildScripts($scripts) { |
92
|
|
|
|
93
|
|
|
foreach ($scripts as $script) { |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public static function getCurrentModelId($items) |
99
|
|
|
{ |
100
|
|
|
return BaseModelController::getCurrentModelId($items); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public static function addMenu($options) |
105
|
|
|
{ |
106
|
|
|
return config(['admin.menu' => array_merge(self::getMenu(), $options)]); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
protected static function getMenu() |
110
|
|
|
{ |
111
|
|
|
return config('admin.menu'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param $plugin |
116
|
|
|
* @return mixed |
117
|
|
|
*/ |
118
|
|
|
// public static function getPlugin($plugin) |
119
|
|
|
// { |
120
|
|
|
// return with(App::make('ArtificerPluginManager'))->make($plugin); |
121
|
|
|
// } |
122
|
|
|
|
123
|
|
|
// Todo is it used anywhere? |
124
|
|
|
// public static function store($filepath = null, $content, $overide = false) |
125
|
|
|
// { |
126
|
|
|
// if (!$filepath) { |
127
|
|
|
// $pathinfo = pathinfo($filepath); |
128
|
|
|
// $filepath = $pathinfo['dirname']; |
129
|
|
|
// } |
130
|
|
|
// |
131
|
|
|
// $path = explode('/', $filepath); |
132
|
|
|
// array_pop($path); |
133
|
|
|
// $path = join('/', $path); |
134
|
|
|
// |
135
|
|
|
// if (!file_exists($path)) { |
136
|
|
|
// \File::makeDirectory($path, 0777, true, true); |
137
|
|
|
// } |
138
|
|
|
// |
139
|
|
|
// if (!file_exists($filepath) || $overide) { |
140
|
|
|
// return \File::put($filepath, $content); |
141
|
|
|
// } |
142
|
|
|
// |
143
|
|
|
// return false; |
144
|
|
|
// } |
145
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.