ImageNode from Polarpress migration + model + helper class, PageRender controller
This commit is contained in:
parent
b8acb478b0
commit
60dc53b7ca
43
app/Helpers/PageBlocksHelper.php
Normal file
43
app/Helpers/PageBlocksHelper.php
Normal 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
app/Http/Controllers/PageRender.php
Normal file
82
app/Http/Controllers/PageRender.php
Normal 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
app/Models/ImageNode.php
Normal file
34
app/Models/ImageNode.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('image_nodes', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user