/** * Return the sortable label. * * @param string $size * @return null|string */ protected function sortableLabel($size = 'sm') { if ($this->object->isSortable()) { return '<span class="label label-primary label-' . $size . '">' . trans('streams::field.sortable.name') . '</span>'; } return null; }
/** * Return the translation foreign key attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } return 'protected $translationForeignKey = \'entry_id\';'; }
/** * Return the use statement for trashable if so. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { if (!$stream->isSearchable()) { return "false"; } return "true"; }
/** * Return the use statement for trashable if so. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { if (!$stream->isTrashable()) { return null; } return "use \\Illuminate\\Database\\Eloquent\\SoftDeletes;"; }
/** * Return fields only NOT assigned * to the provided stream. * * @param StreamInterface $stream * @return static */ public function notAssignedTo(StreamInterface $stream) { $fieldSlugs = $stream->getAssignmentFieldSlugs(); return new static(array_filter($this->items, function (FieldInterface $field) use($fieldSlugs) { return !in_array($field->getSlug(), $fieldSlugs); })); }
/** * Parse the assignments. * * @param StreamInterface $stream * @param $string */ protected function parseAssignments(StreamInterface $stream, &$string) { $string .= "\n'assignments' => ["; foreach ($stream->getAssignments() as $assignment) { $this->parseAssignment($assignment, $string); } $string .= "\n],"; }
/** * Handle the command. * * @param StreamSchema $schema */ public function handle(StreamSchema $schema) { $schema->createTable($this->stream); if ($this->stream->isTranslatable()) { $table = $this->stream->getEntryTranslationsTableName(); $schema->createTranslationsTable($table); } }
/** * Return the entity name. * * @param StreamInterface $stream * @param Module $module * @return string */ public function parse(Module $module, StreamInterface $stream) { // First, check if the user has default content $destination = $module->getPath(); $entityName = strtolower(str_singular($stream->getSlug())); $file = $destination . "/seeders/{$entityName}" . ".php"; return file_exists($file) ? file_get_contents($file) : ''; }
/** * Call the method on the query. * * @param $name * @param $arguments * @return Builder|null */ public function __call($name, $arguments) { if ($assignment = $this->stream->getAssignment(snake_case($name))) { $this->query->where($assignment->getColumnName(), $arguments ? array_shift($arguments) : null); return $this; } return parent::__call($name, $arguments); }
/** * Return the entry translation model attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } $namespace = studly_case($stream->getNamespace()); $class = studly_case("{$stream->getNamespace()}_{$stream->getSlug()}") . 'EntryTranslationsModel'; return 'protected $translationModel = \'Anomaly\\Streams\\Platform\\Model\\' . $namespace . '\\' . $class . '\';'; }
/** * Return the relationships attribute. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { $relationships = []; /* @var AssignmentInterface $assignment */ foreach ($stream->getRelationshipAssignments() as $assignment) { $relationships[] = "'{$assignment->getFieldSlug()}'"; } return "[" . implode(', ', $relationships) . "]"; }
/** * Call the method on the query. * * @param $name * @param $arguments * @return Builder|null */ function __call($name, $arguments) { if ($assignment = $this->stream->getAssignment(snake_case($name))) { $this->query->where($assignment->getColumnName(), $arguments ? array_shift($arguments) : null); return $this; } return parent::__call($name, $arguments); // TODO: Change the autogenerated stub }
/** * Handle the command. * * @param AddonCollection $addons * @param Repository $repository */ public function handle(AddonCollection $addons, Repository $repository) { $slug = $this->stream->getSlug(); $namespace = $this->stream->getNamespace(); foreach ($addons->withConfig("streams.{$namespace}.{$slug}") as $config) { $this->stream->mergeConfig($config); } $this->stream->mergeConfig($repository->get("streams::streams.{$namespace}.{$slug}", [])); }
/** * Parse the relation methods. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { $string = ''; $assignments = $stream->getAssignments(); foreach ($assignments->relations() as $assignment) { $this->parseAssignment($assignment, $string); } return $string; }
/** * Handle the command. * * @param StreamSchema $schema */ public function handle(StreamSchema $schema, StreamRepositoryInterface $streams) { /* @var StreamInterface $stream */ $stream = $streams->find($this->stream->getId()); $schema->renameTable($stream, $this->stream); if ($stream->isTranslatable()) { $schema->renameTranslationsTable($stream, $this->stream); } }
/** * Return the entry model base namespace. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { $string = "["; foreach ($stream->getAssignmentFieldSlugs() as $slug) { $string .= "\n'{$slug}',"; } $string .= "\n]"; return $string; }
/** * Run after a stream has been deleted. * * @param StreamInterface $model */ public function deleted(StreamInterface $model) { $model->compile(); $model->flushCache(); $this->dispatch(new DropStreamsEntryTable($model)); $this->dispatch(new DeleteStreamEntryModels($model)); $this->dispatch(new DeleteStreamAssignments($model)); $this->dispatch(new DeleteStreamTranslations($model)); $this->events->fire(new StreamWasDeleted($model)); }
/** * Handle the comand. * * @param Parser $parser * @param Application $application */ public function handle(Parser $parser, Application $application) { $data = ['namespace' => (new EntryNamespaceParser())->parse($this->stream), 'class' => (new EntryTranslationsClassParser())->parse($this->stream), 'table' => (new EntryTranslationsTableParser())->parse($this->stream)]; $template = file_get_contents(__DIR__ . '/../../../resources/stubs/models/translation.stub'); $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace())); $path .= '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()); $file = $path . 'EntryTranslationsModel.php'; @unlink($file); // Don't judge me.. file_put_contents($file, $parser->parse($template, $data)); }
/** * Handle the command. * * @param Filesystem $files * @param Parser $parser * @param Application $application */ public function handle(Filesystem $files, Parser $parser, Application $application) { $data = ['class' => (new EntryClassParser())->parse($this->stream), 'title' => (new EntryTitleParser())->parse($this->stream), 'table' => (new EntryTableParser())->parse($this->stream), 'rules' => (new EntryRulesParser())->parse($this->stream), 'dates' => (new EntryDatesParser())->parse($this->stream), 'stream' => (new EntryStreamParser())->parse($this->stream), 'trashable' => (new EntryTrashableParser())->parse($this->stream), 'relations' => (new EntryRelationsParser())->parse($this->stream), 'namespace' => (new EntryNamespaceParser())->parse($this->stream), 'field_slugs' => (new EntryFieldSlugsParser())->parse($this->stream), 'searchable' => (new EntrySearchableParser())->parse($this->stream), 'relationships' => (new EntryRelationshipsParser())->parse($this->stream), 'translation_model' => (new EntryTranslationModelParser())->parse($this->stream), 'translated_attributes' => (new EntryTranslatedAttributesParser())->parse($this->stream), 'translation_foreign_key' => (new EntryTranslationForeignKeyParser())->parse($this->stream)]; $template = file_get_contents(__DIR__ . '/../../../resources/stubs/models/entry.stub'); $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace())); $files->makeDirectory($path, 0777, true, true); $file = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryModel.php'; $files->makeDirectory(dirname($file), 0777, true, true); $files->delete($file); $files->put($file, $parser->parse($template, $data)); }
/** * Return the translation foreign key attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } $assignments = $stream->getTranslatableAssignments(); if ($assignments->isEmpty()) { return null; } return 'protected $translatedAttributes = [\'' . implode('\', \'', $assignments->fieldSlugs()) . '\'];'; }
/** * Recompile entry models for a given stream. * * @param StreamInterface $stream */ public function recompile(StreamInterface $stream) { // Generate the base model. $this->dispatch(new GenerateEntryModel($stream)); /** * If the stream is translatable generate * the translations model too. */ if ($stream->isTranslatable()) { $this->dispatch(new GenerateEntryTranslationsModel($stream)); } }
/** * Handle the command. * * @param Application $application */ public function handle(Application $application, Filesystem $files) { if (!class_exists('TeamTNT\\TNTSearch\\TNTSearch')) { return; } $model = $this->stream->getEntryModel(); $index = $application->getStoragePath('search/' . $model->searchableAs() . '.index'); if (!file_exists($index)) { return; } $files->delete($index); }
/** * Return the dates attribute. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { $dates = []; $dates[] = "'created_at'"; $dates[] = "'updated_at'"; /* @var AssignmentInterface $assignment */ foreach ($stream->getDateAssignments() as $assignment) { $dates[] = "'{$assignment->getFieldSlug()}'"; } if ($stream->isTrashable()) { $dates[] = "'deleted_at'"; } return "[" . implode(', ', $dates) . "]"; }
/** * Parse the assignment rules. * * @param StreamInterface $stream * @param AssignmentInterface $assignment * @param $string */ protected function parseAssignmentRules(StreamInterface $stream, AssignmentInterface $assignment, &$string) { $rules = []; if ($assignment->isRequired()) { $rules[] = 'required'; } if ($assignment->isUnique()) { $rules[] = 'unique:' . $stream->getEntryTableName() . ',' . $assignment->getColumnName(); } if (is_array($rules)) { $rules = implode('|', array_filter($rules)); $string .= "\n'{$assignment->getFieldSlug()}' => '{$rules}',"; } }
/** * Handle the command. * * @param Application $application */ public function handle(Application $application, Filesystem $files) { if (!class_exists('TeamTNT\\TNTSearch\\TNTSearch')) { return; } if (!class_exists($this->stream->getEntryModelName())) { return; } $model = $this->stream->getEntryModel(); $index = $application->getStoragePath('search/' . $model->searchableAs() . '.index'); if ($this->stream->isSearchable() && file_exists($index)) { return; } if (!$this->stream->isSearchable() && file_exists($index)) { $files->delete($index); return; } if (!$this->stream->isSearchable()) { return; } try { app(EngineManager::class)->engine('tntsearch')->initIndex($model); } catch (\Exception $e) { // Kewl. } }
/** * Handle the command. * * @param Filesystem $files * @param Application $application * @return string */ public function handle(Filesystem $files, Application $application) { $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace())); $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryModel.php'; if ($files->exists($model)) { $files->delete($model); } if (!$this->stream->isTranslatable()) { return; } $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryTranslationsModel.php'; if ($files->exists($model)) { $files->delete($model); } }
/** * Find all assignments by stream. * * @param StreamInterface $stream * @return AssignmentCollection */ public function findByStream(StreamInterface $stream) { return $this->model->where('stream_id', $stream->getId())->get(); }
/** * Return the title key for an entry model. * * @param StreamInterface $stream * @return mixed */ public function parse(StreamInterface $stream) { return $stream->getTitleColumn(); }
/** * Set the stream attribute. * * @param StreamInterface $stream */ public function setStreamAttribute(StreamInterface $stream) { $this->attributes['stream_id'] = $stream->getId(); }
/** * Return the entry table name. * * @param StreamInterface $stream * @return mixed */ public function parse(StreamInterface $stream) { return $stream->getEntryTableName(); }