Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

CMS Workflow installation problems


Go to End


42 Posts   5741 Views

Avatar
(deleted)

Community Member, 473 Posts

17 June 2010 at 7:45pm

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.

Avatar
Junglefish

Community Member, 109 Posts

17 June 2010 at 9:29pm

Hi Simon

Genius! I implemented the latter of your two options and that is perfect! Exactly what I was after.

Thanks for your help,

jf/

Go to Top