Yes, the Embargo/Expiry module is deliberately simple. There are two ways to do this:
1) Get the database to do everything. This will still show pages that are expired (that's just another clause to add to the Where clause) and wont show pages to those that should be able to see them, even when embargoed/expired. You could add that logic in, but then you're starting to just imitate the canView() method.
function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "Embargo > NOW() AND ParentID = ".$this->LatestNewsID(), "Date DESC", "", $num) : false;
}
2) Get the canView() method to do all the processing. This adds a bit more of a load to PHP, as it will need to load more objects, but does handle all the logic nicely.
function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
if (!$news || !$news->exists()) {
return false;
}
$items = DataObject::get("ArticlePage", "ParentID = ".$this->LatestNewsID(), "Date DESC");
$pages = array();
if ($items) foreach ($items as $page) {
if ($page->canView()) $pages[] = $page;
if (count($pages) >= $num) break;
}
return new DataObjectSet($pages);
}
In case the code doesn't document itself enough, this gets all the possible ArticlePages, then adds them to an array until either all the pages have been looped through, or enough pages have been selected. Then a DataObjectSet ($items is also one of these) is created which contains these pages, and returned.