/** * The constructor sets the values using the supplied config array * * @param array $config //the array of options provide in each model's config */ public function __construct($config) { //set the class properties for the items which we know to exist $this->storagePath = path('storage') . 'administrator_settings/'; $this->title = array_get($config, 'title'); $this->name = array_get($config, 'name'); $this->edit = array_get($config, 'edit_fields'); $this->rules = array_get($config, 'rules', array()); $this->beforeSave = array_get($config, 'before_save', function () { }); $this->actions = array_get($config, 'actions'); //fetch the meaningful information for actions $this->actions = Action::getActions($this); $this->fetchData(); }
/** * The constructor takes a field, column array, and the associated Eloquent model * * @param array $config //the array of options provide in each model's config */ public function __construct($config) { //set the class properties for the items which we know to exist $this->title = array_get($config, 'title'); $this->single = array_get($config, 'single'); $this->model = array_get($config, 'model'); $this->columns = array_get($config, 'columns'); $this->actions = array_get($config, 'actions'); $this->edit = array_get($config, 'edit_fields'); $this->filters = array_get($config, 'filters', array()); $this->name = array_get($config, 'model_name'); //fetch the meaningful information for columns and actions //we won't do the same for edit fields and filters because that information is not always persistent across a request $this->columns = Column::getColumns($this); $this->actions = Action::getActions($this); //copy $this->model because of php syntax issues $model = $this->model; //now set the properties for other items //form width option $formWidth = array_get($config, 'form_width', $this->formWidth); if (!is_int($formWidth) || $formWidth < $this->formWidth) { $formWidth = $this->formWidth; } $this->formWidth = $formWidth; //sort options $this->sort = array_get($config, 'sort', array()); $this->setSort(); //get the rows per page $this->setRowsPerPage(); //grab the model link callback $linkCallback = array_get($config, 'link'); $this->linkCallback = is_callable($linkCallback) ? $linkCallback : null; //grab the action permissions, if supplied $actionPermissions = array_get($config, 'action_permissions', array()); $create = array_get($actionPermissions, 'create'); $delete = array_get($actionPermissions, 'delete'); $update = array_get($actionPermissions, 'update'); $this->actionPermissions['create'] = is_callable($create) ? $create() : true; $this->actionPermissions['delete'] = is_callable($delete) ? $delete() : true; $this->actionPermissions['update'] = is_callable($update) ? $update() : true; }
/** * POST method for handling custom actions on the settings page * * @param SettingsConfig $config * * @return JSON */ public function action_settings_custom_action($config) { $model = ModelHelper::getModel($config, $id, false, true); $actionName = Input::get('action_name', false); //get the action and perform the custom action $action = Action::getByName($config, $actionName); $result = $action->perform($model); //if the result is a string, return that as an error. if (is_string($result)) { return Response::json(array('success' => false, 'error' => $result)); } else { if (!$result) { return Response::json(array('success' => false, 'error' => $action->messages['error'])); } else { return Response::json(array('success' => true)); } } }