Completed
Push — master ( 3b65eb...dc665d )
by Nicolaas
11:00 queued 02:51
created

code/tasks/EcommerceTaskReviewSearches.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 $defaultDays = 100;
16
17
    /**
18
     * minimum number of searches for
19
     * a particular keyword in order to show it at all.
20
     *
21
     * @int
22
     */
23
    protected $defaultMinimum = 5;
24
25
    /**
26
     * show up to XXX days ago.
27
     *
28
     * @int
29
     */
30
    protected $endingDaysBack = 0;
31
32
    /**
33
     * Standard (required) SS variable for BuildTasks.
34
     *
35
     * @var string
36
     */
37
    protected $title = 'Search Statistics';
38
39
    /**
40
     * Standard (required) SS variable for BuildTasks.
41
     *
42
     * @var string
43
     */
44
    protected $description = '
45
        What did people search for on the website, you can use the days, min and ago GET variables to query different sets.';
46
47
    public function run($request)
48
    {
49
        $days = intval($request->getVar('days') - 0);
50
        if (!$days) {
51
            $days = $this->defaultDays;
52
        }
53
        $countMin = intval($request->getVar('min') - 0);
54
        if (!$countMin) {
55
            $countMin = $this->defaultMinimum;
56
        }
57
        $endingDaysBack = intval($request->getVar('ago') - 0);
58
        if (!$endingDaysBack) {
59
            $endingDaysBack = $this->endingDaysBack;
60
        }
61
        $field = EcommerceSearchHistoryFormField::create('stats', $this->title)
62
            ->setNumberOfDays($days)
63
            ->setMinimumCount($countMin)
64
            ->setEndingDaysBack($endingDaysBack);
65
        echo $field->forTemplate();
66
        $arrayNumberOfDays = array(30, 365);
67
68
        $fields = FieldList::create(
69
            HeaderField::create(
70
                'ShowResultsFor',
71
                'Show results for ...'
72
            ),
73
            NumericField::create(
74
                'days',
75
                'Number of days',
76
                isset($_GET['days']) ? $_GET['days'] : $this->defaultDays
77
            )->setRightTitle('For example, enter 10 to get results from a 10 day period.'),
78
            NumericField::create(
79
                'ago',
80
                'Up to how many days go',
81
                isset($_GET['ago']) ? $_GET['ago'] : $this->endingDaysBack
82
            )->setRightTitle('For example, entering 365 days means you get all statistics the specified number of days up to one year ago.'),
83
            NumericField::create(
84
                'min',
85
                'Count treshold',
86
                isset($_GET['min']) ? $_GET['min'] : $this->defaultMinimum
87
            )->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.')
88
        );
89
        $actions = FieldList::create(FormAction::create("run")->setTitle("show results"));
90
        $form = Form::create($this, "SearchFields", $fields, $actions, null);
91
        $form->setAttribute('method', 'get');
92
        $form->setAttribute('action', $this->Link());
93
        echo $form->forTemplate();
94
        echo '<style>
95
            div.field {margin-bottom: 20px;}
96
            .right {font-style:italics; color: #555;}
97
        </style>';
98
    }
99
100
    public function Link($action = null)
0 ignored issues
show
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102
        return '/dev/tasks/EcommerceTaskReviewSearches/';
103
    }
104
}
105