1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Base Class for EditableOption Fields such as the ones used in |
5
|
|
|
* dropdown fields and in radio check box groups |
6
|
|
|
* |
7
|
|
|
* @method EditableMultipleOptionField Parent() |
8
|
|
|
* @package userforms |
9
|
|
|
*/ |
10
|
|
|
class EditableOption extends DataObject { |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $default_sort = "Sort"; |
|
|
|
|
13
|
|
|
|
14
|
|
|
private static $db = array( |
|
|
|
|
15
|
|
|
"Name" => "Varchar(255)", |
16
|
|
|
"Title" => "Varchar(255)", |
17
|
|
|
"Default" => "Boolean", |
18
|
|
|
"Sort" => "Int" |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
private static $has_one = array( |
|
|
|
|
22
|
|
|
"Parent" => "EditableMultipleOptionField", |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
private static $extensions = array( |
|
|
|
|
26
|
|
|
"Versioned('Stage', 'Live')" |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
private static $summary_fields = array( |
|
|
|
|
30
|
|
|
'Title', |
31
|
|
|
'Default' |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Member $member |
36
|
|
|
* |
37
|
|
|
* @return boolean |
38
|
|
|
*/ |
39
|
|
|
public function canEdit($member = null) { |
40
|
|
|
return $this->Parent()->canEdit($member); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Member $member |
45
|
|
|
* |
46
|
|
|
* @return boolean |
47
|
|
|
*/ |
48
|
|
|
public function canDelete($member = null) { |
49
|
|
|
return $this->canEdit($member); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getEscapedTitle() { |
53
|
|
|
return Convert::raw2att($this->Title); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Member $member |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function canView($member = null) { |
61
|
|
|
return $this->Parent()->canView($member); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return whether a user can create an object of this type |
66
|
|
|
* |
67
|
|
|
* @param Member $member |
68
|
|
|
* @param array $context Virtual parameter to allow context to be passed in to check |
|
|
|
|
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function canCreate($member = null) { |
|
|
|
|
72
|
|
|
// Check parent page |
73
|
|
|
$parent = $this->getCanCreateContext(func_get_args()); |
74
|
|
|
if($parent) { |
75
|
|
|
return $parent->canEdit($member); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Fall back to secure admin permissions |
79
|
|
|
return parent::canCreate($member); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Helper method to check the parent for this object |
84
|
|
|
* |
85
|
|
|
* @param array $args List of arguments passed to canCreate |
86
|
|
|
* @return DataObject Some parent dataobject to inherit permissions from |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
protected function getCanCreateContext($args) { |
|
|
|
|
89
|
|
|
// Inspect second parameter to canCreate for a 'Parent' context |
90
|
|
|
if(isset($args[1]['Parent'])) { |
91
|
|
|
return $args[1]['Parent']; |
92
|
|
|
} |
93
|
|
|
// Hack in currently edited page if context is missing |
94
|
|
|
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) { |
95
|
|
|
return Controller::curr()->currentPage(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// No page being edited |
99
|
|
|
return null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param Member $member |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
|
|
public function canPublish($member = null) { |
107
|
|
|
return $this->canEdit($member); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Member $member |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
public function canUnpublish($member = null) { |
115
|
|
|
return $this->canDelete($member); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.