From f9afcae389e842b75aa868b5c139f015f0dc8395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 1 Apr 2016 21:50:05 +0200 Subject: [PATCH] FEATURE #1526: add simple photogallery Photogallery currently works with directories, UI is terrible, but it works. --- modules/Gallery/Assets/.gitkeep | 0 modules/Gallery/Config/.gitkeep | 0 modules/Gallery/Config/config.php | 12 ++ modules/Gallery/Console/.gitkeep | 0 modules/Gallery/Database/Migrations/.gitkeep | 0 modules/Gallery/Database/Seeders/.gitkeep | 0 .../Seeders/GalleryDatabaseSeeder.php | 20 ++ modules/Gallery/Entities/.gitkeep | 0 modules/Gallery/Handlers/Gallery.php | 194 ++++++++++++++++++ modules/Gallery/Http/Controllers/.gitkeep | 0 modules/Gallery/Http/Middleware/.gitkeep | 0 modules/Gallery/Http/Requests/.gitkeep | 0 modules/Gallery/Http/routes.php | 1 + modules/Gallery/Providers/.gitkeep | 0 .../Providers/GalleryServiceProvider.php | 110 ++++++++++ modules/Gallery/Repositories/.gitkeep | 0 .../Resources/lang/en/admin/content.php | 5 + modules/Gallery/Resources/lang/en/module.php | 6 + .../views/admin/content/editUpload.blade.php | 3 + .../views/admin/content/newUpload.blade.php | 3 + modules/Gallery/Tests/.gitkeep | 0 modules/Gallery/composer.json | 15 ++ modules/Gallery/start.php | 15 ++ 23 files changed, 384 insertions(+) create mode 100644 modules/Gallery/Assets/.gitkeep create mode 100644 modules/Gallery/Config/.gitkeep create mode 100644 modules/Gallery/Config/config.php create mode 100644 modules/Gallery/Console/.gitkeep create mode 100644 modules/Gallery/Database/Migrations/.gitkeep create mode 100644 modules/Gallery/Database/Seeders/.gitkeep create mode 100644 modules/Gallery/Database/Seeders/GalleryDatabaseSeeder.php create mode 100644 modules/Gallery/Entities/.gitkeep create mode 100644 modules/Gallery/Handlers/Gallery.php create mode 100644 modules/Gallery/Http/Controllers/.gitkeep create mode 100644 modules/Gallery/Http/Middleware/.gitkeep create mode 100644 modules/Gallery/Http/Requests/.gitkeep create mode 100644 modules/Gallery/Http/routes.php create mode 100644 modules/Gallery/Providers/.gitkeep create mode 100644 modules/Gallery/Providers/GalleryServiceProvider.php create mode 100644 modules/Gallery/Repositories/.gitkeep create mode 100644 modules/Gallery/Resources/lang/en/admin/content.php create mode 100644 modules/Gallery/Resources/lang/en/module.php create mode 100644 modules/Gallery/Resources/views/admin/content/editUpload.blade.php create mode 100644 modules/Gallery/Resources/views/admin/content/newUpload.blade.php create mode 100644 modules/Gallery/Tests/.gitkeep create mode 100644 modules/Gallery/composer.json create mode 100644 modules/Gallery/start.php diff --git a/modules/Gallery/Assets/.gitkeep b/modules/Gallery/Assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Config/.gitkeep b/modules/Gallery/Config/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Config/config.php b/modules/Gallery/Config/config.php new file mode 100644 index 00000000..2a2b7237 --- /dev/null +++ b/modules/Gallery/Config/config.php @@ -0,0 +1,12 @@ + 'Gallery', + 'translatedName' => 'gallery::module.name', + 'translatedDescription' => 'gallery::module.description', + 'alias' => 'gallery', + 'handler' => '\\Modules\\Gallery\\Handlers\\Gallery', + 'providers' => [\Modules\Gallery\Providers\GalleryServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/modules/Gallery/Console/.gitkeep b/modules/Gallery/Console/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Database/Migrations/.gitkeep b/modules/Gallery/Database/Migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Database/Seeders/.gitkeep b/modules/Gallery/Database/Seeders/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Database/Seeders/GalleryDatabaseSeeder.php b/modules/Gallery/Database/Seeders/GalleryDatabaseSeeder.php new file mode 100644 index 00000000..1d0d0a07 --- /dev/null +++ b/modules/Gallery/Database/Seeders/GalleryDatabaseSeeder.php @@ -0,0 +1,20 @@ +call("OthersTableSeeder"); + } + +} \ No newline at end of file diff --git a/modules/Gallery/Entities/.gitkeep b/modules/Gallery/Entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Handlers/Gallery.php b/modules/Gallery/Handlers/Gallery.php new file mode 100644 index 00000000..1636fee8 --- /dev/null +++ b/modules/Gallery/Handlers/Gallery.php @@ -0,0 +1,194 @@ +module_settings)) { + $content->module_settings = json_decode($content->module_settings); + } + + // get directory ID + $directoryId = $content->module_settings->directoryId; + + // get all images in given directory + $images = File::where('directory_id', $directoryId) + ->where('mime_type', 'LIKE', 'image%') + ->get(); + + // render content + return Controller::VisitorsView($content->template, ['images' => $images, 'page' => $content]); + } + + public static function getHistoryHandler() + { + return History::class; + } + + /** + * Save module-specific values into database + * + * @param Content $content + * @param Request $request + * + * @return mixed + * @internal param Widget $widget + */ + public static function createNew(Content &$content, Request $request) + { + $parentDirectoryId = Storage::get(self::CONFIG_FILENAME); + + // create new directory for images + $directory = Directory::create([ + 'name' => $request->title, + 'description' => $request->description, + 'parent_id' => $parentDirectoryId + ]); + + // save id into module_config array + $settings = [ + 'directoryId' => $directory->id + ]; + + // save settings + $content->module_settings = json_encode($settings); + } + + /** + * Method used for editing existing content page. + * + * Reason why it is separated from createNew() method is simple - we need to save history of changes. + * + * @param Content $content + * @param Request $request + * + * @param $revisionID string ID of revision used + * + * @return int number of edited fields + */ + public static function edit(Content &$content, Request $request, $revisionID) + { + // nothing to edit + } + + /** + * Does given module manage content? Or is it just module with widgets/something internal/something absolutely else? + * + * @return bool + */ + public static function managesContent() + { + return true; + } + + public static function getModuleId() + { + $handler = config('gallery.handler'); + $allModules = ModulesHandlerToId::getWithTranslations(); + $moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null; + + return $moduleId; + } + + /** + * Getter for section names in creating/editing content resource + * + * @return mixed + */ + public static function getExtendedFormSections() + { + $sections = Handler::getExtendedFormSections(); + + $sections['upload'] = trans('gallery::admin/content.upload'); + + return $sections; + } + + /** + * Getter for views used in extended part of form for creating new content + * + * This method should return pairs . View is returned only as name in plain text + * + * @return array of views/templates/html codes divided into section + */ + public static function getExtendedFormInputsCreate() + { + $parts = Handler::getExtendedFormInputsCreate(); + $parts['upload'] = 'gallery::admin.content.newUpload'; + + return $parts; + } + + /** + * Getter for extended part of form for editing existing content + * + * Basically, this method may be + * + * @return array of views/templates/html codes divided into section + */ + public static function getExtendedFormInputsEdit() + { + $parts = Handler::getExtendedFormInputsCreate(); + $parts['upload'] = 'gallery::admin.content.editUpload'; + + return $parts; + } + + /** + * Register admin menu (or multiple ones) + * + * This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before + * starting any middleware.. + * + * @param User $user model of logged user + */ + public static function registerAdminMenu(User $user) + { + // nothing to register + } + + /** + * Install module + * + * @return mixed + */ + public static function install() + { + $directory = Directory::where('name', self::DIRECTORY_NAME) + ->first(); + + if (!count($directory)) { + $directory = Directory::create([ + 'name' => self::DIRECTORY_NAME, + 'hidden' => true + ]); + } + + Storage::put(self::CONFIG_FILENAME, $directory->id); + } +} \ No newline at end of file diff --git a/modules/Gallery/Http/Controllers/.gitkeep b/modules/Gallery/Http/Controllers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Http/Middleware/.gitkeep b/modules/Gallery/Http/Middleware/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Http/Requests/.gitkeep b/modules/Gallery/Http/Requests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Http/routes.php b/modules/Gallery/Http/routes.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/modules/Gallery/Http/routes.php @@ -0,0 +1 @@ +registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + __DIR__ . '/../Config/config.php' => config_path('gallery.php'), + ]); + $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'gallery'); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/gallery'); + + $sourcePath = __DIR__ . '/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ]); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/gallery'; + }, \Config::get('view.paths')), [$sourcePath]), 'gallery'); + + /** + * @var $registrator TemplateRegistrator + */ + $registrator = $this->app->make('registerTemplateDir'); + try { + // setup some global variables + $registrator->setBaseDirectory('resources/views/modules/gallery/visitor'); + $registrator->setNamespace('gallery'); + $registrator->setModuleId(call_user_func([config('gallery.handler'), 'getModuleId'])); + + // register path with current template name + $registrator->register(config('app.theme'), 'gallery::admin.templatePath'); + } catch (InvalidArgumentException $e) { + // ignore this exception + } + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = base_path('resources/lang/modules/gallery'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, 'gallery'); + } else { + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'gallery'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array (); + } +} diff --git a/modules/Gallery/Repositories/.gitkeep b/modules/Gallery/Repositories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/Resources/lang/en/admin/content.php b/modules/Gallery/Resources/lang/en/admin/content.php new file mode 100644 index 00000000..5458870a --- /dev/null +++ b/modules/Gallery/Resources/lang/en/admin/content.php @@ -0,0 +1,5 @@ + 'Upload photos', + 'uploadAfterSavingGallery' => 'Uploading for this gallery is not available yet. You must create the gallery first and upload later.' +]; \ No newline at end of file diff --git a/modules/Gallery/Resources/lang/en/module.php b/modules/Gallery/Resources/lang/en/module.php new file mode 100644 index 00000000..6b0048ab --- /dev/null +++ b/modules/Gallery/Resources/lang/en/module.php @@ -0,0 +1,6 @@ + 'Gallery', + 'description' => 'Simple photogallery', + +]; \ No newline at end of file diff --git a/modules/Gallery/Resources/views/admin/content/editUpload.blade.php b/modules/Gallery/Resources/views/admin/content/editUpload.blade.php new file mode 100644 index 00000000..d20f55a4 --- /dev/null +++ b/modules/Gallery/Resources/views/admin/content/editUpload.blade.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/modules/Gallery/Resources/views/admin/content/newUpload.blade.php b/modules/Gallery/Resources/views/admin/content/newUpload.blade.php new file mode 100644 index 00000000..8d84eda9 --- /dev/null +++ b/modules/Gallery/Resources/views/admin/content/newUpload.blade.php @@ -0,0 +1,3 @@ +
+ @lang('gallery::admin/content.uploadAfterSavingGallery') +
\ No newline at end of file diff --git a/modules/Gallery/Tests/.gitkeep b/modules/Gallery/Tests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Gallery/composer.json b/modules/Gallery/composer.json new file mode 100644 index 00000000..24d1e0a0 --- /dev/null +++ b/modules/Gallery/composer.json @@ -0,0 +1,15 @@ +{ + "name": "pingpong-modules/gallery", + "description": "", + "authors": [ + { + "name": "Pingpong Labs", + "email": "pingpong.labs@gmail.com" + } + ], + "autoload": { + "psr-4": { + "Modules\\Gallery\\": "" + } + } +} \ No newline at end of file diff --git a/modules/Gallery/start.php b/modules/Gallery/start.php new file mode 100644 index 00000000..7be329cb --- /dev/null +++ b/modules/Gallery/start.php @@ -0,0 +1,15 @@ +