ImageNode from Polarpress migration + model + helper class, PageRender controller
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run

This commit is contained in:
2025-05-05 15:25:55 +02:00
parent b8acb478b0
commit 60dc53b7ca
4 changed files with 192 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Auth;
use App\Models\Page;
class PageBlocksHelper
{
public static function fetchTotalUsers() { }
public static function fetchTotalMembers() { }
public static function fetchAvatarCollection() { }
public static function mainMenuLinks() {
if (Auth::check()) {
return Page::where('is_published', true)
->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() { }
}
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Inertia\Inertia;
use App\Helpers\PageBlocksHelper;
use App\Helpers\PageSettingsHelper;
use App\Models\Page;
use App\Models\PageRevision;
use App\Models\ImageNode;
class PageRender extends Controller
{
public function view(Request $request, $slug) {
$page = Page::where('slug', $slug)->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
]);
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
class ImageNode extends Model
{
use HasFactory;
protected $table = 'image_nodes';
protected $fillable = [
'user_id',
'parent_id',
'name',
'fs_type',
'fs_meta',
];
public function user() {
return $this->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');
}
}