|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class SearchHistory extends DataObject |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $db = array( |
|
|
|
|
|
|
6
|
|
|
'Title' => 'Varchar(255)', |
|
7
|
|
|
'ProductCount' => 'Int', |
|
8
|
|
|
'GroupCount' => 'Int', |
|
9
|
|
|
); |
|
10
|
|
|
|
|
11
|
|
|
private static $default_sort = '"Created" DESC'; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
14
|
|
|
'Title' => 'PartialMatchFilter', |
|
15
|
|
|
'ProductCount' => 'GreaterThanOrEqualFilter', |
|
16
|
|
|
'GroupCount' => 'GreaterThanOrEqualFilter', |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
20
|
|
|
'Created' => 'When', |
|
21
|
|
|
'Title' => 'Keyword', |
|
22
|
|
|
'ProductCount' => 'Products Found', |
|
23
|
|
|
'GroupCount' => 'Categories Found', |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* standard SS variable. |
|
29
|
|
|
* |
|
30
|
|
|
* @Var String |
|
31
|
|
|
*/ |
|
32
|
|
|
private static $singular_name = 'Search History Entry'; |
|
|
|
|
|
|
33
|
|
|
public function i18n_singular_name() |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
return $this->Config()->get('singular_name'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* standard SS variable. |
|
40
|
|
|
* |
|
41
|
|
|
* @Var String |
|
42
|
|
|
*/ |
|
43
|
|
|
private static $plural_name = 'Search History Entries'; |
|
|
|
|
|
|
44
|
|
|
public function i18n_plural_name() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
return $this->Config()->get('plural_name'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* creates a new entry if you are not a shop admin. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $keywordString |
|
53
|
|
|
* |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function add_entry($keywordString, $productCount = 0, $groupCount = 0) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($member = Member::currentUser()) { |
|
59
|
|
|
if ($member->IsShopAdmin()) { |
|
60
|
|
|
return -1; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
$obj = new self(); |
|
64
|
|
|
$obj->Title = $keywordString; |
|
|
|
|
|
|
65
|
|
|
$obj->ProductCount = $productCount; |
|
|
|
|
|
|
66
|
|
|
$obj->GroupCount = $groupCount; |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $obj->write(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* remove excessive spaces. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function onBeforeWrite() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->Title = trim(preg_replace('!\s+!', ' ', $this->Title)); |
|
|
|
|
|
|
77
|
|
|
parent::onBeforeWrite(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* standard SS method. |
|
82
|
|
|
* |
|
83
|
|
|
* @param Member $member |
|
|
|
|
|
|
84
|
|
|
* |
|
85
|
|
|
* @return bool |
|
86
|
|
|
*/ |
|
87
|
|
|
public function canCreate($member = null) |
|
88
|
|
|
{ |
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* standard SS method. |
|
94
|
|
|
* |
|
95
|
|
|
* @param Member $member |
|
|
|
|
|
|
96
|
|
|
* |
|
97
|
|
|
* @return bool |
|
|
|
|
|
|
98
|
|
|
*/ |
|
99
|
|
|
public function canView($member = null) |
|
100
|
|
|
{ |
|
101
|
|
|
if (! $member) { |
|
102
|
|
|
$member = Member::currentUser(); |
|
103
|
|
|
} |
|
104
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
|
|
|
|
|
105
|
|
|
if ($extended !== null) { |
|
106
|
|
|
return $extended; |
|
107
|
|
|
} |
|
108
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
|
109
|
|
|
return true; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return parent::canEdit($member); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* standard SS method. |
|
117
|
|
|
* |
|
118
|
|
|
* @param Member $member |
|
|
|
|
|
|
119
|
|
|
* |
|
120
|
|
|
* @return bool |
|
121
|
|
|
*/ |
|
122
|
|
|
public function canEdit($member = null) |
|
123
|
|
|
{ |
|
124
|
|
|
return false; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* standard SS method. |
|
129
|
|
|
* |
|
130
|
|
|
* @param Member $member |
|
|
|
|
|
|
131
|
|
|
* |
|
132
|
|
|
* @return bool |
|
133
|
|
|
*/ |
|
134
|
|
|
public function canDelete($member = null) |
|
135
|
|
|
{ |
|
136
|
|
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
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.