master
sergeybodin 2023-06-16 15:57:08 +03:00
commit 0d07c9b02d
8 changed files with 185 additions and 2 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;
use App\Models\Pages\Page;
use App\Models\Publications\Publication;
use App\Services\PermissionsService;
use App\Transformers\Assets\AssetTransformer;

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

View File

@ -85,7 +85,11 @@ class PagesTableSeeder extends Seeder
'Ответы на часто задаваемые вопросы' => [],
]
],
'КСИ' => [],
'КСИ' => [
'children' => [
]
],
'Добровольная сертификация' => [
'children' => [
'О системе' => [],