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