Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Dec 15, 2023
1 parent f4f7262 commit 86c995d
Show file tree
Hide file tree
Showing 21 changed files with 563 additions and 17 deletions.
23 changes: 23 additions & 0 deletions app/Enums/AggressorLegalHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns;

enum AggressorLegalHistory: string
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
use Concerns\Enums\HasLabel;

case CRIMES = 'crimes';
case CONTRAVENTIONS = 'contraventions';
case PROTECTION_ORDER = 'protection_order';

protected function labelKeyPrefix(): ?string
{
return 'enum.aggressor_legal_history';
}
}
27 changes: 27 additions & 0 deletions app/Enums/AggressorRelationship.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns;

enum AggressorRelationship: string
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
use Concerns\Enums\HasLabel;

case MARITAL = 'marital';
case CONSENSUAL = 'consensual';
case FORMER_PARTNER = 'former_partner';
case PARENTAL = 'parental';
case FILIAL = 'filial';
case OTHER_RELATED = 'other_related';
case OTHER = 'other';

protected function labelKeyPrefix(): ?string
{
return 'enum.aggressor_relationship';
}
}
26 changes: 26 additions & 0 deletions app/Enums/Drug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns;

enum Drug: string
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
use Concerns\Enums\HasLabel;

case ALCOHOL_OCCASIONAL = 'alcohol_occasional';
case ALCOHOL_FREQUENT = 'alcohol_frequent';
case TOBACCO = 'tobacco';
case TRANQUILIZERS = 'tranquilizers';
case DRUGS = 'drugs';
case OTHER = 'other';

protected function labelKeyPrefix(): ?string
{
return 'enum.drug';
}
}
29 changes: 29 additions & 0 deletions app/Enums/Violence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns;

enum Violence: string
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
use Concerns\Enums\HasLabel;

case VERBAL = 'verbal';
case PSYCHOLOGICAL = 'psychological';
case PHYSICAL = 'physical';
case SEXUAL = 'sexual';
case ECONOMIC = 'economic';
case SOCIAL = 'social';
case SPIRITUAL = 'spiritual';
case CYBER = 'cyber';
case DEPRIVATION = 'deprivation';

protected function labelKeyPrefix(): ?string
{
return 'enum.violence';
}
}
18 changes: 18 additions & 0 deletions app/Filament/Admin/Pages/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Filament\Admin\Pages;

use Filament\Pages\Dashboard as BaseDashboard;
use Illuminate\Contracts\Support\Htmlable;

class Dashboard extends BaseDashboard
{
public function getHeading(): string | Htmlable
{
return __('dashboard.welcome', [
'name' => auth()->user()->first_name,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace App\Filament\Organizations\Resources\BeneficiaryResource\Pages;

use App\Enums\AggressorLegalHistory;
use App\Enums\AggressorRelationship;
use App\Enums\CivilStatus;
use App\Enums\Drug;
use App\Enums\Gender;
use App\Enums\HomeOwnership;
use App\Enums\Income;
use App\Enums\Occupation;
use App\Enums\Studies;
use App\Enums\Ternary;
use App\Enums\Violence;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
Expand Down Expand Up @@ -77,8 +83,8 @@ protected static function beneficiarySection(): Section
->enum(Ternary::class)
->live(),

TextInput::make('psychiatric_history_notes')
->label(__('field.psychiatric_history_notes'))
TextInput::make('psychiatric_notes')
->label(__('field.psychiatric_notes'))
->visible(fn (Get $get) => Ternary::isYes($get('psychiatric_history'))),
]),

Expand All @@ -91,8 +97,8 @@ protected static function beneficiarySection(): Section
->enum(Ternary::class)
->live(),

TextInput::make('criminal_history_notes')
->label(__('field.criminal_history_notes'))
TextInput::make('criminal_notes')
->label(__('field.criminal_notes'))
->visible(fn (Get $get) => Ternary::isYes($get('criminal_history'))),
]),

Expand Down Expand Up @@ -133,4 +139,132 @@ protected static function beneficiarySection(): Section
->enum(HomeOwnership::class),
]);
}

protected static function aggressorSection(): Section
{
return Section::make(__('beneficiary.section.personal_information.section.aggressor'))
->relationship('aggressor')
->columns()
->schema([
Select::make('relationship')
->label(__('field.aggressor_relationship'))
->placeholder(__('placeholder.select_one'))
->options(AggressorRelationship::options())
->enum(AggressorRelationship::class)
->live(),

TextInput::make('age')
->label(__('field.aggressor_age'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(200),

Select::make('gender')
->label(__('field.aggressor_gender'))
->placeholder(__('placeholder.select_one'))
->options(Gender::options())
->enum(Gender::class),

Select::make('citizenship_id')
->label(__('field.aggressor_citizenship'))
->placeholder(__('placeholder.citizenship'))
->relationship('citizenship', 'name')
->nullable(),

Select::make('civil_status')
->label(__('field.aggressor_civil_status'))
->placeholder(__('placeholder.civil_status'))
->options(CivilStatus::options())
->enum(CivilStatus::class),

Select::make('studies')
->label(__('field.aggressor_studies'))
->placeholder(__('placeholder.studies'))
->options(Studies::options())
->enum(Studies::class),

Select::make('occupation')
->label(__('field.aggressor_occupation'))
->placeholder(__('placeholder.select_one'))
->options(Occupation::options())
->enum(Occupation::class),

Grid::make()
->schema([
Select::make('has_violence_history')
->label(__('field.aggressor_has_violence_history'))
->placeholder(__('placeholder.select_one'))
->options(Ternary::options())
->enum(Ternary::class)
->live(),

Select::make('violence_types')
->label(__('field.aggressor_violence_types'))
->placeholder(__('placeholder.select_many'))
->visible(fn (Get $get) => Ternary::isYes($get('violence_history')))
->options(Violence::options())
->enum(Violence::class)
->multiple(),

]),

Grid::make()
->schema([
Select::make('has_psychiatric_history')
->label(__('field.aggressor_has_psychiatric_history'))
->placeholder(__('placeholder.select_one'))
->options(Ternary::options())
->enum(Ternary::class)
->live(),

TextInput::make('psychiatric_history_notes')
->label(__('field.aggressor_psychiatric_history_notes'))
->visible(fn (Get $get) => Ternary::isYes($get('psychiatric_history'))),
]),

Grid::make()
->schema([
Select::make('has_drug_history')
->label(__('field.aggressor_has_drug_history'))
->placeholder(__('placeholder.select_one'))
->options(Ternary::options())
->enum(Ternary::class)
->live(),

Select::make('drugs')
->label(__('field.aggressor_drugs'))
->placeholder(__('placeholder.select_many'))
->visible(fn (Get $get) => Ternary::isYes($get('has_drug_history')))
->options(Drug::options())
->enum(Drug::class)
->multiple(),
]),

Grid::make()
->schema([
Select::make('legal_history')
->label(__('field.aggressor_legal_history'))
->placeholder(__('placeholder.select_many'))
->visible(fn (Get $get) => Ternary::isYes($get('violence_history')))
->options(AggressorLegalHistory::options())
->enum(AggressorLegalHistory::class)
->multiple()
->live(),
]),

Grid::make()
->schema([
Select::make('has_protection_order')
->label(__('field.has_protection_order'))
->placeholder(__('placeholder.select_one'))
->options(Ternary::options())
->enum(Ternary::class)
->live(),

TextInput::make('protection_order_notes')
->label(__('field.protection_order_notes')),
]),
]);
}
}
64 changes: 64 additions & 0 deletions app/Models/Aggressor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace App\Models;

use App\Concerns\HasCitizenship;
use App\Enums\AggressorLegalHistory;
use App\Enums\AggressorRelationship;
use App\Enums\CivilStatus;
use App\Enums\Drug;
use App\Enums\Gender;
use App\Enums\Occupation;
use App\Enums\Studies;
use App\Enums\Ternary;
use App\Enums\Violence;
use Illuminate\Database\Eloquent\Casts\AsEnumCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Aggressor extends Model
{
use HasCitizenship;
use HasFactory;

protected $fillable = [
'age',
'civil_status',
'drugs',
'has_drug_history',
'has_protection_order',
'has_psychiatric_history',
'has_violence_history',
'legal_history',
'occupation',
'protection_order_notes',
'psychiatric_history_notes',
'relationship',
'studies',
'violence_types',
];

protected $casts = [
'age' => 'integer',
'civil_status' => CivilStatus::class,
'drugs' => AsEnumCollection::class . ':' . Drug::class,
'gender' => Gender::class,
'has_drug_history' => Ternary::class,
'has_protection_order' => Ternary::class,
'has_psychiatric_history' => Ternary::class,
'has_violence_history' => Ternary::class,
'legal_history' => AsEnumCollection::class . ':' . AggressorLegalHistory::class,
'occupation' => Occupation::class,
'relationship' => AggressorRelationship::class,
'studies' => Studies::class,
'violence_types' => AsEnumCollection::class . ':' . Violence::class,
];

public function beneficiary(): BelongsTo
{
return $this->belongsTo(Beneficiary::class);
}
}
7 changes: 7 additions & 0 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Beneficiary extends Model
{
Expand Down Expand Up @@ -127,6 +128,12 @@ public function legalResidenceCity(): BelongsTo
return $this->belongsTo(City::class, 'legal_residence_city_id');
}

public function aggressor(): HasOne
{
return $this->hasOne(Aggressor::class)
->withDefault();
}

public function age(): Attribute
{
return Attribute::make(
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public function registerMediaCollections(): void
->registerMediaConversions(function () {
$this->addMediaConversion('thumb')
->fit(Manipulations::FIT_CONTAIN, 64, 64)
->keepOriginalImageFormat()
->optimize();

$this->addMediaConversion('large')
->fit(Manipulations::FIT_CONTAIN, 256, 256)
->keepOriginalImageFormat()
->optimize();
});
}
Expand Down
Loading

0 comments on commit 86c995d

Please sign in to comment.