Hi, the Task I have to do is the Following.
A List of Dataobjects should be splitted over two divs. To make it easyer for the moment I split them in the middle. The the fist half should be printed in Column1, the SecondHalf in Column two.
I build the following Object and Controller with the methods FirstHalfProjectImages and LastHalfProjectImages.
<?php
class ProjectImagePage extends Page
{
static $has_many = array (
'ProjectImages' => 'ProjectImage'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this, // Controller
'ProjectImages', // Source name
'ProjectImage', // Source class
'Attachment', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$f->addFieldToTab("Root.Content.Projects", $manager);
return $f;
}
/*function ProjectImages(){
$images = DataObject::get('ProjectImages');
return $images;
}*/
}
class ProjectImagePage_Controller extends Page_Controller{
function FirstHalfProjectImages(){
$ProjectImages = DataObject::get("ProjectImage");
$half = round($ProjectImages->Count() / 2);
$doSet = new DataObjectSet();
$i = 1;
foreach($ProjectImages as $ProjectImage){
if($i <= $half){
$doSet->push($ProjectImage);
}
$i++;
}
return $doSet;
}
function LastHalfProjectImages(){
$ProjectImages = DataObject::get("ProjectImage");
$half = round($ProjectImages->Count() / 2);
$doSet = new DataObjectSet();
$i = 1;
foreach($ProjectImages as $ProjectImage){
if($i > $half){
$doSet->push($ProjectImage);
}
$i++;
}
return $doSet;
}
}
?>
<?php
class ProjectImage extends DataObject{
static $db = array (
'ProjektName' => 'Text',
'Description' => 'Text'
);
static $has_one = array (
'Attachment' => 'Image',
'ProjectImagePage' => 'ProjectImagePage'
);
public function getCMSFields_forPopup(){
return new FieldSet(
new TextField('ProjektName'),
new TextareaField('Description'),
new ImageField('Attachment')
);
}
}
?>
Now my Problem: The Code is working finde, but I have two Pages that are of ProjectImagePage-Type and each should show an own collection of ProjectImages. But the First/LastHalfProjectImages Methods are always getting the full List out of the ProjectImage Table. How do I filter only the ones related to the current ProjectImagePage?
Next Thing, I need ongoing Numbering for column1 and 2
My Template looks the following:
<div id="column1">
<% control FirstHalfProjectImages %>
<li><a href="#">$Pos. <span>$Description</span></a></li>
<% end_control %>
</div>
<div id="column2">
<% control LastHalfProjectImages %>
<li><a href="#">$Pos. <span>$Description</span></a></li>
<% end_control %>
</div>
But as you can imagine Numbering ($Pos) is starting with 1 again in Column2. How can I create and read from a variable to add its value to $Pos of Column2 so that it may starts with 6 if 5 ist the last $pos of Column1?