Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Embargo / Expiry still displays blog posts in BlogHolder page

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1685 Views
  • seagull
    Avatar
    Community Member
    17 Posts

    Embargo / Expiry still displays blog posts in BlogHolder page Link to this post

    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.

  • seagull
    Avatar
    Community Member
    17 Posts

    Re: Embargo / Expiry still displays blog posts in BlogHolder page Link to this post

    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;

  • seagull
    Avatar
    Community Member
    17 Posts

    Re: Embargo / Expiry still displays blog posts in BlogHolder page Link to this post

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

    Any suggestions?

  • Lamin Barrow
    Avatar
    Community Member
    21 Posts

    Re: Embargo / Expiry still displays blog posts in BlogHolder page Link to this post

    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

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Embargo / Expiry still displays blog posts in BlogHolder page Link to this post

    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.

    1685 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.