Hi UncleCheese,
The thing is I have two DataObject which already bring to CMS and has many is the relationship beftween those dataobject.
- Project
- ActivityPhoto
I would like to know the trick how to create filter which allow user to select Project Code from Project DataObject before inserting new record for ActivityPhoto. http://www.cambodia-wildlife-adventures.org/filter.jpg
Once again, thanks for your advice and contribution.
Bunheng
Update
Now i can bring up the filter but it doesn't work properly.
<?php
class Activity extends Page {
static $icon = "activities/images/activity";
static $db = array(
);
static $has_many = array(
'ActivityPhotos' => 'ActivityPhoto',
'Projects' => 'Project'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this,
'ActivityPhotos',
'ActivityPhoto',
'Photo',
array('Title' => 'Title'),
'getCMSFields_forPopup'
);
$manager->setFilter('ProjectID', 'Choose Project Code', $this->Projects()->toDropdownMap('ID', 'Code'));
$items = new DataObjectManager(
$this,
'Projects',
'Project'
);
$fields->addFieldsToTab("Root.Content.Projects", $items);
$fields->addFieldToTab("Root.Content.Activity", $manager);
$fields->removeFieldFromTab("Root.Content", 'Photo');
if ($this->Projects()->Count() > 0)
$this->ActivityPhotos()->filter = "ProjectID_" . $this->Projects()->First()->ID;
$manager->setAddTitle("Photos to " . $this->CurrentProjectCode());
$manager->filter_empty_string = false;
return $fields;
}
function getProjectID() {
return str_replace("ProjectID_", "", $this->ActivityPhotos()->filter);
}
function CurrentProjectCode() {
return DataObject::get_one("Project", $this->getProjectID())->Code;
}
}
class Activity_Controller extends Page_Controller {
}
?>