1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This dataobject |
4
|
|
|
* saves search replacements |
5
|
|
|
* as in Smoogle will be replaced by Google. |
6
|
|
|
*/ |
7
|
|
|
class SearchReplacement extends DataObject implements EditableEcommerceObject |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
private static $db = array( |
|
|
|
|
10
|
|
|
'Search' => 'Varchar(255)', |
11
|
|
|
'Replace' => 'Varchar(255)', |
12
|
|
|
'ReplaceWholePhrase' => 'Boolean' |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
private static $indexes = array( |
|
|
|
|
16
|
|
|
'SearchIndex' => 'unique("Search")', |
17
|
|
|
'Replace' => true |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
private static $summary_fields = array( |
|
|
|
|
21
|
|
|
'Search' => 'Aliases (e.g. Biike)', |
22
|
|
|
'Replace' => 'Proper name (e.g. Bike)', |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
private static $field_labels = array( |
|
|
|
|
26
|
|
|
'Search' => 'Aliases (e.g. Biike)', |
27
|
|
|
'Replace' => 'Proper Name (e.g. Bike)', |
28
|
|
|
'ReplaceWholePhrase' => 'Replace Whole Phrase' |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* standard SS variable. |
35
|
|
|
* |
36
|
|
|
* @Var String |
37
|
|
|
*/ |
38
|
|
|
private static $singular_name = 'Search Replacement'; |
|
|
|
|
39
|
|
|
public function i18n_singular_name() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return $this->Config()->get('singular_name'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* standard SS variable. |
46
|
|
|
* |
47
|
|
|
* @Var String |
48
|
|
|
*/ |
49
|
|
|
private static $plural_name = 'Search Replacements'; |
|
|
|
|
50
|
|
|
public function i18n_plural_name() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
return $this->Config()->get('plural_name'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private static $separator = ','; |
|
|
|
|
56
|
|
|
|
57
|
|
|
public function fieldLabels($includerelations = true) |
58
|
|
|
{ |
59
|
|
|
return array( |
60
|
|
|
'Search' => 'When someone searches for ... (separate searches by '.$this->Config()->get('separator').') - aliases', |
61
|
|
|
'Replace' => 'It is replaced by - proper name ...', |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function onBeforeWrite() |
66
|
|
|
{ |
67
|
|
|
parent::onBeforeWrite(); |
68
|
|
|
//all lower case and make replace double spaces |
69
|
|
|
$this->Search = trim(preg_replace('!\s+!', ' ', strtolower($this->Search))); |
|
|
|
|
70
|
|
|
$searchArray = array(); |
71
|
|
|
foreach (explode(',', $this->Search) as $term) { |
|
|
|
|
72
|
|
|
$searchArray[] = trim($term); |
73
|
|
|
} |
74
|
|
|
$this->Search = implode(',', $searchArray); |
|
|
|
|
75
|
|
|
$this->Replace = strtolower($this->Replace); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* standard SS method. |
80
|
|
|
* |
81
|
|
|
* @param Member $member |
|
|
|
|
82
|
|
|
* |
83
|
|
|
* @return bool |
|
|
|
|
84
|
|
|
*/ |
85
|
|
|
public function canCreate($member = null) |
86
|
|
|
{ |
87
|
|
|
if (! $member) { |
88
|
|
|
$member = Member::currentUser(); |
89
|
|
|
} |
90
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
91
|
|
|
if ($extended !== null) { |
92
|
|
|
return $extended; |
93
|
|
|
} |
94
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return parent::canEdit($member); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* standard SS method. |
103
|
|
|
* |
104
|
|
|
* @param Member $member |
|
|
|
|
105
|
|
|
* |
106
|
|
|
* @return bool |
|
|
|
|
107
|
|
|
*/ |
108
|
|
|
public function canView($member = null) |
109
|
|
|
{ |
110
|
|
|
if (! $member) { |
111
|
|
|
$member = Member::currentUser(); |
112
|
|
|
} |
113
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
114
|
|
|
if ($extended !== null) { |
115
|
|
|
return $extended; |
116
|
|
|
} |
117
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
118
|
|
|
return true; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return parent::canEdit($member); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* standard SS method. |
126
|
|
|
* |
127
|
|
|
* @param Member $member |
|
|
|
|
128
|
|
|
* |
129
|
|
|
* @return bool |
|
|
|
|
130
|
|
|
*/ |
131
|
|
|
public function canEdit($member = null) |
132
|
|
|
{ |
133
|
|
|
if (! $member) { |
134
|
|
|
$member = Member::currentUser(); |
135
|
|
|
} |
136
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
137
|
|
|
if ($extended !== null) { |
138
|
|
|
return $extended; |
139
|
|
|
} |
140
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
141
|
|
|
return true; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return parent::canEdit($member); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* standard SS method. |
149
|
|
|
* |
150
|
|
|
* @param Member $member |
|
|
|
|
151
|
|
|
* |
152
|
|
|
* @return bool |
|
|
|
|
153
|
|
|
*/ |
154
|
|
|
public function canDelete($member = null) |
155
|
|
|
{ |
156
|
|
|
if (! $member) { |
157
|
|
|
$member = Member::currentUser(); |
158
|
|
|
} |
159
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
160
|
|
|
if ($extended !== null) { |
161
|
|
|
return $extended; |
162
|
|
|
} |
163
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
164
|
|
|
return true; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return parent::canEdit($member); |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* link to edit the record. |
172
|
|
|
* |
173
|
|
|
* @param string | Null $action - e.g. edit |
174
|
|
|
* |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function CMSEditLink($action = null) |
178
|
|
|
{ |
179
|
|
|
return CMSEditLinkAPI::find_edit_link_for_object($this, $action); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
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.