Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
 /**
  * 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();
     }
 }