diff --git a/app/Models/Publications/Publication.php b/app/Models/Publications/Publication.php index bf8ada1..f8b9036 100644 --- a/app/Models/Publications/Publication.php +++ b/app/Models/Publications/Publication.php @@ -29,7 +29,6 @@ class Publication extends Model { 'type', 'name', 'excerpt', - 'description', 'is_published' ]; diff --git a/app/Models/Registries/Category.php b/app/Models/Registries/Category.php new file mode 100644 index 0000000..f1d0640 --- /dev/null +++ b/app/Models/Registries/Category.php @@ -0,0 +1,50 @@ +belongsTo(Registry::class); + } + + public function parent(): BelongsTo { + return $this->belongsTo(Category::class, 'parent_id'); + } + + public function children(): HasMany { + return $this->hasMany(Category::class, 'parent_id'); + } + + public function entries(): HasMany { + return $this->hasMany(Entry::class); + } + + + +} diff --git a/app/Models/Registries/RegistryEntry.php b/app/Models/Registries/Entry.php similarity index 50% rename from app/Models/Registries/RegistryEntry.php rename to app/Models/Registries/Entry.php index 4c41b94..35eb798 100644 --- a/app/Models/Registries/RegistryEntry.php +++ b/app/Models/Registries/Entry.php @@ -2,23 +2,34 @@ namespace App\Models\Registries; +use App\Models\Asset; 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\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; -class RegistryEntry extends Model { +class Entry extends Model { use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait; + protected $table = 'registry_entries'; + protected $dates = [ + 'active_since', + 'active_till' ]; protected $fillable = [ 'uuid', 'registry_id', - 'name' + 'category_id', + 'asset_id', + 'number', + 'name', + 'active_since', + 'active_till' ]; protected $hidden = [ @@ -30,6 +41,18 @@ class RegistryEntry extends Model { return $this->belongsTo(Registry::class); } + public function category(): BelongsTo { + return $this->belongsTo(Category::class); + } + + public function asset(): BelongsTo { + return $this->belongsTo(Asset::class); + } + + public function operations(): HasMany { + return $this->hasMany(Operation::class); + } + } diff --git a/app/Models/Registries/Operation.php b/app/Models/Registries/Operation.php new file mode 100644 index 0000000..87430dc --- /dev/null +++ b/app/Models/Registries/Operation.php @@ -0,0 +1,55 @@ +belongsTo(Entry::class); + } + + public function order(): BelongsTo { + return $this->belongsTo(Asset::class); + } + + + public function getParsedTypeAttribute(): array { + return ['name' => $this->type, 'title' => OperationType::TITLES[$this->type] ?? null]; + } + + + +} diff --git a/app/Models/Registries/OperationType.php b/app/Models/Registries/OperationType.php new file mode 100644 index 0000000..7e6b625 --- /dev/null +++ b/app/Models/Registries/OperationType.php @@ -0,0 +1,15 @@ + 'Разработка', + self::REWORK => 'Пересмотр', + self::MODIFICATION => 'Изменение' + ]; +} \ No newline at end of file diff --git a/app/Models/Registries/Registry.php b/app/Models/Registries/Registry.php index 3a3f9c4..bf5279f 100644 --- a/app/Models/Registries/Registry.php +++ b/app/Models/Registries/Registry.php @@ -3,15 +3,15 @@ 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\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; class Registry extends Model { - use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait; + use UuidScopeTrait, SoftDeletes, RelationValuesTrait; protected $dates = [ ]; @@ -32,6 +32,14 @@ class Registry extends Model { return $this->belongsTo(Page::class); } + public function categories(): HasMany { + return $this->hasMany(Category::class); + } + + public function entries(): HasMany { + return $this->hasMany(Entry::class); + } + public function getParsedTypeAttribute(): array { diff --git a/app/Transformers/Publications/PublicationTransformer.php b/app/Transformers/Publications/PublicationTransformer.php index c8d02cb..98867e6 100644 --- a/app/Transformers/Publications/PublicationTransformer.php +++ b/app/Transformers/Publications/PublicationTransformer.php @@ -32,7 +32,6 @@ class PublicationTransformer extends TransformerAbstract { 'subtype' => $model->parsedType, 'name' => $model->name, 'excerpt' => $model->excerpt, - 'description' => $model->description, 'is_published' => boolval($model->is_published), 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null diff --git a/app/Transformers/Registries/CategoryTransformer.php b/app/Transformers/Registries/CategoryTransformer.php new file mode 100644 index 0000000..0804597 --- /dev/null +++ b/app/Transformers/Registries/CategoryTransformer.php @@ -0,0 +1,51 @@ + $model->uuid, + '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 includeRegistry(Category $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeParent(Category $model): ?Item { + return $model->parent ? $this->item($model->parent, new CategoryTransformer()) : null; + } + + public function includeChildren(Category $model): Collection { + return $this->collection($model->children, new CategoryTransformer()); + } + + public function includeEntries(Category $model): Collection { + return $this->collection($model->entries, new EntryTransformer()); + } + + public function includePermissions(Category $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/EntryTransformer.php b/app/Transformers/Registries/EntryTransformer.php new file mode 100644 index 0000000..7f77a60 --- /dev/null +++ b/app/Transformers/Registries/EntryTransformer.php @@ -0,0 +1,55 @@ + $model->uuid, + 'number' => $model->number, + 'name' => $model->name, + 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, + 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null + ]; + } + + public function includeRegistry(Entry $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeCategory(Entry $model): ?Item { + return $model->category ? $this->item($model->category, new CategoryTransformer()) : null; + } + + public function includeAsset(Entry $model): ?Item { + return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null; + } + + public function includeOperations(Entry $model): Collection { + return $this->collection($model->operations, new OperationTransformer()); + } + + public function includePermissions(Entry $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/OperationTransformer.php b/app/Transformers/Registries/OperationTransformer.php new file mode 100644 index 0000000..23d1efc --- /dev/null +++ b/app/Transformers/Registries/OperationTransformer.php @@ -0,0 +1,54 @@ + $model->uuid, + 'type' => $model->parsedType, + 'name' => $model->name, + 'developer' => $model->developer, + 'order_name' => $model->order_name, + 'order_date' => $model->order_date ? $model->order_date->toIso8601String() : null, + 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, + 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null + ]; + } + + public function includeRegistry(Entry $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeCategory(Entry $model): ?Item { + return $model->category ? $this->item($model->category, new CategoryTransformer()) : null; + } + + public function includeAsset(Entry $model): ?Item { + return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null; + } + + public function includePermissions(Entry $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/RegistryTransformer.php b/app/Transformers/Registries/RegistryTransformer.php index da19ee4..bea402a 100644 --- a/app/Transformers/Registries/RegistryTransformer.php +++ b/app/Transformers/Registries/RegistryTransformer.php @@ -17,7 +17,7 @@ class RegistryTransformer extends TransformerAbstract { ]; protected array $availableIncludes = [ - 'page', 'entries', 'permissions' + 'page', 'categories', 'entries', 'permissions' ]; public function transform(Registry $model): array { @@ -34,6 +34,10 @@ class RegistryTransformer extends TransformerAbstract { return $model->page ? $this->item($model->page, new PageTransformer()) : null; } + public function includeCategories(Registry $model): Collection { + return $this->collection($model->categories, new CategoryTransformer()); + } + public function includeEntries(Registry $model): Collection { return $this->collection($model->objects, new ObjectTransformer()); } diff --git a/database/migrations/2023_06_14_143616_create_registries_table.php b/database/migrations/2023_06_14_143616_create_registries_table.php index bfa864f..4dbba1a 100644 --- a/database/migrations/2023_06_14_143616_create_registries_table.php +++ b/database/migrations/2023_06_14_143616_create_registries_table.php @@ -16,7 +16,7 @@ class CreateRegistriesTable extends Migration Schema::create('registries', function (Blueprint $table) { $table->id(); $table->char('uuid', 36)->index()->unique(); - $table->integer('page_id')->index()->default(0); + $table->integer('page_id')->index()->nullable(); $table->string('type')->index()->nullable(); $table->string('name')->index()->nullable(); $table->timestamps(); diff --git a/database/migrations/2023_06_21_071812_add_description_to_publications_table.php b/database/migrations/2023_06_21_071812_add_description_to_publications_table.php deleted file mode 100644 index b3aec44..0000000 --- a/database/migrations/2023_06_21_071812_add_description_to_publications_table.php +++ /dev/null @@ -1,32 +0,0 @@ -addColumn('text', 'description')->after('excerpt')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('publications', function (Blueprint $table) { - $table->dropColumn('description'); - }); - } -} diff --git a/database/migrations/2023_06_21_195321_create_registry_categories_table.php b/database/migrations/2023_06_21_195321_create_registry_categories_table.php new file mode 100644 index 0000000..7150a00 --- /dev/null +++ b/database/migrations/2023_06_21_195321_create_registry_categories_table.php @@ -0,0 +1,36 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('registry_id')->index()->nullable(); + $table->integer('parent_id')->index()->default(0); + $table->string('name')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_categories'); + } +} diff --git a/database/migrations/2023_06_21_195350_create_registry_entries_table.php b/database/migrations/2023_06_21_195350_create_registry_entries_table.php new file mode 100644 index 0000000..44c2ba3 --- /dev/null +++ b/database/migrations/2023_06_21_195350_create_registry_entries_table.php @@ -0,0 +1,40 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('registry_id')->index()->nullable(); + $table->integer('category_id')->index()->nullable(); + $table->integer('asset_id')->index()->nullable(); + $table->string('number')->index()->nullable(); + $table->string('name')->index()->nullable(); + $table->date('active_since')->index()->nullable(); + $table->date('active_till')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_entries'); + } +} diff --git a/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php b/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php new file mode 100644 index 0000000..33fc39b --- /dev/null +++ b/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php @@ -0,0 +1,41 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('entry_id')->index()->nullable(); + $table->integer('order_id')->index()->nullable(); + $table->string('type')->index()->nullable(); + $table->string('developer')->index()->nullable(); + $table->string('order_name')->index()->nullable(); + $table->date('order_date')->index()->nullable(); + $table->date('active_since')->index()->nullable(); + $table->date('active_till')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_entry_operations'); + } +}