diff --git a/app/Modules/Themes/Entities/ThemeManager.php b/app/Modules/Themes/Entities/ThemeManager.php index 03db6085e..1392c9064 100644 --- a/app/Modules/Themes/Entities/ThemeManager.php +++ b/app/Modules/Themes/Entities/ThemeManager.php @@ -71,9 +71,11 @@ public function getScanPath(): string */ public function find(string $name): ?Theme { + $lname = strtolower($name); + foreach ($this->allEnabled() as $theme) { - if ($theme->getLowerElement() == strtolower($name)) + if ($theme->getLowerElement() == $lname) { return $theme; } @@ -91,9 +93,11 @@ public function find(string $name): ?Theme */ public function findOrFail(string $name): ?Theme { + $lname = strtolower($name); + foreach ($this->allEnabled() as $theme) { - if ($theme->getLowerElement() == strtolower($name)) + if ($theme->getLowerElement() == $lname) { return $theme; } @@ -101,7 +105,7 @@ public function findOrFail(string $name): ?Theme foreach ($this->allDisabled() as $theme) { - if ($theme->getLowerElement() == strtolower($name)) + if ($theme->getLowerElement() == $lname) { return $theme; } @@ -184,7 +188,7 @@ public function allDisabled(): array * @param string $type * @return array */ - public function allByType($type = 'site') + public function allByType(string $type = 'site') { $themes = []; @@ -273,7 +277,7 @@ private function getThemesFromFiles(int $state = null): Collection */ private function getThemesFromDatabase(int $state = null, string $type = null): Collection { - $s = (new Model)->getTable(); + /*$s = (new Model)->getTable(); $query = $this->getDatabase() ->table($s) @@ -285,21 +289,32 @@ private function getThemesFromDatabase(int $state = null, string $type = null): $s . '.params', $s . '.protected', $s . '.client_id' + ]);*/ + + $query = Model::query() + ->select([ + 'id', + 'enabled', + 'name', + 'element', + 'params', + 'protected', + 'client_id' ]); if (!is_null($state)) { - $query->where($s . '.enabled', '=', $state); + $query->where('enabled', '=', $state); } if (!is_null($type)) { - $query->where($s . '.client_id', '=', $type == 'admin' ? 1 : 0); + $query->where('client_id', '=', $type == 'admin' ? 1 : 0); } - $query - ->where($s . '.type', '=', 'theme') - ->orderBy($s . '.enabled', 'desc'); - $rows = $query->get(); + $rows = $query + ->where('type', '=', 'theme') + ->orderBy('enabled', 'desc') + ->get(); if (count($rows) <= 0) { @@ -354,10 +369,10 @@ public function getFiles() /** * @return \Illuminate\Database\DatabaseManager */ - protected function getDatabase() + /*protected function getDatabase() { return $this->app['db']; - } + }*/ /** * @return \Illuminate\Config\Repository diff --git a/app/Modules/Themes/Models/Theme.php b/app/Modules/Themes/Models/Theme.php index a39536b7e..61bc78a2b 100755 --- a/app/Modules/Themes/Models/Theme.php +++ b/app/Modules/Themes/Models/Theme.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Collection; use App\Halcyon\Models\Casts\Params; use App\Halcyon\Form\Form; use Carbon\Carbon; @@ -26,6 +27,8 @@ * @property int $ordering * @property Carbon|null $updated_at * @property int $updated_by + * + * @property string $api */ class Theme extends Model { @@ -130,7 +133,7 @@ public function duplicate(): bool * @param string $name The name. * @return string New name. */ - protected function generateNewTitle($name): string + protected function generateNewTitle(string $name): string { // Alter the name $style = self::query() @@ -254,9 +257,9 @@ public function path(): string * Get active templates for specified client * * @param int $client_id - * @return Theme|null + * @return Collection */ - public function allActive($client_id = 0) + public function allActive(int $client_id = 0): Collection { return self::query() ->where('enabled', '=', 1) diff --git a/app/Modules/Themes/Publishing/AssetPublisher.php b/app/Modules/Themes/Publishing/AssetPublisher.php index 952216cbf..af7ed49e6 100644 --- a/app/Modules/Themes/Publishing/AssetPublisher.php +++ b/app/Modules/Themes/Publishing/AssetPublisher.php @@ -16,7 +16,7 @@ class AssetPublisher extends Publisher * * @return string */ - public function getDestinationPath() + public function getDestinationPath(): string { return $this->repository->getAssetPath($this->theme->getLowerName()); } @@ -26,7 +26,7 @@ public function getDestinationPath() * * @return string */ - public function getSourcePath() + public function getSourcePath(): string { return config('module.themes.paths.themes', app_path('Themes')); } diff --git a/app/Modules/Themes/Publishing/Publisher.php b/app/Modules/Themes/Publishing/Publisher.php index a51cbc636..00a7af2d9 100644 --- a/app/Modules/Themes/Publishing/Publisher.php +++ b/app/Modules/Themes/Publishing/Publisher.php @@ -3,6 +3,7 @@ namespace App\Modules\Themes\Publishing; use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; use App\Modules\Themes\Contracts\PublisherInterface; //use App\Modules\Themes\Contracts\RepositoryInterface; use App\Modules\Themes\Entities\Theme; @@ -25,7 +26,7 @@ abstract class Publisher implements PublisherInterface /** * The laravel console instance. * - * @var \Illuminate\Console\Command + * @var Command */ protected $console; @@ -65,7 +66,7 @@ public function __construct(Theme $theme) * * @return self */ - public function showMessage() + public function showMessage(): self { $this->showMessage = true; @@ -77,7 +78,7 @@ public function showMessage() * * @return self */ - public function hideMessage() + public function hideMessage(): self { $this->showMessage = false; @@ -89,7 +90,7 @@ public function hideMessage() * * @return Theme */ - public function getTheme() + public function getTheme(): self { return $this->theme; } @@ -99,7 +100,7 @@ public function getTheme() * @param RepositoryInterface $repository * @return $this */ - public function setRepository($repository)//RepositoryInterface + public function setRepository(RepositoryInterface $repository): self { $this->repository = $repository; @@ -111,7 +112,7 @@ public function setRepository($repository)//RepositoryInterface * * @return RepositoryInterface */ - public function getRepository() + public function getRepository(): RepositoryInterface { return $this->repository; } @@ -119,11 +120,10 @@ public function getRepository() /** * Set console instance. * - * @param \Illuminate\Console\Command $console - * + * @param Command $console * @return $this */ - public function setConsole(Command $console) + public function setConsole(Command $console): self { $this->console = $console; @@ -133,9 +133,9 @@ public function setConsole(Command $console) /** * Get console instance. * - * @return \Illuminate\Console\Command + * @return Command */ - public function getConsole() + public function getConsole(): Command { return $this->console; } @@ -143,9 +143,9 @@ public function getConsole() /** * Get laravel filesystem instance. * - * @return \Illuminate\Filesystem\Filesystem + * @return Filesystem */ - public function getFilesystem() + public function getFilesystem(): Filesystem { return $this->repository->getFiles(); } @@ -155,19 +155,21 @@ public function getFilesystem() * * @return string */ - abstract public function getDestinationPath(); + abstract public function getDestinationPath(): string; /** * Get source path. * * @return string */ - abstract public function getSourcePath(); + abstract public function getSourcePath(): string; /** * Publish something. + * + * @throws \RuntimeException */ - public function publish() + public function publish(): void { if (!$this->console instanceof Command) { diff --git a/app/Modules/Themes/Resources/views/admin/edit.blade.php b/app/Modules/Themes/Resources/views/admin/edit.blade.php index 101b16f1f..470ce9caa 100644 --- a/app/Modules/Themes/Resources/views/admin/edit.blade.php +++ b/app/Modules/Themes/Resources/views/admin/edit.blade.php @@ -49,13 +49,13 @@
- +
- +
-
+