/** * Validates the supplied options * * @return void */ public function validateOptions() { //override the config $this->validator->override($this->suppliedOptions, $this->rules); //if the validator failed, throw an exception if ($this->validator->fails()) { throw new \InvalidArgumentException("There are problems with your '" . $this->suppliedOptions['action_name'] . "' action in the " . $this->config->getOption('name') . " model: " . implode('. ', $this->validator->messages()->all())); } }
/** * Gets all action permissions * * @param bool $override * * @return array of Action objects */ public function getActionPermissions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->actionPermissions) || $override) { $this->actionPermissions = array(); $model = $this->config->getDataModel(); $options = $this->config->getOption('action_permissions'); $defaults = $this->actionPermissionsDefaults; //merge the user-supplied action permissions into the defaults $permissions = array_merge($defaults, $options); //loop over the actions to build the list foreach ($permissions as $action => $callback) { if (is_callable($callback)) { $this->actionPermissions[$action] = (bool) $callback($model); } else { $this->actionPermissions[$action] = (bool) $callback; } } } return $this->actionPermissions; }
/** * Set the number of rows per page for this data table * * @param \Illuminate\Session\Store $session * @param int $globalPerPage * @param int $override //if provided, this will set the session's rows per page value */ public function setRowsPerPage(\Illuminate\Session\Store $session, $globalPerPage, $override = null) { if ($override) { $perPage = (int) $override; $session->put('administrator_' . $this->config->getOption('name') . '_rows_per_page', $perPage); } $perPage = $session->get('administrator_' . $this->config->getOption('name') . '_rows_per_page'); if (!$perPage) { $perPage = (int) $globalPerPage; } $this->rowsPerPage = $perPage; }
/** * Gets the column objects * * @return array */ public function getColumns() { //make sure we only run this once and then return the cached version if (!sizeof($this->columns)) { foreach ($this->config->getOption('columns') as $name => $options) { //if only a string value was supplied, may sure to turn it into an array $object = $this->make($this->parseOptions($name, $options)); $this->columns[$object->getOption('column_name')] = $object; } } return $this->columns; }
/** * Gets the filters for the given model config * * @return array */ public function getFilters() { //get the model's filter fields $configFilters = $this->config->getOption('filters'); //make sure that the filters array hasn't been created before and that there are supplied filters in the config if (!sizeof($this->filters) && $configFilters) { //iterate over the filters and create field objects for them foreach ($configFilters as $name => $filter) { if ($fieldObject = $this->make($name, $filter)) { //the filters array is indexed on the field name and holds the arrayed values for the filters $this->filters[$fieldObject->getOption('field_name')] = $fieldObject; } } } return $this->filters; }