7913 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1143 Views |
-
Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 12:00am
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!
-
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 3:16am
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;
} -
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 9:05am
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;
}?>
-
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 9:34am
You pasted that code below the closing bracket of your class. Please be sure to check syntax before posting bugs.
-
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 9:50am
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.. -
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 10:56am
Is this in MyImageGalleryItem or MyImageGalleryPage? See above...
In your MyImageGalleryPage.php, overload the Items() method.
But your code says ImageGalleryItem??
-
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 11:14am
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!
-
Re: Is it possible to control specific images for "Number of images per page"?

23 December 2009 at 1:50pm
So you put the function in MyImageGalleryPage? It doesn't look like it's there.
| 1143 Views | ||
| Go to Top | Next > |

