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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[SOLVED] ImageGallery - Previous/Next Album


Go to End


8 Posts   1570 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 11:12am

Edited: 22/05/2009 11:47am

Hi all,

I have UncleCheese's ImageGallery module installed on 2.3.1 and everything seems to be fine. I have added three albums: First Album, Second Album and Last Album.

The oddity I am noticing is where it display's Previous and Next album navigation.

When First Album is open:
Previous Album = blank (correct)
Next Album = Last Album (incorrect)

When Second Album is open:
Previous Album = First Album (correct)
Next Album = Last Album (correct)

When Last Album is open:
Previous Album = First Album (incorrect)
Next Album = blank (correct)

Known bug? Any ideas?

Cheers
Aaron

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 May 2009 at 11:17am

I'm aware of it. The problem is in assigning a default sort value to a newly created Album. They probably all have null values or 0 right now so it's not able to order them correctly. You can do a quick fix by sorting the albums once in the DataObjectManager. Even if you don't re-order them, just pick one up and put it down to call the script.

I'll put this in the bug reports thread.

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 11:28am

Cheers mate.

I deleted the albums and added them again (in order) to see what happened in the table sortorder. As follows:

First Album = 0
Second Album = 2
Last Album = 3

I then dragged First Album under Second Album
First Album = 1
Second Album = 0
Last Album = 2

Then dragged First Album to the first position and:
First Album = 0
Second Album = 1
Last Album = 2

Yet, First Album behaviour is the same. Second and now Last Album are working as expected.

Aaron

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 11:43am

Hi UC,

I have fixed the bug on my installation, and it was to do with the Sort order in the adjacentAlbum method of ImageGalleryPage.php

Orig code:

protected function adjacentAlbum($dir) 
	{
		$t = $dir == "next" ? ">" : "<";
		return DataObject::get_one(
			"ImageGalleryAlbum",
			"ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}", 
			false,
			"SortOrder DESC"
		);
		
	}

My fix: See extra $sort var, and the insertion of that var in the Sort param for the query.

protected function adjacentAlbum($dir) 
	{
		$t = $dir == "next" ? ">" : "<";
		$sort = $dir == "next" ? "ASC" : "DESC";
		return DataObject::get_one(
			"ImageGalleryAlbum",
			"ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}", 
			false,
			"SortOrder $sort"
		);
		
	}

It appears that simple Less Than, Greater Than where statements are dependant on the order of table contents, depending on which end of the Album Order the current request is coming from.

Cheers
Aaron

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 11:46am

Confirm adding forth album. All Prev/Next links are displaying as expected.

Cheers
Aaron

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 11:56am

Confirm deleting all albums and adding the test 3 from scratch. All Prev/Next links displaying as expected.

Cheers
Aaron

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 May 2009 at 1:40pm

Gah... what a bonehead mistake. Thanks for figuring it out. I'll check in the update.

Avatar
Double-A-Ron

Community Member, 607 Posts

22 May 2009 at 2:01pm

Given the coolness and intricacy of the module, a few little logic hiccups are to be expected.

Kudos on this work mate.

Cheers
Aaron