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

Embargo / Expiry still displays blog posts in BlogHolder page


Go to End


5 Posts   2688 Views

Avatar
seagull

Community Member, 17 Posts

23 November 2009 at 10:03pm

So I know that this module is being phased out but I'm asking anyway. Embargo / Expiry works very well but it won't hide blog posts that are set to embargo. Is there anyway to stop blog previews from showing up in the BlogHolder page?

function canView($member) {} ??? works fro blogPage but not for BlogHolder??

Thanks.

Avatar
seagull

Community Member, 17 Posts

11 December 2009 at 5:22pm

Just got a reply from Simon Welsh, the author of the Embargo/Expiry Module. Thanks Simon that's a HUGE help.

It's to do with the BlogHolder not checking canView() on each of its children that it displays. I'm basing this off of the 0.2.1 release of the blog module.

In blog/code/BlogHolder.php, find (in the Entries method in the BlogHolder class):

return DataObject::get("Page","`ParentID` = $this->ID $tagCheck $dateCheck","`BlogEntry`.Date DESC",'',"$limit");

replace with:

$items = DataObject::get("Page","`ParentID` = $this->ID $tagCheck $dateCheck","`BlogEntry`.Date DESC");
$newSet = new DataObjectSet();
foreach($items as $item) {
if($item->canView()) $newSet->push($item);
}
if($limit) {
list($start, $length) = split(' *, *', $limit);
if(!$length) {
return $newSet->getRange(0, $start);
}
return $newSet->getRange($start, $length);
}
return $newSet;

Avatar
seagull

Community Member, 17 Posts

13 December 2009 at 12:31pm

okay now I've just discovered that the Blog Pagination has disappeared after changing the codeas shown above.

Any suggestions?

Avatar
Lamin Barrow

Community Member, 22 Posts

3 July 2010 at 3:12am

Edited: 03/07/2010 3:13am

I had the same problem too but mine wasn't associated with the BlogHolder. I was using custom page types and using a dataobject::get to get my custom pages in a paginated view.

Actually, there is an easy fix to this. Instead of modifying the core code, you can just edit your BlogHolder templates files and it should work painlessly as expect.

Like this.

<% control BlogPosts %>
<% if canView %>

<!-- The Post here -->

<% end_if %>
<% end_control %>

The embargo and expiring modules comes with the canView function. As you can see, you can use it in your template to filter posted based which posted get seen (you would see everything regardless of embargo or expiry restrictions if you are an admin) based on the embargo and expiry restriction.

I hope this helps.

Cheers
Lamin

Avatar
Gene

Community Member, 41 Posts

17 November 2010 at 11:10am

Edited: 17/11/2010 11:13am

The canView/Template method works great unless you're trying to limit the amount of records pulled in, in which case the records are filtered after the fact. If you want a replacement method to call you can add a BlogTreeDecorator and put these two methods inside...

	function ViewableEntries($limit = '', $tag = '', $date = '') {
		return $this->owner->Entries($limit, $tag, $date, array($this, 'canViewEntries'));
	}
	
	function canViewEntries($className, $filter, $limit, $order) {

		if (class_exists('EmbargoExpiryDecorator')) {
			$date = date('Y-m-d H:i:s');
			$embargo = " AND (Embargo IS NULL OR Embargo <= '$date')";
			$expiry = " AND (Expiry IS NULL OR Expiry >= '$date')";
			
			$filter .= $embargo . $expiry;
		}
		
		return DataObject::get('BlogEntry', $filter, $order, '', $limit);
	}

Then you can call ViewableEntries(4) in your template and get back exactly 4 viewable results.