SearchTermsReport   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 34
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A columns() 0 12 1
A query() 0 13 1
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