|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* extension of Product Group |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
* |
|
8
|
|
|
**/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class ModuleProductGroup extends ProductGroupWithTags |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Standard SS variable. |
|
16
|
|
|
*/ |
|
17
|
|
|
private static $singular_name = "Module"; |
|
|
|
|
|
|
18
|
|
|
public function i18n_singular_name() |
|
19
|
|
|
{ |
|
20
|
|
|
return _t("ProductGroup.MODULEPRODUCTGROUP", "Module"); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Standard SS variable. |
|
25
|
|
|
*/ |
|
26
|
|
|
private static $plural_name = "Modules"; |
|
|
|
|
|
|
27
|
|
|
public function i18n_plural_name() |
|
28
|
|
|
{ |
|
29
|
|
|
return _t("ProductGroup.MODULEPRODUCTGROUPS", "Modules"); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
private static $default_child = 'ModuleProduct'; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
private static $icon = "ecommerce_software/images/treeicons/ModuleProductGroup"; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* standard SS method |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$fields = parent::getCMSFields(); |
|
44
|
|
|
$fields->removeByName("Tags"); |
|
45
|
|
|
return $fields; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* returns the inital (all) products, based on the all the eligile products |
|
50
|
|
|
* for the page. |
|
51
|
|
|
* |
|
52
|
|
|
* This is THE pivotal method that probably changes for classes that |
|
53
|
|
|
* extend ProductGroup as here you can determine what products or other buyables are shown. |
|
54
|
|
|
* |
|
55
|
|
|
* The return from this method will then be sorted and filtered to product the final product list |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $extraFilter Additional SQL filters to apply to the Product retrieval |
|
|
|
|
|
|
58
|
|
|
* @param boolean $recursive |
|
|
|
|
|
|
59
|
|
|
* @return DataObjectSet | Null |
|
60
|
|
|
**/ |
|
61
|
|
|
public function currentInitialProducts($extraFilter = null, $alternativeFilterKey = '') |
|
62
|
|
|
{ |
|
63
|
|
|
$this->allProducts = parent::currentInitialProducts($extraFilter, $alternativeFilterKey); |
|
64
|
|
|
if ($extraFilter) { |
|
|
|
|
|
|
65
|
|
|
if ($extraFilter instanceof DataObjectSet) { |
|
|
|
|
|
|
66
|
|
|
$tags = $extraFilter; |
|
67
|
|
|
//do nothing |
|
68
|
|
|
} elseif ($extraFilter instanceof DataObject) { |
|
69
|
|
|
$tags = new ArrayList(array($extraFilter)); |
|
70
|
|
|
} elseif (is_array($extraFilter) || intval($extraFilter) == $extraFilter) { |
|
71
|
|
|
$tags = EcommerceProductTag::get() |
|
72
|
|
|
->filter(array("ID" => $extraFilter)); |
|
73
|
|
|
} else { |
|
74
|
|
|
user_error("Error in tags", E_USER_NOTICE); |
|
75
|
|
|
} |
|
76
|
|
|
$idArray = array(); |
|
77
|
|
|
if ($tags->count()) { |
|
78
|
|
|
$stage = ''; |
|
79
|
|
|
if (Versioned::current_stage() == "Live") { |
|
80
|
|
|
$stage = "_Live"; |
|
81
|
|
|
} |
|
82
|
|
|
if ($tags->count()) { |
|
83
|
|
|
foreach ($tags as $tag) { |
|
84
|
|
|
$rows = DB::query(" |
|
85
|
|
|
SELECT \"ProductID\" |
|
86
|
|
|
FROM \"EcommerceProductTag_Products\" |
|
87
|
|
|
INNER JOIN \"ModuleProduct{$stage}\" |
|
88
|
|
|
ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\" |
|
89
|
|
|
WHERE \"EcommerceProductTag_Products\".\"EcommerceProductTagID\" IN (".implode(",", $tags->column("ID")).") |
|
|
|
|
|
|
90
|
|
|
"); |
|
91
|
|
|
if ($rows) { |
|
92
|
|
|
foreach ($rows as $row) { |
|
93
|
|
|
$idArray[$row["ProductID"]] = $row["ProductID"]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
if (count($idArray)) { |
|
98
|
|
|
$this->allProducts = $this->allProducts->filter(array("ID" => $idArray)); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
return $this->allProducts; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Returns the class we are working with for the initial product selection |
|
108
|
|
|
* @return String |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function getClassNameSQL() |
|
111
|
|
|
{ |
|
112
|
|
|
return "ModuleProduct"; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* returns the CLASSNAME part of the final selection of products. |
|
119
|
|
|
* @return String |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function currentClassNameSQL() |
|
122
|
|
|
{ |
|
123
|
|
|
return "ModuleProduct"; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param String $tagCode - code of the current tag. |
|
129
|
|
|
* @return Object - DataObjectSet - Tags that are related to ModuleProducts |
|
130
|
|
|
*/ |
|
131
|
|
|
public function DefaultEcommerceProductTags($tagCode = "") |
|
132
|
|
|
{ |
|
133
|
|
|
$stage = ''; |
|
134
|
|
|
if (Versioned::current_stage() == "Live") { |
|
135
|
|
|
$stage = "_Live"; |
|
136
|
|
|
} |
|
137
|
|
|
$idArray = array(); |
|
138
|
|
|
$productIDs[0] = 0; |
|
|
|
|
|
|
139
|
|
|
$rows = DB::query(" |
|
140
|
|
|
SELECT \"EcommerceProductTagID\" |
|
141
|
|
|
FROM \"EcommerceProductTag_Products\" |
|
142
|
|
|
INNER JOIN \"ModuleProduct{$stage}\" |
|
143
|
|
|
ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\" |
|
144
|
|
|
INNER JOIN \"SiteTree{$stage}\" |
|
145
|
|
|
ON \"ModuleProduct{$stage}\".\"ID\" = \"SiteTree{$stage}\".\"ID\" |
|
146
|
|
|
WHERE \"SiteTree{$stage}\".ShowInSearch = 1 |
|
147
|
|
|
"); |
|
148
|
|
|
if ($rows) { |
|
149
|
|
|
foreach ($rows as $row) { |
|
150
|
|
|
$idArray[$row["EcommerceProductTagID"]] = $row["EcommerceProductTagID"]; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
if (count($idArray)) { |
|
154
|
|
|
$tags = EcommerceProductTag::get() |
|
155
|
|
|
->filter(array("ID" => $idArray)); |
|
156
|
|
|
if ($tags->count()) { |
|
157
|
|
|
foreach ($tags as $tag) { |
|
158
|
|
|
$tag->Link = $this->Link("show")."/".$tag->Code."/"; |
|
159
|
|
|
if ($tag->Code == $tagCode) { |
|
160
|
|
|
$tag->LinkingMode = "current"; |
|
161
|
|
|
} else { |
|
162
|
|
|
$tag->LinkingMode = "link"; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
return $tags; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
class ModuleProductGroup_Controller extends ProductGroupWithTags_Controller |
|
|
|
|
|
|
173
|
|
|
{ |
|
174
|
|
|
public function init() |
|
175
|
|
|
{ |
|
176
|
|
|
parent::init(); |
|
177
|
|
|
Requirements::javascript("ecommerce_software/javascript/ModuleProductGroup.js"); |
|
178
|
|
|
Requirements::themedCSS("ModuleProduct", "ecommerce_software"); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Return the products for this group. |
|
184
|
|
|
* |
|
185
|
|
|
* @return DataObjectSet(Products) |
|
|
|
|
|
|
186
|
|
|
**/ |
|
187
|
|
|
public function Products() |
|
|
|
|
|
|
188
|
|
|
{ |
|
189
|
|
|
if ($this->tag) { |
|
190
|
|
|
$toShow = $this->tag; |
|
191
|
|
|
Requirements::customScript("ModuleProductGroup.set_urlFiltered(true)", "set_urlFiltered"); |
|
192
|
|
|
} else { |
|
193
|
|
|
$toShow = null; |
|
194
|
|
|
} |
|
195
|
|
|
return $this->ProductsShowable($toShow); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Tags available in the template |
|
201
|
|
|
*/ |
|
202
|
|
|
public function Tags() |
|
|
|
|
|
|
203
|
|
|
{ |
|
204
|
|
|
$tagCode = ""; |
|
205
|
|
|
if ($this->tag) { |
|
206
|
|
|
$tagCode = $this->tag->Code; |
|
207
|
|
|
} |
|
208
|
|
|
return $this->DefaultEcommerceProductTags($tagCode); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Site search form |
|
215
|
|
|
*/ |
|
216
|
|
|
public function ModuleSearchForm() |
|
217
|
|
|
{ |
|
218
|
|
|
$searchText = _t('ModuleProductGroup.KEYWORDS', 'keywords'); |
|
219
|
|
|
|
|
220
|
|
|
if ($this->request) { |
|
221
|
|
|
$searchText = $this->request->getVar('Search'); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
$fields = new FieldList( |
|
225
|
|
|
new TextField('Search', _t('ModuleProductGroup.KEYWORDS', 'keywords'), $searchText) |
|
226
|
|
|
); |
|
227
|
|
|
$actions = new FieldList( |
|
228
|
|
|
new FormAction('modulesearchformresults', _t('ModuleSearchForm.FILTER', 'Filter')) |
|
229
|
|
|
); |
|
230
|
|
|
$form = new SearchForm($this, 'ModuleSearchForm', $fields, $actions); |
|
231
|
|
|
$form->classesToSearch(array("SiteTree")); |
|
232
|
|
|
return $form; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Process and render search results. |
|
237
|
|
|
* |
|
238
|
|
|
* @param array $data The raw request data submitted by user |
|
239
|
|
|
* @param SearchForm $form The form instance that was submitted |
|
240
|
|
|
* @param SS_HTTPRequest $request Request generated for this action |
|
241
|
|
|
*/ |
|
242
|
|
|
public function modulesearchformresults($data, $form, $request) |
|
|
|
|
|
|
243
|
|
|
{ |
|
244
|
|
|
$data = array( |
|
245
|
|
|
'Results' => $form->getResults(), |
|
246
|
|
|
'Query' => $form->getSearchQuery(), |
|
247
|
|
|
'Title' => _t('SearchForm.SearchResults', 'Search Results') |
|
248
|
|
|
); |
|
249
|
|
|
//search tags |
|
250
|
|
|
//search authors |
|
251
|
|
|
if ($data["Results"]) { |
|
252
|
|
|
foreach ($data["Results"] as $key => $resultItem) { |
|
253
|
|
|
if (!($resultItem instanceof ModuleProduct)) { |
|
254
|
|
|
($data["Results"]->remove($resultItem)); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
} else { |
|
258
|
|
|
$data["Results"] = new ArrayList(); |
|
259
|
|
|
} |
|
260
|
|
|
$search = Convert::raw2sql($data["Query"]); |
|
261
|
|
|
if (strlen($search) > 2) { |
|
262
|
|
|
$additionalProducts = ModuleProduct::get()->filterAny(array("Code:PartialMatch" => $search, "MenuTitle:PartialMatch" => $search)); |
|
263
|
|
|
if ($additionalProducts) { |
|
264
|
|
|
foreach ($additionalProducts as $moduleProduct) { |
|
265
|
|
|
$data["Results"]->push($moduleProduct); |
|
|
|
|
|
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
$tags = EcommerceProductTag::get()->filterAny(array("Title:PartialMatch" => $search, "Synonyms:PartialMatch" => $search, "Explanation:PartialMatch" => $search)); |
|
269
|
|
View Code Duplication |
if ($tags->count()) { |
|
|
|
|
|
|
270
|
|
|
foreach ($tags as $tag) { |
|
271
|
|
|
$rows = DB::query("SELECT ProductID FROM EcommerceProductTag_Products WHERE EcommerceProductTagID = ".$tag->ID); |
|
272
|
|
|
if ($rows) { |
|
273
|
|
|
foreach ($rows as $row) { |
|
274
|
|
|
$item = ModuleProduct::get()->byID($row["ProductID"]); |
|
275
|
|
|
if ($item) { |
|
276
|
|
|
$data["Results"]->push($item); |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
$authors = Member::get() |
|
283
|
|
|
->filterAny( |
|
284
|
|
|
array( |
|
285
|
|
|
"ScreenName:PartialMatch" => $search, |
|
286
|
|
|
"FirstName:PartialMatch" => $search, |
|
287
|
|
|
"Surname:PartialMatch" => $search) |
|
288
|
|
|
); |
|
289
|
|
View Code Duplication |
if ($authors->count()) { |
|
|
|
|
|
|
290
|
|
|
foreach ($authors as $author) { |
|
291
|
|
|
$rows = DB::query("SELECT \"ModuleProductID\" FROM \"ModuleProduct_Authors\" WHERE \"MemberID\" = ".$author->ID); |
|
292
|
|
|
if ($rows) { |
|
293
|
|
|
foreach ($rows as $row) { |
|
294
|
|
|
$item = ModuleProduct::get()->byID($row["ModuleProductID"]); |
|
295
|
|
|
if ($item) { |
|
296
|
|
|
$data["Results"]->push($item); |
|
|
|
|
|
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
if ($data["Results"] && $data["Results"] instanceof DataObjectSet) { |
|
|
|
|
|
|
304
|
|
|
$data["Results"]->removeDuplicates(); |
|
305
|
|
|
} |
|
306
|
|
|
if (Director::is_ajax()) { |
|
307
|
|
|
return Convert::array2json(array("ModuleProducts" => $data["Results"]->column("ID"))); |
|
308
|
|
|
} |
|
309
|
|
|
return $this->customise(array("Products" => $data["Results"])); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* Admin ONLY action |
|
314
|
|
|
* to view a list of all developers |
|
315
|
|
|
* that have not been contacted yet |
|
316
|
|
|
*/ |
|
317
|
|
|
public function introemails() |
|
|
|
|
|
|
318
|
|
|
{ |
|
319
|
|
|
$i = 0; |
|
320
|
|
|
$member = Member::currentUser(); |
|
321
|
|
|
$dos = new ArrayList(); |
|
322
|
|
|
if ($member && $member->inGroup("ADMIN")) { |
|
323
|
|
|
$modules = ModuleProduct::get() |
|
324
|
|
|
->filter(array("ShowInSearch" => 1, "ShowInMenus" => 1)); |
|
325
|
|
|
foreach ($modules as $module) { |
|
326
|
|
|
if (!$module->HasEmail() && !$module->HasMemberContact()) { |
|
327
|
|
|
$i++; |
|
328
|
|
|
if ($i < 10) { |
|
329
|
|
|
$dos->push($module); |
|
330
|
|
|
} else { |
|
331
|
|
|
break; |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
return $this->customise(array("Products" => $dos)); |
|
336
|
|
|
} |
|
337
|
|
|
Security::permissionFailure($this, "You need to log in as an Administrator."); |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
|
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.