Skip to content

Commit

Permalink
Fixed getAfgelopenAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamieljv committed Sep 6, 2024
1 parent 6d765ac commit 95d44ee
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/Models/Actie.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,32 @@ public function report()
return $this->hasOne(Report::class)->without('actie');
}

public function getAfgelopenAttribute()
{
return Date::parse($this->end_date . " " . $this->end_time)->timestamp < time();
}

public function getPublishedAttribute()
{
return $this->status === "PUBLISHED";
}

public function scopePublished($query)
public function getAfgelopenAttribute()
{
return $query->where('status', 'PUBLISHED');
if ($this->end_time === null) {
// if end_time is not set, take the end of the day
return Date::parse($this->end_date . " " . "23:59:59")->timestamp < time();
}
return Date::parse($this->end_date . " " . $this->end_time)->timestamp < time();
}

public function scopeNietAfgelopen($query)
{
// check if end_time is defined
return $query->whereRaw("STR_TO_DATE(CONCAT(end_date, ' ', end_time), '%Y-%m-%d %H:%i:%s') > '" . Date::now()->toDateTimeString() . "'")
->orWhereRaw("(end_time is NULL AND STR_TO_DATE(end_date, '%Y-%m-%d') >= '" . Date::now()->toDateString() . "')");
}

public function scopePublished($query)
{
return $query->where('status', 'PUBLISHED');
}

public function publish()
{
$this->status = 'PUBLISHED';
Expand Down

0 comments on commit 95d44ee

Please sign in to comment.