/** * return panel config as seen from user perspective. * elements are filtered down to only the ones visible to this user. * * @param string $panel_name * @param string $letter // of CRUDL * @param string $subpanel_parent // parent panel name * @return array or false // if user does not have access */ public function user_scope($panel_name, $letter = 'L', $subpanel_parent = FALSE) { $ret = array(); $panels = $this->all_by_group(); $primary_role = App::runningInConsole() ? 'admin' : Session::get('user_data.primary_group'); $has_panel_access = FALSE; $has_parent_access = FALSE; if (!$primary_role) { $primary_role = 'anon'; } if ($subpanel_parent) { // does user have access to the parent panel 'U' method? $has_parent_access = isset($panels[$primary_role]['panels'][$subpanel_parent]['permissions']) && strpos($panels[$primary_role]['panels'][$subpanel_parent]['permissions'], 'U') !== FALSE; } else { $has_panel_access = isset($panels[$primary_role]['panels'][$panel_name]['permissions']) && strpos($panels[$primary_role]['panels'][$panel_name]['permissions'], $letter) !== FALSE; } if ($has_panel_access || $has_parent_access) { // can access panel AND can perform $letter method $ret['registry'] = isset($panels[$primary_role]['panels'][$panel_name]) ? $panels[$primary_role]['panels'][$panel_name] : ''; $ret['config'] = StationConfig::panel($panel_name); // start with the whole config! $ret['config']['elements'] = $this->elements_for_letter($ret['config'], $letter); // but filter the elements. $ret['config']['elements'] = $this->inject_vars_for_elements($ret['config']['elements']); if (count($ret['config']['elements']) == 0) { return FALSE; } // no elements, no access for you! return $ret; } return FALSE; }
private function model_code($is_new = FALSE, $modelName, $tableName, $panel_data) { $panel = new Panel(); $code = ""; $code .= $is_new ? "<?php namespace App\\Models; \n\n" . "class {$modelName} extends \\Eloquent {\n\t" : ""; $code .= $this->gen_begin . "\n\n\t" . "protected \$table = '{$tableName}';\n\tprotected \$guarded = array('id');\n\n"; $code .= !$panel_data['panel_options']['has_timestamps'] ? "\tpublic \$timestamps = false;\n\n" : "\n"; if (isset($panel_data['elements'])) { foreach ($panel_data['elements'] as $elem_name => $elem_data) { if (isset($elem_data['data']['relation']) && in_array($elem_data['data']['relation'], $this->valid_relationships) && !isset($elem_data['data']['no_model'])) { $is_subpanel = $elem_data['type'] == 'subpanel'; $order_by = ''; if ($is_subpanel) { // check to see if we can apply order_by clause for foreign table relationship. $subpanel_data = StationConfig::panel($elem_name, TRUE); $order_by_column = isset($subpanel_data['panel_options']['default_order_by']) ? $subpanel_data['panel_options']['default_order_by'] : false; $order_by = $order_by_column ? $this->order_by_clause($order_by_column) : ""; } else { // TODO: add order_by for non sub panels. We will need this soon. } $pivot_table_name = $this->pivot_table_name(array('tableOne' => $tableName, 'tableTwo' => $elem_data['data']['table']), TRUE); $pivot_table = strpos($elem_data['data']['relation'], 'ToMany') !== FALSE ? $pivot_table_name : ''; $pivot_table = $pivot_table == "" && $elem_data['data']['relation'] == 'belongsTo' ? ", '" . $elem_name . "'" : $pivot_table; $pivot_table = $pivot_table == "" && $elem_data['data']['relation'] == 'hasMany' && isset($elem_data['data']['key']) ? ", '" . $elem_data['data']['key'] . "'" : $pivot_table; $code .= "\tpublic function " . $elem_data['data']['table'] . "()\n\t" . "{\n\t\t" . "return \$this->" . $elem_data['data']['relation'] . "('" . $panel->model_name_for($elem_data['data']['table']) . "'" . $pivot_table . ")" . $order_by . ";\n\t" . "}\n"; } } } $code .= "\t" . $this->gen_end; $code .= $is_new ? "\n\n\t// Feel free to add any new code after this line\n}" : ""; return $code; }