-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathHasOneDataObjectManager.php
More file actions
74 lines (55 loc) · 2.13 KB
/
HasOneDataObjectManager.php
File metadata and controls
74 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
class HasOneDataObjectManager extends HasManyDataObjectManager
{
/**
* Most of the code below was copied from HasOneComplexTableField.
* Painful, but necessary, until PHP supports multiple inheritance.
*/
public $itemClass = 'HasOneDataObjectManager_Item';
public $isOneToOne = false;
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 = trim($val,",");
}
$record->write();
}
function setOneToOne() {
$this->isOneToOne = true;
}
function isChildSet($childID) {
return DataObject::get($this->controllerClass(), '"' . $this->joinField . "\" = '$childID'");
}
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 HasOneDataObjectManager_Item extends DataObjectManager_Item {
function MarkingCheckbox() {
$name = $this->parent->Name() . '[]';
$isOneToOne = $this->parent->isOneToOne;
$joinVal = $this->parent->getControllerJoinID();
$childID = $this->item->ID;
$disabled = $this->parent->hasMarkingPermission() ? "" : "disabled='disabled'";
if($this->parent->IsReadOnly || ($isOneToOne && $joinVal != $childID && $this->parent->isChildSet($childID)))
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\" $disabled />";
else
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" $disabled />";
}
}
?>