Complete adaptation from BukidBountyApp to Philippine barangay governance: - Barangay models: Resident, Household, HouseholdMember, Blotter, BlotterHearing, DocumentRequest, RequestPayment, RequestType, BarangayProject, BarangayBudget - Controllers: ResidentController, HouseholdController, BlotterController, BlotterHearingController, DocumentRequestController, RequestTypeController, ProjectController, BudgetController, QRPHController, AdminConsoleController, UserController, FileController, ChapterController, LoginController - Vue pages: Home, ManageResidents, ResidentProfile, ManageHouseholds, ManageBlotters, BlotterDetail, RequestDocument, ManageDocumentRequests, DocumentRequestDetail, ManageRequestTypes, ManageProjects, BudgetLedger, AdminConsole - Barangay roles: PunongBarangay, Kagawad, Secretary, Treasurer, SK, Tanod, BHW, Staff, Resident - UserPermissions matrix rewritten with barangay-specific permission mappings - VueRouteMap replaced with barangay SPA routes - UserActions enum references corrected across all controllers - Removed all market/cooperative/POS/subscription code and models
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
class Chapter extends Model
|
|
{
|
|
protected ?string $table = 'chapters';
|
|
|
|
protected array $fillable = [
|
|
'hashkey', 'name', 'level', 'parent_id', 'location_key',
|
|
'lat', 'lng', 'is_active', 'created_by', 'updated_by',
|
|
];
|
|
|
|
protected array $casts = [
|
|
'is_active' => 'boolean',
|
|
'lat' => 'float',
|
|
'lng' => 'float',
|
|
];
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(Chapter::class, 'parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(Chapter::class, 'parent_id');
|
|
}
|
|
|
|
public function chapterMembers()
|
|
{
|
|
return $this->hasMany(ChapterMember::class, 'chapter_id');
|
|
}
|
|
|
|
public function activeMembers()
|
|
{
|
|
return $this->chapterMembers()->where('is_active', true);
|
|
}
|
|
|
|
public function leaders()
|
|
{
|
|
return $this->activeMembers()->whereNotNull('position');
|
|
}
|
|
|
|
public static function findOrCreateByLocation(string $level, string $locationKey, ?int $parentId = null): self
|
|
{
|
|
$key = strtolower(trim($locationKey));
|
|
return static::firstOrCreate(
|
|
['level' => $level, 'location_key' => $key],
|
|
[
|
|
'hashkey' => hash('sha256', uniqid((string) now(), true)),
|
|
'name' => ucwords(strtolower($locationKey)),
|
|
'level' => $level,
|
|
'location_key' => $key,
|
|
'parent_id' => $parentId,
|
|
'is_active' => true,
|
|
]
|
|
);
|
|
}
|
|
}
|