/**
  * Delete a record from the database.
  *
  * @return mixed
  */
 public function delete()
 {
     $this->model->fireEvent('deletingMultiple');
     $return = parent::delete();
     $this->model->fireEvent('deletedMultiple');
     return $return;
 }
 /**
  * Handle the command.
  *
  * @param Guard $auth
  */
 public function handle(Guard $auth)
 {
     if ($this->entry->created_at) {
         $this->entry->updated_at = time();
         $this->entry->updated_by = $auth->id();
     }
     if (!$this->entry->created_at) {
         $this->entry->created_at = time();
         $this->entry->created_by = $auth->id();
     }
     if (!$this->entry->sort_order) {
         /* @var Builder $query */
         $query = $this->entry->newQuery();
         $this->entry->sort_order = $query->count('id') + 1;
     }
 }
 /**
  * Get the tree entries.
  *
  * @param TreeBuilder $builder
  * @return Collection
  */
 public function get(TreeBuilder $builder)
 {
     // Start a new query.
     $query = $this->model->newQuery();
     /**
      * Prevent joins from overriding intended columns
      * by prefixing with the model's tree name.
      */
     $query = $query->select($this->model->getTable() . '.*');
     /**
      * Eager load any relations to
      * save resources and queries.
      */
     $query = $query->with($builder->getTreeOption('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 TreeIsQuerying($builder, $query));
     /**
      * Before we actually adjust the baseline query
      * set the total amount of entries possible back
      * on the tree so it can be used later.
      */
     $total = $query->count();
     $builder->setTreeOption('total_results', $total);
     /**
      * Order the query results.
      */
     foreach ($builder->getTreeOption('order_by', ['sort_order' => 'asc']) as $column => $direction) {
         $query = $query->orderBy($column, $direction);
     }
     return $query->get();
 }
Ejemplo n.º 4
0
 /**
  * When accessing a property of a decorated entry
  * object first check to see if the key represents
  * a streams field. If it does then return the field
  * type's presenter object. Otherwise handle normally.
  *
  * @param  $key
  * @return mixed
  */
 public function __get($key)
 {
     if ($assignment = $this->object->getAssignment($key)) {
         $type = $assignment->getFieldType();
         if ($assignment->isTranslatable() && ($locale = config('app.locale'))) {
             $entry = $this->object->translateOrDefault($locale);
             $type->setLocale($locale);
         } else {
             $entry = $this->object;
         }
         $type->setEntry($entry);
         if (method_exists($type, 'getRelation')) {
             return $type->decorate($entry->getRelationValue(camel_case($key)));
         }
         $type->setValue($entry->getFieldValue($key));
         return $type->getPresenter();
     }
     return $this->__getDecorator()->decorate(parent::__get($key));
 }
Ejemplo n.º 5
0
 /**
  * Because the assignment record holds translatable data
  * we have a conflict. The assignment table has translations
  * but not all assignment are translatable. This helps avoid
  * the translatable conflict during specific procedures.
  *
  * @param  array  $attributes
  * @return static
  */
 public static function create(array $attributes = [])
 {
     $model = parent::create($attributes);
     $model->saveTranslations();
     return $model;
 }
Ejemplo n.º 6
0
 /**
  * Override the __get method.
  *
  * @param string $key
  * @return EntryPresenter|mixed
  */
 public function __get($key)
 {
     if ($key === 'decorated') {
         return $this->getPresenter();
     }
     return parent::__get($key);
     // TODO: Change the autogenerated stub
 }
Ejemplo n.º 7
0
 /**
  * Boot the model.
  */
 protected static function boot()
 {
     self::$builder = app(FieldTypeBuilder::class);
     parent::boot();
 }
 /**
  * Find an entry.
  *
  * @param $id
  * @return EloquentModel
  */
 public function findOrNew($id)
 {
     return $this->model->findOrNew($id);
 }
 /**
  * Parse a translation.
  *
  * @param EloquentModel $translation
  * @param               $string
  */
 protected function parseTranslation(EloquentModel $translation, &$string)
 {
     $string .= "\n[";
     foreach ($translation->getAttributes() as $key => $value) {
         $value = $translation->getAttribute($key);
         if (is_string($value)) {
             $value = addslashes($value);
         }
         $string .= "\n'{$key}' => '{$value}',";
     }
     $string .= "\n],";
 }
 /**
  * Run after a record has been restored.
  *
  * @param EloquentModel $model
  */
 public function restored(EloquentModel $model)
 {
     $model->flushCache();
     $this->events->fire(new ModelWasRestored($model));
 }
 /**
  * Boot the service provider.
  */
 public function boot(Dispatcher $events)
 {
     $events->fire(new Booting());
     // First load our app environment.
     $this->dispatch(new LoadEnvironmentOverrides());
     // Next take care of core utilities.
     $this->dispatch(new SetCoreConnection());
     $this->dispatch(new ConfigureCommandBus());
     $this->dispatch(new ConfigureUriValidator());
     $this->dispatch(new InitializeApplication());
     // Setup and preparing utilities.
     $this->dispatch(new LoadStreamsConfiguration());
     $this->dispatch(new AutoloadEntryModels());
     $this->dispatch(new AddAssetNamespaces());
     $this->dispatch(new AddImageNamespaces());
     $this->dispatch(new AddViewNamespaces());
     // Observe our base models.
     EntryModel::observe(EntryObserver::class);
     FieldModel::observe(FieldObserver::class);
     StreamModel::observe(StreamObserver::class);
     EloquentModel::observe(EloquentObserver::class);
     AssignmentModel::observe(AssignmentObserver::class);
     $this->app->booted(function () use($events) {
         $events->fire(new Booted());
         /* @var AddonManager $manager */
         $manager = $this->app->make('Anomaly\\Streams\\Platform\\Addon\\AddonManager');
         /* @var Dispatcher $events */
         $events = $this->app->make('Illuminate\\Contracts\\Events\\Dispatcher');
         $events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) {
             $twig = $event->getTwig();
             foreach ($this->plugins as $plugin) {
                 if (!$twig->hasExtension($plugin)) {
                     $twig->addExtension($this->app->make($plugin));
                 }
             }
             if (!$twig->hasExtension('markdown')) {
                 $twig->addExtension(new MarkdownExtension(new MichelfMarkdownEngine()));
             }
             $twig->addExtension(new Extension(new CacheStrategy(new CacheAdapter($this->app->make(Repository::class)), new CacheKey())));
         });
         $manager->register();
         $this->dispatch(new IncludeRoutes());
         $events->fire(new Ready());
     });
     $this->app->singleton('mailer', function () {
         $mailer = new Mailer($this->app['view'], $this->app['swift.mailer'], $this->app['events']);
         $mailer->setContainer($this->app);
         if ($this->app->bound('Psr\\Log\\LoggerInterface')) {
             $mailer->setLogger($this->app->make('Psr\\Log\\LoggerInterface'));
         }
         if ($this->app->bound('queue')) {
             $mailer->setQueue($this->app['queue.connection']);
         }
         $from = $this->app['config']['mail.from'];
         if (is_array($from) && isset($from['address'])) {
             $mailer->alwaysFrom($from['address'], $from['name']);
         }
         $to = $this->app['config']['mail.to'];
         if (is_array($to) && isset($to['address'])) {
             $mailer->alwaysTo($to['address'], $to['name']);
         }
         $pretend = $this->app['config']->get('mail.pretend', false);
         $mailer->pretend($pretend);
         return $mailer;
     });
     $this->app->singleton('Illuminate\\Mail\\Mailer', function () {
         return $this->app->make('mailer');
     });
     $this->app->singleton('Illuminate\\Contracts\\Mail\\Mailer', function () {
         return $this->app->make('mailer');
     });
     $this->dispatch(new ConfigureTranslator());
 }
 /**
  * Get the attribute from the parent
  * if it does not exist here.
  *
  * @param  string $key
  * @return mixed
  */
 public function __get($key)
 {
     $value = parent::__get($key);
     if (!$value && ($parent = $this->getParent())) {
         return $parent->{$key};
     }
     return $value;
 }
Ejemplo n.º 13
0
 /**
  * Get the entries.
  *
  * @return Collection
  */
 public function get()
 {
     return (new Decorator())->decorate($this->model->newCollection($this->query->get()->all()));
 }
 /**
  * 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();
 }
 /**
  * Restore a trashed record.
  *
  * @param EloquentModel $entry
  * @return bool
  */
 public function restore(EloquentModel $entry)
 {
     return $entry->restore();
 }
 /**
  * Boot the service provider.
  */
 public function boot(Dispatcher $events)
 {
     $events->fire(new Booting());
     // First load our app environment.
     $this->dispatch(new LoadEnvironmentOverrides());
     // Next take care of core utilities.
     $this->dispatch(new SetCoreConnection());
     $this->dispatch(new ConfigureUriValidator());
     $this->dispatch(new InitializeApplication());
     // Setup and preparing utilities.
     $this->dispatch(new LoadStreamsConfiguration());
     $this->dispatch(new ConfigureTranslator());
     $this->dispatch(new AutoloadEntryModels());
     $this->dispatch(new AddAssetNamespaces());
     $this->dispatch(new AddImageNamespaces());
     $this->dispatch(new AddViewNamespaces());
     $this->dispatch(new ConfigureScout());
     // Observe our base models.
     EntryModel::observe(EntryObserver::class);
     FieldModel::observe(FieldObserver::class);
     StreamModel::observe(StreamObserver::class);
     EloquentModel::observe(EloquentObserver::class);
     AssignmentModel::observe(AssignmentObserver::class);
     $this->app->booted(function () use($events) {
         $events->fire(new Booted());
         /* @var AddonManager $manager */
         $manager = $this->app->make('Anomaly\\Streams\\Platform\\Addon\\AddonManager');
         /* @var Dispatcher $events */
         $events = $this->app->make('Illuminate\\Contracts\\Events\\Dispatcher');
         $events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) {
             $twig = $event->getTwig();
             foreach ($this->plugins as $plugin) {
                 if (!$twig->hasExtension($plugin)) {
                     $twig->addExtension($this->app->make($plugin));
                 }
             }
             if (!$twig->hasExtension('markdown')) {
                 $twig->addExtension(new MarkdownExtension(new MichelfMarkdownEngine()));
             }
             $twig->addExtension(new Extension(new CacheStrategy(new CacheAdapter($this->app->make(Repository::class)), new CacheKey())));
         });
         $manager->register();
         /*
          * Do this after addons are registered
          * so that they can override named routes.
          */
         $this->dispatch(new IncludeRoutes());
         $events->fire(new Ready());
     });
 }