/** * Handle the command. * * @param ResponseFactory $response */ public function handle(ResponseFactory $response) { $grid = $this->builder->getGrid(); $options = $grid->getOptions(); $data = $grid->getData(); $grid->setResponse($response->view($options->get('wrapper_view', 'streams::blank'), $data)); }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); /* * If the model is already instantiated * then use it as is. */ if (is_object($model)) { $grid->setModel($model); return; } /* * If no model is set, try guessing the * model based on best practices. */ if (!$model) { $parts = explode('\\', str_replace('GridBuilder', 'Model', get_class($this->builder))); unset($parts[count($parts) - 2]); $model = implode('\\', $parts); $this->builder->setModel($model); } /* * If the model is not set then skip it. */ if (!class_exists($model)) { return; } /* * Set the model on the grid! */ $grid->setModel(app($model)); }
/** * Handle the command. */ public function handle() { $this->builder->fire('saving', ['builder' => $this->builder]); $repository = $this->builder->getGridRepository(); $repository->save($this->builder); $this->builder->fire('saved', ['builder' => $this->builder]); }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $options = $grid->getOptions(); $data = $grid->getData(); $content = view($options->get('grid_view', 'streams::grid/grid'), $data)->render(); $grid->setContent($content); $grid->addData('content', $content); }
/** * Handle the command. * * @param Resolver $resolver * @param Evaluator $evaluator */ public function handle(Resolver $resolver, Evaluator $evaluator) { $arguments = ['builder' => $this->builder]; $grid = $this->builder->getGrid(); $options = $this->builder->getOptions(); $options = $resolver->resolve($options, $arguments); $options = $evaluator->evaluate($options, $arguments); foreach ($options as $key => $value) { $grid->setOption($key, $value); } }
/** * Save the grid. * * @param GridBuilder $builder * @param array $items */ public function save(GridBuilder $builder, array $items = []) { $model = $builder->getGridModel(); $items = $items ?: $builder->getRequestValue('items'); foreach ($items as $index => $item) { /* @var EloquentModel $entry */ $entry = $model->find($item['id']); $entry->{$builder->getGridOption('sort_column', 'sort_order')} = $index + 1; $entry->save(); } }
/** * Build the items. * * @param GridBuilder $builder */ public function build(GridBuilder $builder) { foreach ($builder->getGridEntries() as $entry) { $buttons = $this->buttons->build($builder, $entry); $buttons = $buttons->enabled(); $value = $this->value->make($builder, $entry); $id = $entry->getId(); $item = compact('builder', 'buttons', 'entry', 'value', 'id'); $item = $this->evaluator->evaluate($item, compact('builder', 'entry')); $builder->addGridItem($this->factory->make($item)); } }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); /* * Set the default options handler based * on the builder class. Defaulting to * no handler. */ if (!$grid->getOption('options')) { $options = str_replace('GridBuilder', 'GridOptions', get_class($this->builder)); if (class_exists($options)) { app()->call($options . '@handle', compact('builder', 'grid')); } } /* * Set the default data handler based * on the builder class. Defaulting to * no handler. */ if (!$grid->getOption('data')) { $options = str_replace('GridBuilder', 'GridData', get_class($this->builder)); if (class_exists($options)) { $grid->setOption('data', $options . '@handle'); } } /* * Set a optional entries handler based * on the builder class. Defaulting to * no handler in which case we will use * the model and included repositories. */ if (!$grid->getOption('entries')) { $entries = str_replace('GridBuilder', 'GridEntries', get_class($this->builder)); if (class_exists($entries)) { $grid->setOption('entries', $entries . '@handle'); } } /* * Set the default options handler based * on the builder class. Defaulting to * no handler. */ if (!$grid->getOption('repository')) { $model = $grid->getModel(); if (!$grid->getOption('repository') && $model instanceof EntryModel) { $grid->setOption('repository', EntryGridRepository::class); } if (!$grid->getOption('repository') && $model instanceof EloquentModel) { $grid->setOption('repository', EloquentGridRepository::class); } } }
/** * Handle the command. * * @param Asset $asset * @throws \Exception */ public function handle(Asset $asset) { foreach ($this->builder->getAssets() as $collection => $assets) { if (!is_array($assets)) { $assets = [$assets]; } foreach ($assets as $file) { $filters = explode('|', $file); $file = array_shift($filters); $asset->add($collection, $file, $filters); } } }
/** * Handle the command. */ public function handle() { /* * Set the default buttons handler based * on the builder class. Defaulting to * no handler. */ if (!$this->builder->getButtons()) { $buttons = str_replace('GridBuilder', 'GridButtons', get_class($this->builder)); if (class_exists($buttons)) { $this->builder->setButtons($buttons . '@handle'); } } }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); if (is_string($model) && !class_exists($model)) { return; } if (is_string($model)) { $model = app($model); } if ($model instanceof EntryInterface) { $grid->setStream($model->getStream()); } }
/** * Authorize the grid. * * @param GridBuilder $builder */ public function authorize(GridBuilder $builder) { // Try the option first. $permission = $builder->getGridOption('permission'); /* * If the option is not set then * try and automate the permission. */ if (!$permission && ($module = $this->modules->active()) && ($stream = $builder->getGridStream())) { $permission = $module->getNamespace($stream->getSlug() . '.read'); } if (!$this->authorizer->authorize($permission)) { abort(403); } }
/** * Normalize button input. * * @param GridBuilder $builder */ public function normalize(GridBuilder $builder) { $buttons = $builder->getButtons(); foreach ($buttons as $key => &$button) { /** * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /** * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /** * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /** * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /** * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /** * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } /** * Use small buttons for grids. */ $button['size'] = array_get($button, 'size', 'xs'); } $builder->setButtons($buttons); }
/** * Build the buttons. * * @param GridBuilder $builder * @param $entry * @return ButtonCollection */ public function build(GridBuilder $builder, $entry) { $grid = $builder->getGrid(); $buttons = new ButtonCollection(); $this->input->read($builder, $entry); foreach ($builder->getButtons() as $button) { if (!array_get($button, 'enabled', true)) { continue; } $button = $this->evaluator->evaluate($button, compact('entry', 'grid')); $button = $this->parser->parser($button, $entry); $button = $this->factory->make($button); $buttons->push($button); } return $buttons; }
/** * Handle the command. * * @param Container $container * @param ViewTemplate $template * @param BreadcrumbCollection $breadcrumbs */ public function handle(Container $container, ViewTemplate $template, BreadcrumbCollection $breadcrumbs) { $grid = $this->builder->getGrid(); $grid->addData('grid', $grid); if ($handler = $grid->getOption('data')) { $container->call($handler, compact('grid')); } if ($layout = $grid->getOption('layout_view')) { $template->put('layout', $layout); } if ($title = $grid->getOption('title')) { $template->put('title', $title); } if ($breadcrumb = $grid->getOption('breadcrumb')) { $breadcrumbs->put($breadcrumb, '#'); } }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $grid->getModel(); $repository = $grid->getOption('repository'); /** * If there is no repository * then skip this step. */ if (!$repository) { return; } /** * Set the repository on the form! */ $grid->setRepository(app()->make($repository, compact('model', 'grid'))); }
/** * Guess the HREF for a button. * * @param GridBuilder $builder */ public function guess(GridBuilder $builder) { $buttons = $builder->getButtons(); // Nothing to do if empty. if (!($section = $this->sections->active())) { return; } foreach ($buttons as &$button) { // If we already have an HREF then skip it. if (isset($button['attributes']['href'])) { continue; } // Determine the HREF based on the button type. if ($type = array_get($button, 'button')) { $button['attributes']['href'] = $section->getHref($type . '/{entry.id}'); } } $builder->setButtons($buttons); }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); /** * If the builder has an entries handler * then call it through the container and * let it load the entries itself. */ if ($handler = $grid->getOption('entries')) { app()->call($handler, ['builder' => $this->builder]); return; } $entries = $grid->getEntries(); /** * If the entries have already been set on the * grid then return. Nothing to do here. * * If the model is not set then they need * to load the grid entries themselves. */ if (!$entries->isEmpty() || !$model) { return; } /** * Resolve the model out of the container. */ $repository = $grid->getRepository(); /** * If the repository is an instance of * GridRepositoryInterface use it. */ if ($repository instanceof GridRepositoryInterface) { $grid->setEntries($repository->get($this->builder)); } }
/** * Return the item value. * * @param GridBuilder $builder * @param $entry * @return View|mixed|null */ public function make(GridBuilder $builder, $entry) { $value = $builder->getGridOption('item_value', 'entry.title'); /** * If the entry is an instance of EntryInterface * then try getting the field value from the entry. */ if ($entry instanceof EntryInterface && $entry->getField($value)) { if ($entry->assignmentIsRelationship($value)) { $value = $entry->{camel_case($value)}->getTitle(); } else { $value = $entry->getFieldValue($value); } } /** * If the value matches a field with a relation * then parse the string using the eager loaded entry. */ if (preg_match("/^entry.([a-zA-Z\\_]+)/", $value, $match)) { $fieldSlug = camel_case($match[1]); if (method_exists($entry, $fieldSlug) && $entry->{$fieldSlug}() instanceof Relation) { $entry = $this->decorator->decorate($entry); $value = data_get(compact('entry'), str_replace("entry.{$match[1]}.", 'entry.' . camel_case($match[1]) . '.', $value)); } } /** * Decorate the entry object before * sending to decorate so that data_get() * can get into the presenter methods. */ $entry = $this->decorator->decorate($entry); /** * If the value matches a method in the presenter. */ if (preg_match("/^entry.([a-zA-Z\\_]+)/", $value, $match)) { if (method_exists($entry, camel_case($match[1]))) { $value = $entry->{camel_case($match[1])}(); } } /** * By default we can just pass the value through * the evaluator utility and be done with it. */ $value = $this->evaluator->evaluate($value, compact('builder', 'entry')); /** * Lastly, prepare the entry to be * parsed into the string. */ if ($entry instanceof Arrayable) { $entry = $entry->toArray(); } else { $entry = null; } /** * Parse the value with the entry. */ $value = $this->parser->render($builder->getGridOption('item_wrapper', '{value}'), compact('value', 'entry')); /** * If the value looks like a language * key then try translating it. */ if (str_is('*.*.*::*', $value)) { $value = trans($value); } return $value; }
/** * Resolve grid views. * * @param GridBuilder $builder */ public function resolve(GridBuilder $builder) { $this->resolver->resolve($builder->getButtons(), compact('builder')); }