1: <?php namespace Laravella\Crud;
2:
3: use Illuminate\Support\Facades\Auth;
4: use Illuminate\Support\Facades\DB;
5:
6: 7: 8: 9: 10:
11: class Params extends CrudSeeder {
12:
13: public $action = "";
14: public $tableMeta = null;
15: public $tables = null;
16: public $dataA = array();
17: public $paginated = null;
18: public $primaryTables = array();
19: public $prefix = "";
20: public $tableActionViews = null;
21: public $assets = null;
22: public $view = null;
23: public $skin = null;
24: public $selects = array();
25: public $log = array();
26: public $status = "success";
27: public $slug = "";
28: public $displayType = "text/html";
29: public $displayTypes = array();
30: public $widgetTypes = array();
31: public = array();
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: public function __construct($status, $message, $log, $view = null, $action = "", $tableMeta = null, $tableActionViews = null, $prefix = "", $selects = null, $displayType = "", $dataA = array(), $tables = array(), $paginated = array(), $primaryTables = array())
47: {
48: $this->status = $status;
49: $this->message = $message;
50: $this->action = $action;
51: $this->tableMeta = $tableMeta;
52: if (is_object($view))
53: {
54: $this->pageSize = $view->page_size;
55: }
56: else
57: {
58: $this->pageSize = 10;
59: }
60: $this->prefix = $prefix;
61: $this->tableActionViews = $tableActionViews;
62: $this->view = $view;
63: $this->skin = array('admin'=>Options::get('skin', 'admin'), 'frontend'=>Options::get('skin', 'frontend'));
64: $this->selects = $selects;
65: $this->displayType = $displayType;
66: $this->log = $log;
67:
68: $this->paginated = $paginated;
69: $this->tables = $tables;
70: $this->primaryTables = $primaryTables;
71: $this->assets = $this->__getAssets();
72: $this->dataA = $dataA;
73: $this->displayTypes = $this->__getDisplayTypes();
74: $this->widgetTypes = $this->__getWidgetTypes();
75:
76: if (Auth::check())
77: {
78: $userId = Auth::user()->id;
79: $this->menu = $this->getMenu($userId);
80: }
81: }
82:
83: 84: 85:
86: private function __getAssets() {
87: $assetsA = array();
88: if (isset($this->tableActionViews) && is_object($this->tableActionViews))
89: {
90: $assetType = 'default';
91:
92: $assets = DB::table('_db_page_assets as pa')
93: ->join('_db_option_types as pot', 'pot.id', '=', 'pa.page_type_id')
94: ->join('_db_option_types as aot', 'aot.id', '=', 'pa.asset_type_id')
95: ->join('_db_assets as a', 'a.asset_type_id', '=', 'pa.asset_type_id')
96: ->join('_db_pages as p', 'p.page_type_id', '=', 'pa.page_type_id')
97: ->select('pa.id', 'pa.page_type_id', 'pa.asset_type_id', 'a.id',
98: 'p.id', 'aot.name', 'pot.name', 'a.url', 'a.vendor', 'a.type', 'a.version',
99: 'a.position', 'p.action_id', 'p.view_id', 'p.object_id', 'p.page_size',
100: 'p.title', 'p.slug')
101:
102: ->where('pot.name', $this->tableActionViews->view_name)
103: ->where('p.slug', '_db_actions_getselect')
104: ->get();
105:
106:
107:
108:
109:
110:
111: foreach($assets as $asset) {
112: $assetsA[] = array('url'=>$asset->type."/".$asset->url, 'type'=>$asset->type, 'position'=>$asset->position);
113: }
114: }
115:
116: return $assetsA;
117: }
118:
119: 120: 121: 122: 123: 124:
125: private function __getDisplayTypes() {
126: $displayTypes = DB::table('_db_display_types')->get();
127: $dtA = array();
128: foreach($displayTypes as $displayType) {
129: $dtA[$displayType->id] = $displayType->name;
130: }
131: return $dtA;
132: }
133:
134: 135: 136: 137: 138: 139:
140: private function __getWidgetTypes() {
141: $widgetTypes = DB::table('_db_widget_types')->get();
142: $dtA = array();
143: foreach($widgetTypes as $widgetType) {
144: $dtA[$widgetType->id] = $widgetType->name;
145: }
146: return $dtA;
147: }
148:
149: 150: 151: 152: 153:
154: public static function ($userId = null) {
155: if ($userId == null) {
156: $userId = Auth::user()->id;
157: }
158:
159: $menus = DB::table('users as u')->join('usergroups as ug', 'u.usergroup_id', '=', 'ug.id')
160: ->join('_db_menu_permissions as mp', 'mp.usergroup_id', '=', 'ug.id')
161: ->join('_db_menus as m', 'm.id', '=', 'mp.menu_id')
162: ->join('_db_menus as m2', 'm2.parent_id', '=', 'm.id')
163: ->where('u.id', '=', $userId)
164: ->select('u.username', 'ug.group',
165: 'm.id', 'm.icon_class', 'm.label', 'm.href', 'm.parent_id',
166: 'm2.id as m2_id', 'm2.icon_class as m2_icon_class', 'm2.label as m2_label',
167: 'm2.href as m2_href', 'm2.parent_id as m2_parent_id')->get();
168:
169:
170:
171: $menuA = array();
172: foreach($menus as $menu) {
173: if (!isset($menuA[$menu->label])) {
174: $menuA[$menu->label] = array();
175: }
176: $menuA[$menu->label][] = array('username'=>$menu->username, 'group'=>$menu->group,
177: 'id'=>$menu->id, 'icon_class'=>$menu->icon_class, 'label'=>$menu->label,
178: 'href'=>$menu->href, 'parent_id'=>$menu->parent_id, 'm2_id'=>$menu->m2_id,
179: 'm2_icon_class'=>$menu->m2_icon_class, 'm2_label'=>$menu->m2_label,
180: 'm2_href'=>$menu->m2_href, 'm2_parent_id'=>$menu->m2_parent_id);
181: }
182: return $menuA;
183: }
184:
185: 186: 187: 188: 189: 190:
191: public function ($userId=null)
192: {
193: return static::getUserMenu($userId);
194: }
195:
196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212:
213: public static function forEdit($status = "success", $message = "", $log = array(), $view = null, $action = "", $tableMeta = null, $tableActionViews = null, $prefix = "", $selects = null, $displayType = "text/html", $tables = null, $paginated = null, $primaryTables = null)
214: {
215: $params = new Params($status, $message, $log);
216: return $params;
217: }
218:
219: 220: 221: 222: 223: 224: 225:
226: public function asArray()
227: {
228: $returnA = array("action" => $this->action,
229: "meta" => $this->tableMeta['fields_array'],
230: "tableName" => $this->tableMeta['table']['name'],
231: "prefix" => $this->prefix,
232: "pageSize" => $this->pageSize,
233: "view" => $this->view,
234: "skin" => $this->skin,
235: "slug" => $this->slug,
236: "selects" => $this->selects,
237: "log" => $this->log,
238: "status" => $this->status,
239: "message" => $this->message,
240: "pkName" => $this->tableMeta['table']['pk_name'],
241: "displayType" => $this->displayType,
242: "tables" => $this->tables,
243: "data" => $this->paginated,
244: "dataA" => $this->dataA,
245: "pkTables" => $this->primaryTables,
246: "menu" => $this->menu,
247: "assets" => $this->assets,
248: "displayTypes" => $this->displayTypes,
249: "widgetTypes" => $this->widgetTypes
250: );
251:
252: if (isset($this->tableActionViews) && is_object($this->tableActionViews))
253: {
254: $returnA["title"] = $this->tableActionViews->title;
255: }
256: else
257: {
258: $returnA["title"] = "";
259: }
260:
261: if (Options::get('debug')){
262: $returnA['params'] = json_encode($returnA);
263: }
264:
265: return $returnA;
266: }
267:
268: }
269:
270: ?>
271: