Overview

Namespaces

  • Composer
    • Autoload
  • Illuminate
    • Support
      • Contracts
      • Facades
  • Laravella
    • Crud
      • Exceptions
      • Facades
  • None
  • PHP

Classes

  • CrudDatabaseSeeder
  • CrudInstallCommand
  • CrudSeeder
  • CrudServiceProvider
  • CrudUpdateCommand
  • DbGopher
  • Log
  • Options
  • Params
  • PostCrudSeeder
  • SeedActions
  • SeedAssets
  • SeedGroups
  • SeedLogs
  • SeedMenus
  • SeedObjects
  • SeedOptions
  • SeedPageTypes
  • SeedSeverities
  • SeedTables
  • SeedUsergroups
  • SeedUsers
  • SeedViews
  • UpdateCMSFields
  • UpdateReferences
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php namespace Laravella\Crud;
  2: 
  3: use Illuminate\Support\Facades\Auth;
  4: use Illuminate\Support\Facades\DB;
  5: 
  6: /**
  7:  * 
  8:  * Used to pass a consistent set of data to views and prevent "$variable not found" errors.
  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 $menu = array();
 32: 
 33:     /**
 34:      * 
 35:      * Used to pass a consistent set of data to views and prevent "$variable not found" errors.
 36:      * 
 37:      * @param type $status Wether the action succeeded or not.  See log for further details.
 38:      * @param type $action the action that controller is performing. See _db_actions.name 
 39:      * @param type $tableMeta The table's meta data. As generated by Laravella\Crud\Table::getTableMeta()
 40:      * @param type $tables Is an array of Table objects. Actual data.
 41:      * @param type $pageSize. The size of the pagination.
 42:      * @param type $primaryTables A list of records with primary keys related to this table's via foreign keys.
 43:      * @param type $prefix Used to prepend the href on the primary key
 44:      * @param type $view An entry in _db_views
 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;  //single, called by first()
 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:         //potentially null
 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: //            ->where('pa.page_type_id', $this->tableActionViews->page_type_id)
102:             ->where('pot.name', $this->tableActionViews->view_name)
103:             ->where('p.slug', '_db_actions_getselect')
104:             ->get();
105:             
106: //            $queries = DB::getQueryLog();
107: //            $last_query = end($queries);
108: //            echo var_dump($last_query);
109: //            die;
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:      * get all entries from _db_display_types
121:      * This determines under which conditions a field will be displayed
122:      * 
123:      * @return type
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:      * get all entries from _db_widget_types
136:      * This determines how a field will be displayed, what it will look like
137:      * 
138:      * @return type
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:      * @param type $userId
152:      * @return type
153:      */
154:     public static function getUserMenu ($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:      * Build a menu array from _db_menus
187:      * 
188:      * @param type $userId
189:      * @return type
190:      */
191:     public function getMenu($userId=null)
192:     {
193:         return static::getUserMenu($userId);
194:     }
195: 
196:     /**
197:      * Instantiate a Params object to use for Editing
198:      * 
199:      * @param type $status
200:      * @param type $message
201:      * @param type $log
202:      * @param type $view
203:      * @param type $action
204:      * @param type $tableMeta
205:      * @param type $tableActionViews
206:      * @param type $prefix
207:      * @param type $selects
208:      * @param type $tables
209:      * @param type $paginated
210:      * @param type $primaryTables
211:      * @return \Laravella\Crud\Params
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:      * meta
221:      * data
222:      * name
223:      * pagesize
224:      * selects
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:         ); //$this->tables[$tableName]['tableMetaData']['table']['pk_name']);
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: 
crud API documentation generated by ApiGen 2.8.0