where('expiration_date >=', date('Y-m-d')); if ($schoolYear) { $builder->where('school_year', $schoolYear); } return $builder->orderBy('expiration_date', 'ASC')->findAll(); } /** * Get events by name (partial match). * * @param string $name * @param string|null $schoolYear * @return array */ public function getEventsByName(string $name, $schoolYear = null) { $builder = $this->like('event_name', $name); if ($schoolYear) { $builder->where('school_year', $schoolYear); } return $builder->orderBy('expiration_date', 'ASC')->findAll(); } /** * Get all events. * * @param string|null $schoolYear * @return array */ public function getAllEvents($schoolYear = null) { $builder = $this; if ($schoolYear) { $builder = $builder->where('school_year', $schoolYear); } return $builder->orderBy('created_at', 'DESC')->findAll(); } /** * Add a new event. * * @param array $data * @return int|string|false */ public function addEvent(array $data) { return $this->insert($data); } /** * Get events by expiration date. * * @param string $date * @param string|null $schoolYear * @return array */ public function getEventsByDate($date, $schoolYear = null) { $builder = $this->where('expiration_date', $date); if ($schoolYear) { $builder->where('school_year', $schoolYear); } return $builder->findAll(); } /** * Get all active (not expired) events. * * @param string|null $schoolYear * @param string|null $semester * @return array */ public function getActiveEvents($schoolYear = null, $semester = null) { $builder = $this->where('expiration_date >=', date('Y-m-d')); if ($schoolYear) { $builder->where('school_year', $schoolYear); } if ($semester) { $builder->where('semester', $semester); } return $builder->orderBy('expiration_date', 'ASC')->findAll(); } /** * Get event by ID. * * @param int $id * @param string|null $schoolYear * @return array|null */ public function getEvent($id, $schoolYear = null) { $builder = $this->where('id', $id); if ($schoolYear) { $builder->where('school_year', $schoolYear); } return $builder->first(); } /** * Update event by ID. * * @param int $id * @param array $data * @param string|null $schoolYear * @return bool */ public function updateEvent($id, $data, $schoolYear = null) { if ($schoolYear) { // Ensure only updates for this school year $this->where('id', $id)->where('school_year', $schoolYear)->set($data)->update(); return true; } return $this->update($id, $data); } /** * Delete event by ID. * * @param int $id * @param string|null $schoolYear * @return bool */ public function deleteEvent($id, $schoolYear = null) { if ($schoolYear) { return $this->where('id', $id)->where('school_year', $schoolYear)->delete(); } return $this->delete($id); } }