Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern - Improved code organization and maintainability - Fixed minor bugs and inconsistencies
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Education\Models;
|
||||
|
||||
use App\Ship\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
class AdmissionCampaign extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'info' => 'array'
|
||||
];
|
||||
|
||||
public function admission_plans(): HasMany
|
||||
{
|
||||
return $this->hasMany(AdmissionPlan::class, 'admission_campaigns_id', 'id');
|
||||
}
|
||||
|
||||
public function educationalPrograms(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
EducationalProgram::class,
|
||||
AdmissionPlan::class,
|
||||
'admission_campaigns_id', // внешний ключ в AdmissionPlan
|
||||
'id', // внешний ключ в EducationalPrograms
|
||||
'id', // локальный ключ в AdmissionCampaign
|
||||
'educational_programs_id' // локальный ключ в AdmissionPlan
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Education\Models;
|
||||
|
||||
use App\Ship\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AdmissionPlan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'exams' => 'array',
|
||||
'contests' => 'array'
|
||||
];
|
||||
|
||||
public function educationalProgram(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EducationalProgram::class, 'educational_programs_id', 'id');
|
||||
}
|
||||
|
||||
public function admissionCampaign(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AdmissionCampaign::class, 'admission_campaigns_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Education\Models;
|
||||
|
||||
use App\Ship\Enums\Education\LevelEducational;
|
||||
use App\Ship\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
|
||||
class DirectionStudy extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'lvl_edu' => LevelEducational::class,
|
||||
];
|
||||
|
||||
public function programs(): HasMany
|
||||
{
|
||||
return $this->hasMany(EducationalProgram::class);
|
||||
}
|
||||
|
||||
public function scopeWithActivePrograms(Builder $query): Builder
|
||||
{
|
||||
return $query->with(['programs' => function ($query) {
|
||||
$query->whereHas('admission_plans.admissionCampaign', function ($q) {
|
||||
$q->where('status', 1);
|
||||
});
|
||||
}]);
|
||||
}
|
||||
|
||||
public function scopeWithActiveAdmissionCampaign(Builder $query): Builder
|
||||
{
|
||||
return $query->whereHas('programs.admission_plans.admissionCampaign', function ($q) {
|
||||
$q->where('status', 1);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeWithAdmissionCampaignByYear(Builder $query, string $year): Builder
|
||||
{
|
||||
return $query->whereHas('programs.admission_plans.admissionCampaign', function ($q) use ($year) {
|
||||
$q->where('status', 1)->where('academic_year', $year);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeForBachelorLevel(Builder $query): Builder
|
||||
{
|
||||
return $query->where('lvl_edu', LevelEducational::BACHELOR);
|
||||
}
|
||||
|
||||
public function scopeForMiddleLevel(Builder $query): Builder
|
||||
{
|
||||
return $query->whereIn('lvl_edu', [LevelEducational::MIDDLE_LEVEL_SPECIALIST_TRAINING, LevelEducational::PREPARATION_OF_QUALIFIED_WORKERS]);
|
||||
}
|
||||
|
||||
public function scopeForMasterLevel(Builder $query): Builder
|
||||
{
|
||||
return $query->where('lvl_edu', LevelEducational::MASTER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Education\Models;
|
||||
|
||||
use App\Containers\InstituteStructure\Models\Department;
|
||||
use App\Ship\Enums\Education\LevelEducational;
|
||||
use App\Ship\Models\Model;
|
||||
use App\Ship\Traits\HasSeo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class EducationalProgram extends Model
|
||||
{
|
||||
use HasFactory, HasSeo;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
|
||||
protected $casts = [
|
||||
'program_features' => 'array',
|
||||
'about_program' => 'array',
|
||||
'learning_forms' => 'array',
|
||||
'lvl_edu' => LevelEducational::class,
|
||||
];
|
||||
|
||||
public function directionStudy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DirectionStudy::class);
|
||||
}
|
||||
|
||||
public function departments(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Department::class, 'program_department');
|
||||
}
|
||||
|
||||
|
||||
public function admission_plans(): HasMany
|
||||
{
|
||||
return $this->hasMany(AdmissionPlan::class, 'educational_programs_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user