1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
5
|
|
|
* @package: ecommerce |
6
|
|
|
* @sub-package: tasks |
7
|
|
|
**/ |
8
|
|
|
class EcommerceTaskReviewSearches extends BuildTask |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* number of days shown. |
12
|
|
|
* |
13
|
|
|
* @int |
14
|
|
|
*/ |
15
|
|
|
protected $defaultMaxRows = 999; |
16
|
|
|
/** |
17
|
|
|
* number of days shown. |
18
|
|
|
* |
19
|
|
|
* @int |
20
|
|
|
*/ |
21
|
|
|
protected $defaultDays = 100; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* minimum number of searches for |
25
|
|
|
* a particular keyword in order to show it at all. |
26
|
|
|
* |
27
|
|
|
* @int |
28
|
|
|
*/ |
29
|
|
|
protected $defaultMinimum = 5; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* show up to XXX days ago. |
33
|
|
|
* |
34
|
|
|
* @int |
35
|
|
|
*/ |
36
|
|
|
protected $endingDaysBack = 0; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Standard (required) SS variable for BuildTasks. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $title = 'Search Statistics'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Standard (required) SS variable for BuildTasks. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $description = ' |
51
|
|
|
What did people search for on the website, you can use the days, min and ago GET variables to query different sets.'; |
52
|
|
|
|
53
|
|
|
public function run($request) |
54
|
|
|
{ |
55
|
|
|
$maxRows = intval(preg_replace('/[^\d.]/', '', $request->getVar('maxrows'))); |
56
|
|
|
$maxRows = intval($maxRows - 0); |
57
|
|
|
if (!$maxRows) { |
58
|
|
|
$maxRows = $this->defaultMaxRows; |
59
|
|
|
} |
60
|
|
|
$days = intval($request->getVar('days') - 0); |
61
|
|
|
if (!$days) { |
62
|
|
|
$days = $this->defaultDays; |
63
|
|
|
} |
64
|
|
|
$countMin = intval($request->getVar('min') - 0); |
65
|
|
|
if (!$countMin) { |
66
|
|
|
$countMin = $this->defaultMinimum; |
67
|
|
|
} |
68
|
|
|
$endingDaysBack = intval($request->getVar('ago') - 0); |
69
|
|
|
if (!$endingDaysBack) { |
70
|
|
|
$endingDaysBack = $this->endingDaysBack; |
71
|
|
|
} |
72
|
|
|
$field = EcommerceSearchHistoryFormField::create('stats', $this->title) |
73
|
|
|
->setNumberOfDays($days) |
74
|
|
|
->setMinimumCount($countMin) |
75
|
|
|
->setMaxRows($maxRows) |
76
|
|
|
->setEndingDaysBack($endingDaysBack); |
77
|
|
|
echo $field->forTemplate(); |
78
|
|
|
$arrayNumberOfDays = array(30, 365); |
|
|
|
|
79
|
|
|
|
80
|
|
|
$fields = FieldList::create( |
81
|
|
|
HeaderField::create( |
82
|
|
|
'ShowResultsFor', |
83
|
|
|
'Show results for ...' |
84
|
|
|
), |
85
|
|
|
NumericField::create( |
86
|
|
|
'days', |
87
|
|
|
'Number of days', |
88
|
|
|
isset($_GET['days']) ? $_GET['days'] : $this->defaultDays |
89
|
|
|
)->setRightTitle('For example, enter 10 to get results from a 10 day period.'), |
90
|
|
|
NumericField::create( |
91
|
|
|
'maxrows', |
92
|
|
|
'Maximum Number of Rows?', |
93
|
|
|
isset($_GET['maxrows']) ? $_GET['maxrows'] : $this->defaultMaxRows |
94
|
|
|
)->setRightTitle('For example, enter 10 to get results from a 10 day period.'), |
95
|
|
|
NumericField::create( |
96
|
|
|
'ago', |
97
|
|
|
'Up to how many days go', |
98
|
|
|
isset($_GET['ago']) ? $_GET['ago'] : $this->endingDaysBack |
99
|
|
|
)->setRightTitle('For example, entering 365 days means you get all statistics the specified number of days up to one year ago.'), |
100
|
|
|
NumericField::create( |
101
|
|
|
'min', |
102
|
|
|
'Count treshold', |
103
|
|
|
isset($_GET['min']) ? $_GET['min'] : $this->defaultMinimum |
104
|
|
|
)->setRightTitle('Minimum number of searches for it to show up in the statistics. For example, enter five to show only phrases that were searched for at least five times during the specified period.') |
105
|
|
|
); |
106
|
|
|
$actions = FieldList::create(FormAction::create("run")->setTitle("show results")); |
107
|
|
|
$form = Form::create($this, "SearchFields", $fields, $actions, null); |
108
|
|
|
$form->setAttribute('method', 'get'); |
109
|
|
|
$form->setAttribute('action', $this->Link()); |
110
|
|
|
echo $form->forTemplate(); |
111
|
|
|
echo '<style> |
112
|
|
|
div.field {margin-bottom: 20px;} |
113
|
|
|
.right {font-style:italics; color: #555;} |
114
|
|
|
</style>'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function Link($action = null) |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
return '/dev/tasks/EcommerceTaskReviewSearches/'; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.