registries alfa

master
Константин 2023-06-16 15:21:20 +03:00
parent e134c9b0cc
commit 1fddf71b66
8 changed files with 182 additions and 3 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\Models\Registries;
use App\Models\Pages\Page;
use App\Support\HasObjectsTrait;
use App\Support\RelationValuesTrait;
use App\Support\UuidScopeTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Registry extends Model {
use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait;
protected $dates = [
];
protected $fillable = [
'uuid',
'page_id',
'type',
'name'
];
protected $hidden = [
'id'
];
public function page(): BelongsTo {
return $this->belongsTo(Page::class);
}
public function getParsedTypeAttribute(): array {
return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Models\Registries;
use App\Support\HasObjectsTrait;
use App\Support\RelationValuesTrait;
use App\Support\UuidScopeTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class RegistryEntry extends Model {
use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait;
protected $dates = [
];
protected $fillable = [
'uuid',
'registry_id',
'name'
];
protected $hidden = [
'id'
];
public function registry(): BelongsTo {
return $this->belongsTo(Registry::class);
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models\Registries;
class RegistryType {
public const DOCUMENTS = 'documents';
public const TITLES = [
self::DOCUMENTS => 'Реестр документов'
];
}

View File

@ -2,7 +2,6 @@
namespace App\Transformers\Publications; namespace App\Transformers\Publications;
use App\Models\Pages\Page;
use App\Models\Publications\Publication; use App\Models\Publications\Publication;
use App\Services\PermissionsService; use App\Services\PermissionsService;
use App\Transformers\Assets\AssetTransformer; use App\Transformers\Assets\AssetTransformer;
@ -23,7 +22,7 @@ class PublicationTransformer extends TransformerAbstract {
'page', 'poster', 'author', 'sections', 'sidebars', 'permissions' 'page', 'poster', 'author', 'sections', 'sidebars', 'permissions'
]; ];
public function transform(Page $model): array { public function transform(Publication $model): array {
return [ return [
'id' => $model->uuid, 'id' => $model->uuid,
'slug' => $model->slug, 'slug' => $model->slug,

View File

@ -0,0 +1,46 @@
<?php
namespace App\Transformers\Registries;
use App\Models\Registries\Registry;
use App\Services\PermissionsService;
use App\Transformers\Objects\ObjectTransformer;
use App\Transformers\Pages\PageTransformer;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
use League\Fractal\Resource\Primitive;
use League\Fractal\TransformerAbstract;
class RegistryTransformer extends TransformerAbstract {
protected array $defaultIncludes = [
];
protected array $availableIncludes = [
'page', 'entries', 'permissions'
];
public function transform(Registry $model): array {
return [
'id' => $model->uuid,
'type' => $model->parsedType,
'name' => $model->name,
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
];
}
public function includePage(Registry $model): ?Item {
return $model->page ? $this->item($model->page, new PageTransformer()) : null;
}
public function includeEntries(Registry $model): Collection {
return $this->collection($model->objects, new ObjectTransformer());
}
public function includePermissions(Registry $model): Primitive {
return $this->primitive((new PermissionsService($model))->get());
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRegistriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('registries', function (Blueprint $table) {
$table->id();
$table->char('uuid', 36)->index()->unique();
$table->integer('page_id')->index()->default(0);
$table->string('type')->index()->nullable();
$table->string('name')->index()->nullable();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('registries');
}
}

View File

@ -10,6 +10,7 @@ class ObjectTypesTableSeeder extends Seeder {
'page-sidebar' => [ 'page-sidebar' => [
'title' => 'Сторонний блок контентной страницы' 'title' => 'Сторонний блок контентной страницы'
], ],
'page-section' => [ 'page-section' => [
'title' => 'Секция контентной страницы', 'title' => 'Секция контентной страницы',
'children' => [ 'children' => [
@ -35,6 +36,15 @@ class ObjectTypesTableSeeder extends Seeder {
'title' => 'Видео' 'title' => 'Видео'
] ]
] ]
],
'registry-entry' => [
'title' => 'Запись в реестре',
'children' => [
'registry-entry-document' => [
'title' => 'Документ'
]
]
] ]
]; ];

View File

@ -95,7 +95,7 @@ class PagesTableSeeder extends Seeder
], ],
'КСИ' => [ 'КСИ' => [
'children' => [ 'children' => [
'' => [],
] ]
], ],
'Добровольная сертификация' => [ 'Добровольная сертификация' => [