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
+122 -130
View File
@@ -7,7 +7,10 @@ use App\Models\BaseModel;
class Event extends BaseModel
{
protected $table = 'events';
protected $primaryKey = 'id';
// ✅ CI: timestamps enabled (created_at/updated_at)
public $timestamps = true;
protected $fillable = [
'event_name',
'event_category',
@@ -21,164 +24,153 @@ class Event extends BaseModel
'created_at',
'updated_at',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $casts = [
'amount' => 'decimal:2', // adjust precision if needed
'expiration_date' => 'date', // change to 'datetime' if stored as DATETIME
'created_by' => 'integer',
];
/* Optional relationships */
public function charges()
{
return $this->hasMany(EventCharge::class, 'event_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
/* =========================
* CI method equivalents
* ========================= */
/**
* Get all upcoming events (not expired).
*
* @return array
*/
public function getUpcomingEvents($schoolYear = null)
{
$builder = $this->where('expiration_date >=', date('Y-m-d'));
public static function getUpcomingEvents(?string $schoolYear = null)
{
$q = static::query()
->whereDate('expiration_date', '>=', now()->toDateString());
if ($schoolYear) {
$builder->where('school_year', $schoolYear);
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
return $q->orderBy('expiration_date', 'asc')->get();
}
return $builder->orderBy('expiration_date', 'ASC')->findAll();
}
/**
* Get events by name (partial match).
*/
public static function getEventsByName(string $name, ?string $schoolYear = null)
{
$q = static::query()
->where('event_name', 'like', '%' . $name . '%');
/**
* 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 (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
if ($schoolYear) {
$builder->where('school_year', $schoolYear);
return $q->orderBy('expiration_date', 'asc')->get();
}
return $builder->orderBy('expiration_date', 'ASC')->findAll();
}
/**
* Get all events (optionally filtered by school year).
*/
public static function getAllEvents(?string $schoolYear = null)
{
$q = static::query();
/**
* Get all events.
*
* @param string|null $schoolYear
* @return array
*/
public function getAllEvents($schoolYear = null)
{
$builder = $this;
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
if ($schoolYear) {
$builder = $builder->where('school_year', $schoolYear);
return $q->orderByDesc('created_at')->get();
}
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);
/**
* Add a new event. Returns inserted id.
*/
public static function addEvent(array $data): int
{
$row = static::create($data);
return (int) $row->id;
}
return $builder->findAll();
}
/**
* Get events by expiration date.
*/
public static function getEventsByDate(string $date, ?string $schoolYear = null)
{
$q = static::query()->whereDate('expiration_date', $date);
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
/**
* 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);
return $q->get();
}
if ($semester) {
$builder->where('semester', $semester);
/**
* Get all active (not expired) events (optionally filtered by year/semester).
*/
public static function getActiveEvents(?string $schoolYear = null, ?string $semester = null)
{
$q = static::query()
->whereDate('expiration_date', '>=', now()->toDateString());
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
if (!empty($semester)) {
$q->where('semester', $semester);
}
return $q->orderBy('expiration_date', 'asc')->get();
}
return $builder->orderBy('expiration_date', 'ASC')->findAll();
}
/**
* Get event by id (optionally filtered by school year).
*/
public static function getEvent(int $id, ?string $schoolYear = null): ?self
{
$q = static::query()->whereKey($id);
/**
* 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 (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
if ($schoolYear) {
$builder->where('school_year', $schoolYear);
return $q->first();
}
return $builder->first();
}
/**
* Update event by id (optionally constrained to a school year).
*/
public static function updateEvent(int $id, array $data, ?string $schoolYear = null): bool
{
$q = static::query()->whereKey($id);
/**
* 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;
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
return $q->update($data) >= 0;
}
return $this->update($id, $data);
}
/**
* Delete event by id (optionally constrained to a school year).
*/
public static function deleteEvent(int $id, ?string $schoolYear = null): bool
{
$q = static::query()->whereKey($id);
/**
* 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();
if (!empty($schoolYear)) {
$q->where('school_year', $schoolYear);
}
return (bool) $q->delete();
}
return $this->delete($id);
}
}
}