I am have tried this many different ways and cannot seem to get this to work.
I have a class ProductView that extends DataObject and has a 1-to-many relationship with a ProductPage. The ProductView class contains a field for ThumbnailWidth (numeric) and a has_one relation Page_Image. In my template, I loop through the ProductView DataObjectSet and am trying to output a resized version of the Image according to the maximum ThumbnailWidth that has been entered in the CMS.
I cannot seem to figure out how to retrieve the ThumbnailWidth value of the ProductView within the Page_Image class. I obviously need a get_one statement, but i cannot seem to grab the ID of the ProductView once i am in the Page_Image class. Does anyone know how to do this?
ProductView.php
<?php
class ProductView extends DataObject {
static $db = array(
'ViewTitle' => 'Text',
'ViewDescription' => 'Text',
'ThumbnailWidth' => 'Int'
);
static $has_one = array(
'ProductPage' => 'ProductPage',
'ViewImage' => 'Page_Image'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('ViewTitle', 'Title'),
new TextareaField('ViewDescription', 'Description'),
new NumericField('ThumbnailWidth', 'Thumbnail Width (pixels)','150'),
new ImageField('ViewImage', 'Image')
);
}
}
?>
ProductPage.ss
<% control ProductViewOther %>
<div style="padding-right:20px;float:left;">
<a class="thickbox" rel="ViewImage" title="$ViewTitle" href="$ViewImage.URL"><img src="$ViewImage.ProductPageThumbResize.URL" /></a>
</div>
<% end_control %>
ProductViewOther method in ProductPage.php
/******************************************
* Product View Other - For Product Page
*******************************************/
function ProductViewOther() {
$doSet = DataObject::get(
$callerClass = "ProductView",
$filter = "`ProductPageID` = '".$this->ID."' and `ViewMain` = 'No'"
);
return $doSet ? $doSet : false;
}
Page_Image class on Page.php
class Page_Image extends Image {
function generateProductPageThumbResize($gd) {
<---need to get ProductView ID here so I can retrieve ThumbnailWidth value and assign $newWidth--->
return $gd->resizeByWidth($newWidth);
}
}