diff --git a/app/Http/Controllers/GalleryController.php b/app/Http/Controllers/GalleryController.php index 3463944..3b049cd 100644 --- a/app/Http/Controllers/GalleryController.php +++ b/app/Http/Controllers/GalleryController.php @@ -14,6 +14,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Storage; +use Illuminate\Validation\Rule; class GalleryController extends BaseController { @@ -22,12 +23,21 @@ class GalleryController extends BaseController public function listView() { $galleries = Gallery::query()->where("tenant", "=", session("current_tenant_id"))->orderByDesc("gallery_create_time")->orderByDesc("id")->get(); $tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail(); - return view("gallery.index", ["galleries" => $galleries, "tenant" => $tenant]); + return view("gallery.index", [ "galleries" => $galleries, "tenant" => $tenant]); } - public function newView() { + public function newView(Request $request) { $gallery = new Gallery(); - return view("gallery.new", ["gallery" => $gallery]); + $status = "preview"; + if(!empty($request->old("status"))) { + $status = $request->old("status"); + } + $listed = true; + if(!empty($request->old("listed"))) { + $listed = $request->old("listed"); + } + $tags = ""; + return view("gallery.new", ["gallery" => $gallery, "tags" => $tags, "status" => $status, "listed" => $listed]); } public function newGallery(Request $request) { @@ -36,8 +46,19 @@ class GalleryController extends BaseController 'description' => 'max:15000000', 'url' => [new urlOrNull()], 'date' => [new dateOrNull()], + 'status' => ['required', Rule::in(['preview', 'online', 'archiv'])], + 'listed' => '', + 'tags' => '' ]); + if(!array_key_exists("listed", $validated)) { + $validated["listed"] = false; + } + if(strtolower($validated["listed"]) == "off") { + $validated["listed"] = false; + } + $validated["listed"] = (bool)$validated["listed"]; + //Check if Gallery Date is in the feature if(!empty($validated["date"])) { $t = new \DateTime($validated["date"]); @@ -88,6 +109,9 @@ class GalleryController extends BaseController $gallery->url = $newUrl; $gallery->description = $validated["description"]; $gallery->tenant = session("current_tenant_id"); + $gallery->status = $validated["status"]; + $gallery->listed = $validated["listed"]; + $gallery->tags = json_encode(mb_split(",", $validated["tags"])); if(!empty($validated["date"])) { $gallery->gallery_create_time = $validated["date"]; } else { @@ -102,7 +126,21 @@ class GalleryController extends BaseController public function editGalleryView($name, Request $request) { $gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name); - return view("gallery.new", ["gallery" => $gallery]); + $status = $gallery->status; + if(!empty($request->old("status"))) { + $status = $request->old("status"); + } + $listed = $gallery->listed; + if(!empty($request->old("listed"))) { + $listed = $request->old("listed"); + } + $tagsArray = json_decode($gallery->tags); + + $tags = ""; + if(is_array($tagsArray)) { + $tags = implode(",", $tagsArray); + } + return view("gallery.new", ["gallery" => $gallery, "tags" => $tags, "status" => $status, "listed" => $listed]); } public function editGallery($name, Request $request) { @@ -111,13 +149,27 @@ class GalleryController extends BaseController 'description' => 'max:15000000', 'url' => 'required|regex:/^[a-z0-9\-]{8,30}$/i', 'date' => 'required|regex:/^\d{4}-\d{2}-\d{2}$/i', + 'status' => ['required', Rule::in(['preview', 'online', 'archiv'])], + 'listed' => '', + 'tags' => '' ]); + if(!array_key_exists("listed", $validated)) { + $validated["listed"] = false; + } + if(strtolower($validated["listed"]) == "off") { + $validated["listed"] = false; + } + $validated["listed"] = (bool)$validated["listed"]; + $gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name); $gallery->name = $validated["name"]; $gallery->description = $validated["description"]; $gallery->url = $validated["url"]; $gallery->gallery_create_time = $validated["date"]; + $gallery->status = $validated["status"]; + $gallery->listed = $validated["listed"]; + $gallery->tags = json_encode(mb_split(",", $validated["tags"])); $gallery->saveOrFail(); diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index 8e5d108..ebdebf3 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -27,7 +27,13 @@ class PublicController extends BaseController public function listGalleriesView($name) { $tenant = Tenant::query()->where("url", "=", $name)->firstOrFail(); - $galleries = Gallery::query()->where("tenant", "=", $tenant->id)->orderByDesc("gallery_create_time")->orderByDesc("created_at")->get(); + $galleries = Gallery::query() + ->where("tenant", "=", $tenant->id) + ->where("status", "=", "online") + ->where("listed", "=", 1) + ->orderByDesc("gallery_create_time") + ->orderByDesc("created_at") + ->get(); $parser = new \Parsedown(); foreach ($galleries as $gallery) { $gallery->html = $parser->parse($gallery->description); diff --git a/database/migrations/2021_01_19_204558_gallery_meta_infos.php b/database/migrations/2021_01_19_204558_gallery_meta_infos.php new file mode 100644 index 0000000..37fe7d5 --- /dev/null +++ b/database/migrations/2021_01_19_204558_gallery_meta_infos.php @@ -0,0 +1,33 @@ +enum("status", ["preview", "online", "deleted", "archiv"])->default("online"); + $table->boolean("listed")->default(true)->comment("Listet on the Tenant Page"); + $table->mediumText("tags")->nullable()->default(null); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/gallery/new.blade.php b/resources/views/gallery/new.blade.php index 16b3564..047d390 100644 --- a/resources/views/gallery/new.blade.php +++ b/resources/views/gallery/new.blade.php @@ -42,13 +42,31 @@ - +