7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » trying to get the latest images out of an ImageObject
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 438 Views |
-
trying to get the latest images out of an ImageObject

1 February 2012 at 10:44pm Last edited: 1 February 2012 10:52pm
Hi @ all,
I'm trying to create my own image gallery. The galleries preview at the holder, should contain the last 4 images of this gallery.
The way i tried it doesn't work. I hope someone could help me.The relations between the single pages and objects
GalleryHolder.php -> GalleryPage.php -> GalleryImagesObject.php -> Image Image Image ...The GalleryHolder.php has this two function to sort the galleries and to get the latest 4 images of each gallery
public function getGalleries() {
return DataObject::get('GalleryPage', "ParentID = '$this->ID'", 'Date DESC');
}
function LatestGalleryImages($num=4) {
$galleryimage = DataObject::get_one("GalleryHolder");
return ($galleryimage) ? DataObject::get("GalleryPage", "ParentID = $galleryimage->ID", "Date DESC", "", $num) : false;
}that's the GalleryImagesObject.php
<?php
class GalleryImagesObject extends DataObject {public static $db = array(
'Title' => 'Text',
'Description' => 'Text'
);public static $has_one = array(
'GalleryImage' => 'Image',
'GalleryPage' => 'GalleryPage'
);public function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Title', 'Titel des Bildes'),
new TextAreaField('Description', 'Beschreibung des Bildes'),
new ImageField('GalleryImage', 'Bild(er) hochladen')
);}
}?>
and my GallerHolder.ss looks like this.
<% control getGalleries %>
<% control GalleryImagesObject %>
$GalleryImage
<% end_control %>
<a href="$Link" title="Die Gallerie $Title anzeigen">$Title</a>
<% end_control %>
-----Where's the mistake(s) i made? I can see the link but not the images
Thx for your HelpBenni
P.s. Website
-
Re: trying to get the latest images out of an ImageObject

2 February 2012 at 4:44am
How does GalleryPage relate to GalleryImageObject?
--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com -
Re: trying to get the latest images out of an ImageObject

2 February 2012 at 5:08am Last edited: 2 February 2012 7:54am
Sry, i think that was wrong in my first post. I'm not able to describe the relations good in english.
Thats the GalleryPage.php I hope it will help
<?php
class GalleryPage extends Page {
static $allowed_children = 'none';
static $default_parrent = 'GalleryHolder';
static $can_be_root = false;public static $db = array(
'Date' => 'Date',
'Description' => 'HTMLText',
//'ThumbnailSize' => 'Text',
);
public static $has_many = array(
'GalleryImages' => 'GalleryImagesObject'
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Content.Main', 'Content');
$fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Datum der Aufnahmen'));
$date->setConfig('showcalendar', true);
$fields->addFieldToTab('Root.Content.Main', new SimpleTinyMCEField('Description','Beschreibung der Gallerie'));
//$fields->addFieldToTab('Root.Content.Main', new TextField('ThumbnailSize','Größe der Thumbnails (in px / muss ausgefüllt sein)'));
$fields->addFieldToTab('Root.Content.Main', $GalleryImages = new ImageDataObjectManager($this, 'GalleryImages', 'GalleryImagesObject', 'GalleryImage', array('Title' => 'Titel des Bildes', 'Description' => 'Beschreibung des Bildes'), 'getCMSFields_forPopup'));
$GalleryImages->copyOnImport = false;
//$GalleryImages->setPageSize( '999' );
$GalleryImages->setPerPageMap('50');
$GalleryImages->setPageSize('50');
return $fields;
}
}class GalleryPage_Controller extends Page_Controller {
public function PrevNextPage($Mode = 'next') {
if($Mode == 'next'){
$Where = "ParentID = ($this->ParentID) AND Sort > ($this->Sort)";
$Sort = "Sort ASC";
}
elseif($Mode == 'prev'){
$Where = "ParentID = ($this->ParentID) AND Sort < ($this->Sort)";
$Sort = "Sort DESC";
}
else{
return false;
}
return DataObject::get("SiteTree", $Where, $Sort, null, 1);
}
}
?> -
Re: trying to get the latest images out of an ImageObject

6 February 2012 at 2:44am
Hmm is it possible to get the latest Entry out of an DataObject with the Mysql Field "Created" ? If got absolutly no knowlege about sql but i think it should be possible?!
Perhapse this is one way?
| 438 Views | ||
|
Page:
1
|
Go to Top |

