2007-09-04 05:30:59 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage forms
|
|
|
|
*/
|
|
|
|
|
2007-12-02 22:27:49 +01:00
|
|
|
class HasOneComplexTableField extends HasManyComplexTableField {
|
2007-09-04 05:30:59 +02:00
|
|
|
|
2008-01-08 22:57:59 +01:00
|
|
|
public $itemClass = 'HasOneComplexTableField_Item';
|
2007-12-02 22:32:41 +01:00
|
|
|
|
|
|
|
public $isOneToOne = false;
|
|
|
|
|
2008-01-08 22:57:59 +01:00
|
|
|
function getParentIdName($parentClass, $childClass) {
|
|
|
|
return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one');
|
2007-09-04 05:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getControllerJoinID() {
|
|
|
|
return $this->controller->{$this->joinField};
|
|
|
|
}
|
|
|
|
|
2008-01-08 22:57:59 +01:00
|
|
|
function saveInto(DataObject $record) {
|
2007-09-04 05:30:59 +02:00
|
|
|
$fieldName = $this->name;
|
|
|
|
$fieldNameID = $fieldName . 'ID';
|
2007-10-18 00:48:17 +02:00
|
|
|
|
|
|
|
$record->$fieldNameID = 0;
|
2008-01-08 22:57:59 +01:00
|
|
|
if($val = $this->value[ $this->htmlListField ]) {
|
|
|
|
if($val != 'undefined')
|
2007-10-18 00:48:17 +02:00
|
|
|
$record->$fieldNameID = $val;
|
|
|
|
}
|
|
|
|
|
2007-09-04 05:30:59 +02:00
|
|
|
$record->write();
|
|
|
|
}
|
2007-12-02 22:32:41 +01:00
|
|
|
|
|
|
|
function setOneToOne() {
|
|
|
|
$this->isOneToOne = true;
|
|
|
|
}
|
|
|
|
|
2008-01-08 22:57:59 +01:00
|
|
|
function isChildSet($childID) {
|
|
|
|
return DataObject::get($this->controller->ClassName, '`' . $this->joinField . "` = '$childID'");
|
2007-12-02 22:32:41 +01:00
|
|
|
}
|
|
|
|
|
2007-09-04 05:30:59 +02:00
|
|
|
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() . '[]';
|
|
|
|
|
2007-12-02 22:32:41 +01:00
|
|
|
$isOneToOne = $this->parent->isOneToOne;
|
2007-09-04 05:30:59 +02:00
|
|
|
$joinVal = $this->parent->getControllerJoinID();
|
|
|
|
$childID = $this->item->ID;
|
2007-12-02 22:32:41 +01:00
|
|
|
|
2008-01-08 22:57:59 +01:00
|
|
|
if($this->parent->IsReadOnly || ($isOneToOne && $joinVal != $childID && $this->parent->isChildSet($childID)))
|
2007-09-04 05:30:59 +02:00
|
|
|
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
2008-01-08 22:57:59 +01:00
|
|
|
else if($joinVal == $childID)
|
2007-09-04 05:30:59 +02:00
|
|
|
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}\"/>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|