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
+38 -13
View File
@@ -7,10 +7,10 @@ use App\Models\BaseModel;
class ParentNotification extends BaseModel
{
protected $table = 'parent_notifications';
protected $primaryKey = 'id';
// ✅ CI: useTimestamps = true (created_at/updated_at)
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'student_id',
'code',
@@ -26,15 +26,40 @@ class ParentNotification extends BaseModel
'updated_at',
];
public function hasSent(int $studentId, string $code, string $incidentYmd, string $channel='email', ?string $to=null): bool
{
$qb = $this->where('student_id', $studentId)
->where('code', $code)
->where('incident_date', $incidentYmd)
->where('channel', $channel);
if ($to) $qb->where('to_address', $to);
protected $casts = [
'student_id' => 'integer',
// incident_date is stored as Y-m-d in CI usage
'incident_date' => 'date',
];
$row = $qb->orderBy('id','DESC')->first();
return $row && ($row['status'] ?? '') === 'sent';
/* Optional relationships */
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
}
/**
* Equivalent of CI hasSent()
*/
public static function hasSent(
int $studentId,
string $code,
string $incidentYmd,
string $channel = 'email',
?string $to = null
): bool {
$q = static::query()
->where('student_id', $studentId)
->where('code', $code)
->whereDate('incident_date', $incidentYmd)
->where('channel', $channel);
if (!empty($to)) {
$q->where('to_address', $to);
}
$row = $q->orderByDesc('id')->first();
return $row && (($row->status ?? '') === 'sent');
}
}