Skip to content

Commit

Permalink
Merge pull request #123 from Kamieljv/122-flagging-acties-as-afgelope…
Browse files Browse the repository at this point in the history
…n-is-not-working-yet

Fixed getAfgelopenAttribute
  • Loading branch information
Kamieljv authored Sep 14, 2024
2 parents 8537bf8 + 3036a7d commit 28cc029
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
23 changes: 14 additions & 9 deletions app/Models/Actie.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Actie extends Model
*/
protected $appends = [
'link',
'afgelopen',
'start_end',
'start_unix',
'_geoloc',
Expand Down Expand Up @@ -226,28 +227,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
7 changes: 1 addition & 6 deletions resources/views/assets/js/components/partials/Actie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="flex flex-col overflow-hidden rounded-lg shadow-lg actie relative transition-all ease-out hover:translate-y-[-0.250rem] hover:shadow-[0_0_20px_rgba(0,0,0,0.30)]"
typeof="Article"
>
<a :href="actie.link" class="h-full not-prose" :class="{'opacity-70 grayscale': isAfgelopen}" :title="isAfgelopen ? 'Deze actie is afgelopen' : actie.title ">
<a :href="actie.link" class="h-full not-prose" :class="{'opacity-70 grayscale': actie.afgelopen}" :title="actie.afgelopen ? 'Deze actie is afgelopen' : actie.title ">
<meta property="name" :content="actie.title">
<meta property="author" typeof="Person" content="admin">
<meta property="dateModified" :content="new Date(actie.updated_at).toISOString()">
Expand Down Expand Up @@ -128,11 +128,6 @@ export default {
type: Object,
required: true,
}
},
computed: {
isAfgelopen() {
return new Date(this.actie.end_date + " " + this.actie.end_time) < new Date()
}
}
}
</script>
Expand Down

0 comments on commit 28cc029

Please sign in to comment.