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.

Blog Module /

Discuss the Blog Module.

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

Pagination has disappeard from BlogHolder


Go to End


6 Posts   4022 Views

Avatar
seagull

Community Member, 17 Posts

16 December 2009 at 9:38pm

In order to allow embargo/expiry on Blog posts I changed (with advice from Simon_w) BlogHolder.php (line 94)

from:

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

to:

$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;

This code made the pagination disappear and I'd really like it back. The code forces the blog posts through the canView function.

I'm running blog 0.2.1 on SS 2.3.3

Avatar
MarcusDalgren

Community Member, 288 Posts

19 December 2009 at 11:44am

As far as I know you can't use the built in pagination if you filter the DOSet. The pagination only looks at the original SQL query to figure out what/how to paginate so if you filter afterwards it gets very confused. So unless there's a way to rewrite that code so that it becomes an SQL query which gives you exactly what you need, SilverStripes pagination can't help you.

I've been thinking about either rolling my own pagination code for this scenario (which is pretty common on some sites I've built) or try to figure out a way to write an SQL query that factors in canView.

Avatar
seagull

Community Member, 17 Posts

12 January 2010 at 11:28pm

Thanks for your reply Smurkas. I would like to get this running but I'm not clued up on the engine running silverstripe. I removed

		if($limit) {
			list($start, $length) = split(' *, *', $limit);
			if(!$length) {
				return $newSet->getRange(0, $start);
			}
			return $newSet->getRange($start, $length);
		}

and this has allowed all blog postings which is fine for a quick fix, but as I add more posts I'll need to find a solution. I don't actually understand what the code is doing but obviously it is limiting the posts that are appended into $newSet. Removing this code shows all blog posts but it actually shows the pagination links now too, which are invalid because all posts are shown.

Avatar
Lamin Barrow

Community Member, 22 Posts

3 July 2010 at 3:29am

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
MarcusDalgren

Community Member, 288 Posts

3 July 2010 at 3:37am

It kind of does but you still get pretty weird behaviour. The way SilverStripes standard pagination works it only selects for example 10 rows from the database at a time. Since you don't know how many of those will pass canView with your code we'd get a variable number of BlogPosts depending on the canView settings. So for example page 1 could show 8 posts and page 2 could show 4 posts etc, and that's not ideal.

What you'd ideally want is a filtered set that is paginated afterwards. That way you'd get the same amounts of BogPosts per page. I actually have a solution for this, I'll post the code in this thread later today hopefully.

Avatar
mapes911

Community Member, 12 Posts

1 December 2010 at 9:26pm

hey all,

in case you came across this thread looking for a solution to this problem (like i was), i found a blog post that describes how to paginate a filtered data set.

hope this helps.

http://www.ssbits.com/tutorials/2010/paginating-a-filtered-dataobjectset/

cheers