Skip to content

Commit

Permalink
Fix announcements display; move to Carbon instead of strings for date…
Browse files Browse the repository at this point in the history
… representations
  • Loading branch information
asmecher committed Dec 7, 2024
1 parent b8e3419 commit 9ca4c44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions classes/announcement/Announcement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/announcement/Announcement.php
*
Expand All @@ -15,6 +16,7 @@

use APP\core\Application;
use APP\file\PublicFileManager;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -166,13 +168,14 @@ protected function scopeWithTypeIds(EloquentBuilder $builder, array $typeIds): E
}

/**
* Limit returned announcements to those that have not expired by the specified date.
*
* @param string $date Optionally filter announcements by those
* not expired until $date (YYYY-MM-DD)
* not expired until $date
*/
protected function scopeWithActiveByDate(EloquentBuilder $builder, string $date = ''): EloquentBuilder
protected function scopeWithActiveByDate(EloquentBuilder $builder, Carbon $date = null): EloquentBuilder
{
return $builder->where('date_expire', '>', empty($date) ? Core::getCurrentDate() : $date)
return $builder->where('date_expire', '>', $date ?? Carbon::now())
->orWhereNull('date_expire');
}

Expand Down
2 changes: 1 addition & 1 deletion pages/index/PKPIndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function _setupAnnouncements(Context|Site $contextOrSite, $templateMgr
$announcements->withContextIds($contextIds);

$templateMgr->assign([
'announcements' => $announcements->get()->toArray(),
'announcements' => $announcements->get(),
'numAnnouncementsHomepage' => $numAnnouncementsHomepage,
]);
}
Expand Down

0 comments on commit 9ca4c44

Please sign in to comment.