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.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Gallery: show image details


Go to End


29 Posts   7848 Views

Avatar
DinaHansen

Community Member, 10 Posts

7 October 2009 at 10:41pm

Hi
I am working on a site for a gallery. I have searched everywhere (i think) looking for at gallery module, where I can include image details with the image. I have the ImageGallery installed atm, but I have difficulties working with it.

What I need is to be able to write something like this:

Name of the painting
Painter: Bla bla...
Year painted: Bla bla...
dimensions: Bla bla...

The text doens't need to show in fx. shadowbox (my chosen image viewer), but in the gallery page beside the image.

any help folks?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 October 2009 at 10:01am

ImageGallery allows you to subclass all of its components, so this should be no problem.

class MyGallery extends ImageGalleryPage
{
protected $itemClass = "MyImageGalleryItem";
}

class MyImageGalleryItem extends ImageGalleryItem
{
static $db = array (
'PaintingName' => 'Varchar(255)',
'Year' => 'Int'
// etc...
);

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('PaintingName','Name of painting'));
$f->push(new TextField('Year'));
return $f;
}
}

If you're using Shadowbox as your chosen GalleryUI, then you'll need to override Shadowbox_item.ss

/your_theme/templates/Shadowbox_item.ss

<a id="ViewLink-$ID" rel="shadowbox[gallery]" class="shadowbox" title="$Caption.EscapeXML" href="$ViewLink">
<img src="$ThumbnailURL" alt="$Title.EscapeXML"/>
</a>
<h3>$PaintingName</h3>
<h4>$Year</h4>

Run /dev/build.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 October 2009 at 10:04am

Edited: 08/10/2009 10:04am

Sorry, my bad. You need to override GalleryUI_layout.ss

/your_theme/templates/Includes/GalleryUI_layout.ss

		<% if GalleryItems %>
		<ul class="gallery-layout" id="gallery-list">
			<% if GalleryItems.NotFirstPage %>
				<% control PreviousGalleryItems %>
							<li style="display:none;">$GalleryItem</li>
				<% end_control %>
			<% end_if %>
			<% control GalleryItems %>
				<li style="height:{$ThumbnailHeight}px;width:{$ThumbnailWidth}px;">
						$GalleryItem
<h3>$PaintingName</h3>
<h4>$Year</h4>
				</li>
			<% end_control %>
			<% if GalleryItems.NotLastPage %>
				<% control NextGalleryItems %>
					<li style="display:none;">$GalleryItem</li>
				<% end_control %>
			<% end_if %>
		</ul>
		<% end_if %>

Avatar
pinkp

Community Member, 182 Posts

12 October 2009 at 3:17am

Edited: 12/10/2009 3:18am

Hi this is great exactly what I also needed. However Im having problems, Im new to the classes and php etc and I'm not sure where to put the code.

Question1.
I created MyGallery.php from your example and placed it in the ImageGallery code folder:

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

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

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('PaintingName','Name of painting'));
$f->push(new TextField('PaintingDimensions','Dimensions of painting'));
$f->push(new TextField('Media','Media'));
return $f;
}
}
?>

After a dev/build I got 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='15') AND (`ImageGalleryPageID` = '11')) ORDER BY SortOrder ASC LIMIT 0,10 Table 'jacquifenn.MyImageGalleryItem' doesn't exist

Sorry if this is a very obvious mistake but could you please advise me of exactly where and how to use the code?
I also changed the UI_layout as you described.

Question 2.

I also need a sold feature which will show a red dot next to the painting description.
Could you please suggest a way to do this?
i.e. a check box 'sold [ ]' in the pop up menu for each gallery item if ticked it shows a red dot, perhaps a jpg, next to the PaintingName.

Thank you for your time and any help!! much appreciated.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 October 2009 at 5:01am

1) Don't put anything in the image_gallery/code folder. You should never have to make alterations to the core module code. Add these classes to your mysite/code.

2) Each class needs its own file. You need to create MyImageGalleryPage.php AND MyImageGalleryItem.php each containing their corresponding PHP class.

3) To get your checkbox, just update your db fields and your fieldset in MyImageGalleryItem.php

static $db = array ( 
'PaintingName' => 'Varchar(100)', 
'PaintingDimensions' => 'Varchar(50)', 
'Media' => 'Varchar(50)' ,
'Sold' => 'Boolean'
// etc... 
);

public function getCMSFields_forPopup() 
{ 
$f = parent::getCMSFields_forPopup(); 
$f->push(new TextField('PaintingName','Name of painting')); 
$f->push(new TextField('PaintingDimensions','Dimensions of painting')); 
$f->push(new TextField('Media','Media')); 
$f->push(new CheckboxField('Sold','This painting is sold'));
return $f; 
} 
} 

Avatar
DinaHansen

Community Member, 10 Posts

12 October 2009 at 7:16am

thanks alot, I'll try make the changes!

/Dina

Avatar
pinkp

Community Member, 182 Posts

12 October 2009 at 8:28am

Hi sorry to be a pain but I can't get this to work. I've been reading the tutorials but don't understand. I've created:

MyImageGalleryItem.php

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

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

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('PaintingName','Name of painting'));
$f->push(new TextField('PaintingDimensions','Dimensions of painting'));
$f->push(new TextField('Media','Media'));
$f->push(new CheckboxField('Sold','This painting is sold'));
return $f;
}
}
?>

& MyImageGalleryPage.php

<?php
/**
 * Defines the MyImageGalleryPage page type
 */
 
class MyImageGalleryPage extends ImageGallery {
   static $db = array(
   );
   static $has_one = array(
   );
 
}
 
class MyImageGalleryPage_Controller extends ImageGallery_Controller {
	
}
?>

and placed these in mysite/code,
but again this just gives me errors after dev/build..?

Also how will the check box effect the actual page, if its ticked, how does this effect the page? (as I want this to be 'if ticked add image x.jpg' where $Sold appears)

THANKS for your patience!!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 October 2009 at 11:00am

You've got this a little backwards.

mysite/code/MyImageGalleryItem.php

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

public function getCMSFields_forPopup() 
{ 
$f = parent::getCMSFields_forPopup(); 
$f->push(new TextField('PaintingName','Name of painting')); 
$f->push(new TextField('PaintingDimensions','Dimensions of painting')); 
$f->push(new TextField('Media','Media')); 
$f->push(new CheckboxField('Sold','This painting is sold')); 
return $f; 
} 
} 
?>

/mysite/code/MyImageGalleryPage.php

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

class MyImageGalleryPage_Controller extends ImageGallery_Controller { 
    
} 

For the Sold boolean, you just need to evaluate that on your template.

<% if Sold %>sold<% else %>not sold<% end_if %>

Go to Top