diff --git a/app/Helpers/PageBlocksHelper.php b/app/Helpers/PageBlocksHelper.php new file mode 100644 index 0000000..ea6e96c --- /dev/null +++ b/app/Helpers/PageBlocksHelper.php @@ -0,0 +1,43 @@ +where('main', false) + ->where('linked', true) + ->orderByDesc('linkorder') + ->get(); + } + + return Page::where('is_published', true) + ->where('main', false) + ->where('linked', true) + ->where('visibility', 'public') + ->orderByDesc('linkorder') + ->get(); + } + + public static function sponsors() { } + + public static function partners() { } + + public static function contingent() { } + + public static function articles() { } + + public static function events() { } +} \ No newline at end of file diff --git a/app/Http/Controllers/PageRender.php b/app/Http/Controllers/PageRender.php new file mode 100644 index 0000000..5c2e37f --- /dev/null +++ b/app/Http/Controllers/PageRender.php @@ -0,0 +1,82 @@ +firstOrFail(); + + if ($page->main) { + abort(404); + } + + if (!$page->is_published) { + abort(403); + } + + if ($page->visibility === 'private') { + if (!Auth::check()) { + abort(403); + } + } + + $images = ImageNode::all(); + + $revision = $page->activeRevision; + $revision->load(['page', 'editor']); + + $neededFetchers = collect(); + + $blocks = json_decode($revision->content, true); + + foreach ($blocks as $block) { + if (!empty($block['needs'])) { + $neededFetchers = $neededFetchers->merge($block['needs']); + } + } + + $neededFetchers = $neededFetchers->unique(); + + $blockData = []; + + foreach ($neededFetchers as $fetcher) { + if (method_exists(PageBlocksHelper::class, $fetcher)) { + $blockData[$fetcher] = PageBlocksHelper::$fetcher(); + } + } + + return Inertia::render('Root', [ + 'revision' => [ + 'id' => $revision->id, + 'uuid' => $revision->uuid, + 'version' => $revision->version, + 'title' => $revision->title, + 'slug' => $revision->slug, + 'label' => $revision->label, + 'active' => $revision->active, + 'content' => json_decode($revision->content, true), + 'page' => [ + 'id' => $revision->page->id, + 'uuid' => $revision->page->uuid, + 'is_published'=> $revision->page->is_published, + 'main' => $revision->page->main, + 'visibility' => $revision->page->visibility, + ] + ], + 'images' => $images, + 'blockData' => $blockData + ]); + } +} diff --git a/app/Models/ImageNode.php b/app/Models/ImageNode.php new file mode 100644 index 0000000..cdc4b43 --- /dev/null +++ b/app/Models/ImageNode.php @@ -0,0 +1,34 @@ +belongsTo(User::class, 'user_id'); + } + + public function children() { + return $this->hasMany(ImageNode::class, 'parent_id', 'id'); + } + + public function parent() { + return $this->belongsTo(ImageNode::class, 'parent_id', 'id'); + } +} diff --git a/database/migrations/2023_11_14_134838_create_image_nodes_table.php b/database/migrations/2023_11_14_134838_create_image_nodes_table.php new file mode 100644 index 0000000..21fd856 --- /dev/null +++ b/database/migrations/2023_11_14_134838_create_image_nodes_table.php @@ -0,0 +1,33 @@ +id(); + $table->foreignId('user_id'); + $table->unsignedBigInteger('parent_id')->nullable(); + $table->foreign('parent_id')->references('id')->on('image_nodes')->onDelete('cascade'); + $table->string('name'); + $table->enum('fs_type', ['folder', 'file']); + $table->json('fs_meta')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('image_nodes'); + } +};