SearchTermsReport::columns()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Silverstripe report for searchs
4
 *
5
 * @author Mark Guinn <[email protected]>
6
 * @date 09.24.2014
7
 * @package apluswhs.com
8
 * @subpackage
9
 */
10
class SearchTermsReport extends ShopPeriodReport
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    protected $title = "Search Terms";
13
    protected $description = "Understand what users are searching for.";
14
    protected $dataClass = "SearchLog";
15
    protected $periodfield = "SearchLog.Created";
16
17
    public function columns()
18
    {
19
        return array(
20
            "Query" => array(
21
                "title" => "Query",
22
                "formatting" => '<a href=\"home/SearchForm?q=$ATT_val($Query)\" target=\"_new\">$Query</a>'
23
            ),
24
            'NumResults' => 'Results',
25
            'Quantity' => 'Searches',
26
            'MostRecent' => 'Most Recent',
27
        );
28
    }
29
30
    public function query($params)
31
    {
32
        $query = parent::query($params);
33
        $query->selectField($this->periodfield, "FilterPeriod")
34
            ->addSelect("SearchLog.Query")
35
            ->selectField("Count(SearchLog.ID)", "Quantity")
36
            ->selectField("Max(SearchLog.Created)", "MostRecent")
37
            ->selectField("Max(SearchLog.NumResults)", "NumResults");
38
        $query->addGroupby("SearchLog.Query");
39
        $query->addWhere("\"SearchLog\".\"Filters\" is null AND \"SearchLog\".\"ParentSearchID\" = '0'");
40
        $query->setOrderBy("Quantity", "DESC");
41
        return $query;
42
    }
43
}
44