silverstripe-framework/forms/HasOneComplexTableField.php
Andrew O'Neil 9c29864827 Relation Tables Reorganisation (merged from branches/2.2.0@45907, r45142)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46095 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-12-02 21:27:49 +00:00

54 lines
1.6 KiB
PHP

<?php
class HasOneComplexTableField extends HasManyComplexTableField {
protected $itemClass = 'HasOneComplexTableField_Item';
function getParentIdName( $parentClass, $childClass ) {
return $this->getParentIdNameRelation( $parentClass, $childClass, 'has_one' );
}
function getControllerJoinID() {
return $this->controller->{$this->joinField};
}
function saveInto( DataObject $record ) {
$fieldName = $this->name;
$fieldNameID = $fieldName . 'ID';
$record->$fieldNameID = 0;
if( $val = $this->value[ $this->htmlListField ] ) {
if( $val != 'undefined' )
$record->$fieldNameID = $val;
}
$record->write();
}
function ExtraData() {
$val = $this->getControllerJoinID() ? $this->getControllerJoinID() : '';
$inputId = $this->id() . '_' . $this->htmlListEndName;
return <<<HTML
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$val"/>
HTML;
}
}
class HasOneComplexTableField_Item extends ComplexTableField_Item {
function MarkingCheckbox() {
$name = $this->parent->Name() . '[]';
$joinVal = $this->parent->getControllerJoinID();
$childID = $this->item->ID;
if( $this->parent->IsReadOnly )
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
else if( $joinVal == $childID )
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>";
}
}
?>