<?php
class Page extends SiteTree {
public static $db = array(
);
public static $has_one = array(
);
static $has_many = array (
'GalleryImages' => 'GalleryImage'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this,
'GalleryImages',
'GalleryImage',
'Attachment',
array(
'Name' => 'Name'
),
'getCMSFields_forPopup'
);
$manager->setBrowseButtonText("Kies bestanden"); .
$manager->setGridLabelField('Name');
$manager->setPluralTitle('Afbeeldingen');
$f->addFieldToTab("Root.Content.Afbeeldingen", $manager);
return $f;
}
}
class GalleryImage extends DataObject
{
static $db = array (
'Name' => 'Text',
);
static $has_one = array (
'Attachment' => 'GalleryImage_ExtraImages',
'GalleryPage' => 'Page'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new FileIFrameField('Attachment')
);
}
}
class GalleryImage_ExtraImages extends Image {
function generateSmallThumb($gd) {
$myImage_width = $gd->getWidth();
$myImage_height = $gd->getHeight();
if($myImage_height > $myImage_width)
{
$myImage = $gd->resizeByWidth(200);
$myNewHeight = $myImage->getHeight();
$yPos = ($myNewHeight/2) - 70;
$myImage = $myImage->crop($yPos, 0, 200, 140);
$howManyGridLines = floor($totalHeight/21);
return $myImage;
} else {
return $gd->resizeRatio(200, 140, true);
}
}
function generateMainImage($gd) {
return $gd->resizeByWidth(800);
}
}
?>