本文整理汇总了PHP中Anomaly\Streams\Platform\Ui\Table\TableBuilder::getTableOption方法的典型用法代码示例。如果您正苦于以下问题:PHP TableBuilder::getTableOption方法的具体用法?PHP TableBuilder::getTableOption怎么用?PHP TableBuilder::getTableOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Anomaly\Streams\Platform\Ui\Table\TableBuilder
的用法示例。
在下文中一共展示了TableBuilder::getTableOption方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the command.
*/
public function handle()
{
$stream = $this->builder->getTableStream();
if (!$stream instanceof StreamInterface) {
return;
}
$eager = [];
if ($stream->isTranslatable()) {
$eager[] = 'translations';
}
$assignments = $stream->getRelationshipAssignments();
foreach ($this->builder->getColumns() as $column) {
/**
* If the column value is a string and uses a dot
* format then check if it's a relation.
*/
if (isset($column['value']) && is_string($column['value']) && preg_match("/^entry.([a-zA-Z\\_]+)./", $column['value'], $match)) {
if ($assignment = $assignments->findByFieldSlug($match[1])) {
if ($assignment->getFieldType()->getNamespace() == 'anomaly.field_type.polymorphic') {
continue;
}
$eager[] = camel_case($match[1]);
}
}
}
$this->builder->setTableOption('eager', array_unique($this->builder->getTableOption('eager', []) + $eager));
}
示例2: handle
/**
* Set the active action.
*
* @param SetActiveAction $command
*/
public function handle()
{
$prefix = $this->builder->getTableOption('prefix');
$actions = $this->builder->getTableActions();
if ($action = $actions->findBySlug(app('request')->get($prefix . 'action'))) {
$action->setActive(true);
}
}
示例3: authorize
/**
* Authorize the table.
*
* @param TableBuilder $builder
*/
public function authorize(TableBuilder $builder)
{
// Try the option first.
$permission = $builder->getTableOption('permission');
if ($permission && !$this->authorizer->authorize($permission)) {
abort(403);
}
}
示例4: normalize
/**
* Normalize action input.
*
* @param TableBuilder $builder
*/
public function normalize(TableBuilder $builder)
{
$actions = $builder->getActions();
$prefix = $builder->getTableOption('prefix');
foreach ($actions as $slug => &$action) {
$action = $this->process($prefix, $slug, $action);
}
$builder->setActions($actions);
}
示例5: handle
/**
* Save the order of the entries.
*
* @param SectionCollection $sections
* @param TableBuilder $builder
* @param array $selected
*/
public function handle(SectionCollection $sections, Redirector $redirector, TableBuilder $builder, array $selected)
{
$prefix = $builder->getTableOption('prefix');
$edit = array_shift($selected);
$ids = implode(',', $selected);
if ($section = $sections->active()) {
$builder->setTableResponse($redirector->to($section->getHref('edit/' . $edit . '?' . $prefix . 'edit_next=' . $ids)));
}
}
示例6: setActiveFilter
/**
* Set the active filter.
*
* @param $slug
* @param TableBuilder $builder
*/
protected function setActiveFilter($slug, TableBuilder $builder)
{
/* @var FilterInterface $filter */
foreach ($builder->getTableFilters() as $filter) {
if ($filter->getSlug() === $slug) {
$filter->setPrefix($builder->getTableOption('prefix'));
$filter->setActive(true);
break;
}
}
}
示例7: setActiveAction
/**
* Set the active action.
*
* @param $slug
* @param TableBuilder $builder
*/
protected function setActiveAction($slug, TableBuilder $builder)
{
/* @var ActionInterface $action */
foreach ($builder->getTableActions() as $action) {
if ($action->getSlug() === $slug) {
$action->setPrefix($builder->getTableOption('prefix'));
$action->setActive(true);
break;
}
}
}
示例8: handle
/**
* Save the order of the entries.
*
* @param TableBuilder $builder
* @param Request $request
*/
public function handle(TableBuilder $builder, Request $request)
{
$count = 0;
$model = $builder->getTableModel();
/* @var EloquentModel $entry */
foreach ($request->get($builder->getTableOption('prefix') . 'order', []) as $k => $id) {
if ($entry = $model->find($id)) {
$entry->sort_order = $k + 1;
$entry->save();
$count++;
}
}
$builder->fire('reordered', compact('count', 'builder'));
$this->messages->success(trans('streams::message.reorder_success', compact('count')));
}
示例9: guess
/**
* Guess the sortable flags for headers.
*
* @param TableBuilder $builder
*/
public function guess(TableBuilder $builder)
{
$columns = $builder->getColumns();
$stream = $builder->getTableStream();
foreach ($columns as &$column) {
if ($builder->getTableOption('sortable_headers') === false) {
$column['sortable'] = false;
continue;
}
/*
* If the heading is false or does not exist
* then the intent was to not have
* heading text at all.
*/
if (!isset($column['heading']) || $column['heading'] === false) {
continue;
}
/*
* If sortable is already set the we don't
* need to guess anything.
*/
if (isset($column['sortable'])) {
continue;
}
/*
* If the sort column is set and
* sortable is not yet, set it.
*/
if (isset($column['sort_column'])) {
$column['sortable'] = true;
continue;
}
/*
* No stream means we can't
* really do much here.
*/
if (!$stream instanceof StreamInterface) {
continue;
}
/*
* We're going to be using the value to
* try and determine if a streams field is
* being used. No value, no guess.
*/
if (!isset($column['value']) || !$column['value'] || !is_string($column['value'])) {
continue;
}
/*
* Now we're going to try and determine
* what streams field this column if
* using if any at all.
*/
$field = $column['value'];
/*
* If the value matches a field
* with dot format then reduce it.
*/
if (preg_match("/^entry.([a-zA-Z\\_]+)/", $column['value'], $match)) {
$field = $match[1];
}
/*
* If we can't determine a field type
* then we don't have anything to base
* our guess off of.
*/
if (!($assignment = $stream->getAssignment($field))) {
continue;
}
$type = $assignment->getFieldType();
/*
* If the field type has a database
* column type then we can sort on it
* by default!
*
* @todo: Allow sorting of translatable fields.
*/
if ($type->getColumnType() && !$assignment->isTranslatable()) {
$column['sortable'] = true;
$column['sort_column'] = $type->getColumnName();
} else {
$column['sortable'] = false;
}
}
$builder->setColumns($columns);
}
示例10: predict
/**
* Predict the presence of of the sortable action.
*
* @param TableBuilder $builder
*/
public function predict(TableBuilder $builder)
{
if ($builder->getTableOption('sortable')) {
$builder->setActions(array_merge(['reorder'], $builder->getActions()));
}
}
示例11: get
/**
* Get the table entries.
*
* @param TableBuilder $builder
* @return Collection
*/
public function get(TableBuilder $builder)
{
// Grab any stream we have.
$stream = $builder->getTableStream();
// Start a new query.
$query = $this->model->newQuery();
/*
* Prevent joins from overriding intended columns
* by prefixing with the model's table name.
*/
$query = $query->select($this->model->getTable() . '.*');
/*
* Eager load any relations to
* save resources and queries.
*/
$query = $query->with($builder->getTableOption('eager', []));
/*
* Raise and fire an event here to allow
* other things (including filters / views)
* to modify the query before proceeding.
*/
$builder->fire('querying', compact('builder', 'query'));
app('events')->fire(new TableIsQuerying($builder, $query));
/*
* Before we actually adjust the baseline query
* set the total amount of entries possible back
* on the table so it can be used later.
*/
$total = $query->count();
$builder->setTableOption('total_results', $total);
/*
* Assure that our page exists. If the page does
* not exist then start walking backwards until
* we find a page that is has something to show us.
*/
$limit = (int) $builder->getTableOption('limit', config('streams::system.per_page', 15));
$page = app('request')->get($builder->getTableOption('prefix') . 'page', 1);
$offset = $limit * ($page - 1);
if ($total < $offset && $page > 1) {
$url = str_replace($builder->getTableOption('prefix') . 'page=' . $page, $builder->getTableOption('prefix') . 'page=' . ($page - 1), app('request')->fullUrl());
header('Location: ' . $url);
}
/*
* Limit the results to the limit and offset
* based on the page if any.
*/
$offset = $limit * (app('request')->get($builder->getTableOption('prefix') . 'page', 1) - 1);
$query = $query->take($limit)->offset($offset);
/*
* Order the query results.
*/
if ($order = $builder->getTableOption('order_by')) {
foreach ($order as $column => $direction) {
if ($stream && ($utility = $stream->getFieldTypeQuery($column))) {
$utility->orderBy($query, $direction);
} else {
$query = $query->orderBy($column, $direction);
}
}
}
if ($builder->getTableOption('sortable')) {
$query = $query->orderBy('sort_order', 'ASC');
}
return $query->get();
}