Jump to:

7939 Posts in 1472 Topics by 944 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: 1311 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

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

    Im using a subclass of ImageGallery - 'MyImageGallery' and have set up a check box (Set) to hide certain images which are part of a set so they hide the thumbnails but are still part of the gallery.
    However I just started using it with "Number of images per page" and it still counts the hidden thumbs, therefore not showing the full amount per page. Can I control which images are counted in the "Number of images per page" count?

    Here's some of the code I'm using:

    GalleryUI_layout.ss

    <% control GalleryItems %>
             <% if Set %>$GalleryItem<% else %>
                <li style="height:auto;width:{$ThumbnailWidth}px;">
                   $GalleryItem
                 <p>$PaintingName</p>
                   
                </li><% end_if %>
             <% end_control %>

    Lightbox_Item.ss

    <% if Set %>
    <a id="ViewLink-$ID" rel="lightbox" class="lightbox" title="$Caption.EscapeXML" href="$ViewLink"></a>
    <% else %>
    <a id="ViewLink-$ID" rel="lightbox" class="lightbox" title="$Caption.EscapeXML" href="$ViewLink">
       <img src="$ThumbnailURL" alt="$Title.EscapeXML"/>
    </a>
    <% end_if %>

    MyImageGalleryItem.php

    <?php
    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'Set' => 'Boolean',
    'PaintingName' => 'Varchar(100)'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new CheckboxField('Set','Part of a set, hide the thumbnail'));
    $f->push(new TextField('PaintingName','Name of work'));
    return $f;
    }
    }
    ?>

    Thanks!

  • UncleCheese
    Avatar
    4085 Posts

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

    Yeah, this is the sort of complication you're going to run into when you remove an object from the display and not the recordset itself. What you really should be doing is filtering the query so that those non "Set" records aren't even counted.

    In your MyImageGalleryPage.php, overload the Items() method.

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

  • pinkp
    Avatar
    Community Member
    168 Posts

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

    thanks very much UncleCheese! but using the following code gives me this error:

    Parse error: syntax error, unexpected T_PROTECTED in /Users/me/Sites/SSsite/mysite/code/MyImageGalleryItem.php on line 21

    <?php

    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'Set' => 'Boolean',
    'PaintingName' => 'Varchar(100)'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new CheckboxField('Set','Part of a set, hide the thumbnail'));
    $f->push(new TextField('PaintingName','Name of work'));
    return $f;

    }
    }

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

    ?>

  • UncleCheese
    Avatar
    4085 Posts

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

    You pasted that code below the closing bracket of your class. Please be sure to check syntax before posting bugs.

  • pinkp
    Avatar
    Community Member
    168 Posts

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

    O yes, sorry about that I thought I did that!
    It flushes fine now without error but it hasn't effected the result. Images ticked "Set" are still being counted in the gallery..

  • UncleCheese
    Avatar
    4085 Posts

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

    Is this in MyImageGalleryItem or MyImageGalleryPage? See above...

    In your MyImageGalleryPage.php, overload the Items() method.

    But your code says ImageGalleryItem??

  • pinkp
    Avatar
    Community Member
    168 Posts

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

    Yes sorry that was wrong, one of those days!

    This is my MyImageGalleryPage.php

    <?php
    class MyImageGalleryPage extends ImageGalleryPage {
    protected $itemClass = "MyImageGalleryItem";
    }

    class MyImageGalleryPage_Controller extends ImageGalleryPage_Controller {

    }
    ?>

    I've tried adding your code various ways without success, could you please show me how this file should look, to overload the Items() method, thanks for your patience!

  • UncleCheese
    Avatar
    4085 Posts

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

    So you put the function in MyImageGalleryPage? It doesn't look like it's there.

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