Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Is it possible to control specific images for "Number of images per page"?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1438 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    I wasn't exactly sure where to place it as I get errors or no result:

    MyImageGalleryPage.php

    <?php
    class MyImageGalleryPage extends ImageGalleryPage {
    protected function Items($limit = null) {
    if($limit === null && $this->MediaPerPage ) {
    if( !isset($_REQUEST['start']) || ! is_numeric( $_REQUEST['start'] ) )
    $_REQUEST['start'] = 0;

    $limit = $_REQUEST['start'] . "," . $this->MediaPerPage;
    }

    $filter = ($current_album = $this->CurrentAlbum()) ? "AlbumID = {$current_album->ID} AND" : "";
    /* new */
    $filter .= " Set = '1' AND";
    /* *** */
    $files = DataObject::get(
    $this->getItemClass(),
    "$filter ImageGalleryPageID = {$this->ID}",
    null,
    "",
    $limit
    );
    return $files;
    }
    }

    class MyImageGalleryPage_Controller extends ImageGalleryPage_Controller {

    }
    ?>

    Which shows this error:

    [User Error] Couldn't run query: SELECT `ImageGalleryItem`.*, `MyImageGalleryItem`.*, `ImageGalleryItem`.ID, if(`ImageGalleryItem`.ClassName,`ImageGalleryItem`.ClassName,'ImageGalleryItem') AS RecordClassName FROM `ImageGalleryItem` LEFT JOIN `MyImageGalleryItem` ON `MyImageGalleryItem`.ID = `ImageGalleryItem`.ID WHERE (AlbumID = 1 AND Set = '1' AND ImageGalleryPageID = 6) ORDER BY SortOrder ASC LIMIT 0,9 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Set = '1' AND ImageGalleryPageID = 6) ORDER BY SortOrder ASC LIMIT 0,9' at line 1

  • UncleCheese
    Avatar
    4085 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    Haha... That's funny. "Set" is a reserved keyword in MySQL. So change that to `Set`.

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    OK well that has helped, but I think this is kinda of working in reverse.. My gallery items which are checked as 'Set' are the ones I wish to hide the thumbs of, then keep the rest and have everything display in the lightbox via next, next etc.

    Using that code means it filters the ones which are not 'Set' completely and I am left with empty pages of the hidden thumbs. If I change:

    $filter .= " `Set` = '1' AND";

    to

    $filter .= " `Set` = '0' AND";

    It filters the correct ones the 'Set' items but the others are no longer part of the gallery at all, not in the code, and do not display in the lightbox...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    I think a better criterion to use is `Set` != '1', because by saying `Set` = '0', you're assuming set can only be 1 or 0, and my guess is there are some null values in there for whatever reason.

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    OK that is still showing the correct thumbs in the gallery, but the Set thumbs are still completely removed from the source and therefor the lightbox too..

  • UncleCheese
    Avatar
    4085 Posts

    Re: Is it possible to control specific images for "Number of images per page"? Link to this post

    Oh, so the Set images should be in the recordset after all?

    I'm not sure if what you're trying to do is even possible. Your visual page limit and your query record limit are inconsistent. I don't know how you could reconcile that without completely changing the way pagination is handled.

    That's certainly a tough one. If you get into a jam you can reach me through my website to commission the work. That's about all I can offer at this point.

    1438 Views
Page: 1 2
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.