Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] ImageGallery - Previous/Next Album

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 937 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    [SOLVED] ImageGallery - Previous/Next Album Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

    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.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

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

    Cheers
    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

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

    Cheers
    Aaron

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] ImageGallery - Previous/Next Album Link to this post

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

    Kudos on this work mate.

    Cheers
    Aaron

    937 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.