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

Is it possible to control specific images for "Number of images per page"?


Go to End


14 Posts   2367 Views

Avatar
pinkp

Community Member, 182 Posts

23 December 2009 at 10:42pm

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 December 2009 at 3:39am

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

Avatar
pinkp

Community Member, 182 Posts

24 December 2009 at 6:37am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 December 2009 at 6:43am

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.

Avatar
pinkp

Community Member, 182 Posts

24 December 2009 at 6:48am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 December 2009 at 7:27am

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.

Go to Top