/** * Builds a few basic options */ public function build() { parent::build(); //set the upload url depending on the type of config this is $url = $this->validator->getUrlInstance(); $route = $this->config->getType() === 'settings' ? 'admin_settings_file_upload' : 'admin_file_upload'; //set the upload url to the proper route $this->suppliedOptions['upload_url'] = $url->route($route, array($this->config->getOption('name'), $this->suppliedOptions['field_name'])); }
/** * Sets the filter options for this item * * @param array $filter * * @return void */ public function setFilter($filter) { parent::setFilter($filter); $this->userOptions['value'] = $this->validator->arrayGet($filter, 'value', ''); //if it isn't null, we have to check the 'true'/'false' string if ($this->userOptions['value'] !== '') { $this->userOptions['value'] = $this->userOptions['value'] === 'false' || !$this->userOptions['value'] ? 0 : 1; } }
/** * Filters a query object given * * @param \Illuminate\Database\Query\Builder $query * @param array $selects * * @return void */ public function filterQuery(QueryBuilder &$query, &$selects = null) { //run the parent method parent::filterQuery($query, $selects); //if there is no value, return if (!$this->getOption('value')) { return; } $query->where($this->config->getDataModel()->getTable() . '.' . $this->getOption('field_name'), 'LIKE', '%' . $this->getOption('value') . '%'); }
/** * Builds a few basic options */ public function build() { parent::build(); //set the upload url to the proper route if ($this->config->getType() === 'settings') { $this->suppliedOptions['upload_url'] = admin_url('settings/' . $this->config->getOption('name') . '/' . $this->suppliedOptions['field_name'] . '/file_upload'); } else { $this->suppliedOptions['upload_url'] = admin_url($this->config->getOption('name') . '/' . $this->suppliedOptions['field_name'] . '/file_upload'); } }
/** * Filters a query object * * @param \Illuminate\Database\Query\Builder $query * @param array $selects * * @return void */ public function filterQuery(QueryBuilder &$query, &$selects = null) { //run the parent method parent::filterQuery($query, $selects); //if there is no value, return if (!$this->getOption('value')) { return; } if (is_callable($this->getOption('query'))) { call_user_func($this->getOption('query'), $query, $this->config->getDataModel()->getTable() . '.' . $this->getOption('field_name'), $this->getOption('value')); } else { $query->where($this->config->getDataModel()->getTable() . '.' . $this->getOption('field_name'), '=', $this->getOption('value')); } }
/** * Takes an eloquent result array and turns it into an options array that can be used in the UI * * @param \Frozennode\Administrator\Fields\Field $field * @param \Illuminate\Database\Eloquent\Collection $results * * @return array */ public function formatSelectOptions(Field $field, EloquentCollection $results) { $return = array(); foreach ($results as $m) { $return[] = array('id' => $m->getKey(), 'text' => strval($m->{$field->getOption('name_field')})); } return $return; }
/** * Gets all default values * * @return array */ public function getDefaults() { $defaults = parent::getDefaults(); return array_merge($defaults, $this->relationshipDefaults); }
/** * Gets the formatted value of a relationship input * * @param string $value * @param \Frozennode\Administrator\Fields\Field $field * * @return mixed array | string */ protected function formatRelationshipInput($value, Field $field) { $value = trim($value); if ($field->getOption('multiple_values')) { $value = $value ? explode(',', $value) : array(); } return $value; }
/** * Fills a model with the necessary relationship values * * @param \Illuminate\Database\Eloquent\Model $model * @param \Frozennode\Administrator\Fields\Field $field * * @return \Illuminate\Database\Eloquent\Collection */ public function getModelRelatedItems($model, Field $field) { $name = $field->getOption('field_name'); if ($field->getOption('multiple_values')) { //if a sort_field is provided, use it, otherwise sort by the name field if ($sortField = $field->getOption('sort_field')) { return $model->{$name}()->orderBy($sortField)->get(); } else { return $model->{$name}()->orderBy($field->getOption('name_field'))->get(); } } else { return $model->{$name}()->get(); } }
/** * Takes an eloquent result array and turns it into an options array that can be used in the UI * * @param \Illuminate\Database\Eloquent\Model $model * @param \Frozennode\Administrator\Fields\Field $field * @param array $results * * @return array */ public function formatSelectOptions($model, Field $field, array $results) { $model = $this->config->getDataModel(); return array_map(function($m) use ($field, $model) { return array( 'id' => $m->{$model->getKeyName()}, 'text' => strval($m->{$field->getOption('name_field')}), ); }, $results); }