Files
alrahma_sunday_school_api/app/Models/EmergencyContact.php
T
2026-03-05 12:29:37 -05:00

96 lines
2.4 KiB
PHP
Executable File

<?php
namespace App\Models;
use App\Models\BaseModel;
class EmergencyContact extends BaseModel
{
protected $table = 'emergency_contacts';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $fillable = [
'emergency_contact_name',
'parent_id',
'cellphone',
'email',
'relation',
'semester',
'school_year',
'created_at',
'updated_at',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
/**
* Get emergency contact by student ID.
*
* @param int $studentId
* @return array
*/
public function getEmergencyContactsByStudentId($studentId)
{
return $this->where('student_id', $studentId)
->findAll();
}
/**
* Get emergency contact by parent ID.
*
* @param int $parentId
* @return array
*/
/*
public function getEmergencyContactsByParentId($parentId)
{
return $this->groupStart()
->where('parent_id', $parentId)
->groupEnd()
->findAll();
}
*/
/**
* Get authorized user's emergency contact.
*
* @param int $authorizedUserId
* @return array|null
*/
public function getEmergencyContactByAuthorizedUserId($authorizedUserId)
{
return $this->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
*/
public function getAllEmergencyContacts($studentId)
{
return $this->groupStart()
->where('student_id', $studentId)
->orWhere('parent_id', $studentId)
->groupEnd()
->findAll();
}
// Function to get the emergency contact based on parent_id
public function getEmergencyContactByParentId($parentId)
{
// 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
}
public function getEmergencyContactsByParentId($parentId)
{
return $this->where('parent_id', $parentId)->findAll();
}
}