reconstruction of the project

This commit is contained in:
root
2026-03-08 16:33:24 -04:00
parent 23b7db1107
commit c8de5f7edc
9157 changed files with 77877 additions and 1073823 deletions
+55 -54
View File
@@ -7,8 +7,10 @@ use App\Models\BaseModel;
class EmergencyContact extends BaseModel
{
protected $table = 'emergency_contacts';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
// ✅ CI: useTimestamps = true (created_at/updated_at)
public $timestamps = true;
protected $fillable = [
'emergency_contact_name',
'parent_id',
@@ -20,76 +22,75 @@ class EmergencyContact extends BaseModel
'created_at',
'updated_at',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $casts = [
'parent_id' => 'integer',
'student_id' => 'integer',
'authorized_user_id' => 'integer',
];
/**
* Get emergency contact by student ID.
*
* @param int $studentId
* @return array
*/
public function getEmergencyContactsByStudentId($studentId)
/* Optional relationships */
public function parent()
{
return $this->where('student_id', $studentId)
->findAll();
return $this->belongsTo(User::class, 'parent_id');
}
/**
* Get emergency contact by parent ID.
*
* @param int $parentId
* @return array
*/
/*
public function getEmergencyContactsByParentId($parentId)
public function student()
{
return $this->groupStart()
->where('parent_id', $parentId)
->groupEnd()
->findAll();
return $this->belongsTo(Student::class, 'student_id');
}
*/
/**
* Get authorized user's emergency contact.
*
* @param int $authorizedUserId
* @return array|null
*/
public function getEmergencyContactByAuthorizedUserId($authorizedUserId)
public function authorizedUser()
{
return $this->where('authorized_user_id', $authorizedUserId)
return $this->belongsTo(User::class, 'authorized_user_id');
}
/* =========================
* CI method equivalents
* ========================= */
public static function getEmergencyContactsByStudentId(int $studentId)
{
return static::query()
->where('student_id', $studentId)
->get();
}
public static function getEmergencyContactByAuthorizedUserId(int $authorizedUserId): ?self
{
return static::query()
->where('authorized_user_id', $authorizedUserId)
->first();
}
/**
* Get all emergency contacts for a specific student and their associated parents or authorized user.
*
* @param int $studentId
* @return array
* Your CI logic: (student_id = $studentId) OR (parent_id = $studentId)
* Keeping it exactly as-is, even though the 2nd condition looks unusual.
*/
public function getAllEmergencyContacts($studentId)
public static function getAllEmergencyContacts(int $studentId)
{
return $this->groupStart()
->where('student_id', $studentId)
->orWhere('parent_id', $studentId)
->groupEnd()
->findAll();
return static::query()
->where(function ($q) use ($studentId) {
$q->where('student_id', $studentId)
->orWhere('parent_id', $studentId);
})
->get();
}
// Function to get the emergency contact based on parent_id
public function getEmergencyContactByParentId($parentId)
public static function getEmergencyContactByParentId(int $parentId): ?array
{
// Query to retrieve the emergency contact details using either parent_id or secondparent_id
return $this->where('parent_id', $parentId)
->select('emergency_contact_name, cellphone')
->first(); // Use `first()` to get a single result
$row = static::query()
->where('parent_id', $parentId)
->select(['emergency_contact_name', 'cellphone'])
->first();
return $row ? $row->toArray() : null;
}
public function getEmergencyContactsByParentId($parentId)
public static function getEmergencyContactsByParentId(int $parentId)
{
return $this->where('parent_id', $parentId)->findAll();
return static::query()
->where('parent_id', $parentId)
->get();
}
}
}