Completed
Push — master ( bccb03...5772ae )
by Nicolaas
03:08
created

ProductGroupSearchPage_Controller::searchresults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
eloc 5
nc 1
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A ProductGroupSearchPage_Controller::MenuChildGroups() 0 4 1
1
<?php
2
/**
3
 * This page manages searching for products.
4
 *
5
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
6
 * @package: ecommerce
7
 * @sub-package: Pages
8
 **/
9
class ProductGroupSearchPage extends ProductGroup
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...
10
{
11
    /**
12
     * standard SS variable.
13
     *
14
     * @static String | Array
15
     */
16
    private static $icon = 'ecommerce/images/icons/productgroupsearchpage';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
17
18
    /**
19
     * Standard SS variable.
20
     *
21
     * @var string
22
     */
23
    private static $description = 'This page allowing the user to search for products.';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
24
25
    /**
26
     * Standard SS variable.
27
     */
28
    private static $singular_name = 'Product Search Page';
0 ignored issues
show
Unused Code introduced by
The property $singular_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
29
    public function i18n_singular_name()
30
    {
31
        return _t('ProductGroupSearchPage.SINGULARNAME', 'Product Search Page');
32
    }
33
34
    /**
35
     * Standard SS variable.
36
     */
37
    private static $plural_name = 'Product Search Pages';
0 ignored issues
show
Unused Code introduced by
The property $plural_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
38
    public function i18n_plural_name()
39
    {
40
        return _t('ProductGroupSearchPage.PLURALNAME', 'Product Search Pages');
41
    }
42
43
    /**
44
     * Standard SS function, we only allow for one Product Search Page to exist
45
     * but we do allow for extensions to exist at the same time.
46
     *
47
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
48
     *
49
     * @return bool
50
     */
51
    public function canCreate($member = null)
52
    {
53
        return ProductGroupSearchPage::get()->filter(array('ClassName' => 'ProductGroupSearchPage'))->Count() ? false : $this->canEdit($member);
54
    }
55
56
    /**
57
     * Can product list (and related) be cached at all?
58
     *
59
     * @var bool
60
     */
61
    protected $allowCaching = false;
62
63
    public function getGroupFilter()
64
    {
65
        $resultArray = $this->searchResultsArrayFromSession();
66
        $this->allProducts = $this->allProducts->filter(array('ID' => $resultArray));
67
68
        return $this->allProducts;
69
    }
70
71
    /**
72
     * returns the SORT part of the final selection of products.
73
     *
74
     * @return string | Array
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
     */
76
    protected function currentSortSQL()
77
    {
78
        $sortKey = $this->getCurrentUserPreferences('SORT');
79
        $defaultSortKey = $this->getMyUserPreferencesDefault('SORT');
80
        if ($sortKey == $defaultSortKey) {
81
            $resultArray = $this->searchResultsArrayFromSession();
82
            
83
            return $this->createSortStatementFromIDArray($resultArray);
84
        }
85
86
        return $this->getUserSettingsOptionSQL('SORT', $sortKey);
87
    }
88
89
    public function childGroups($maxRecursiveLevel, $filter = null, $numberOfRecursions = 0)
90
    {
91
        return ArrayList::create();
92
    }
93
}
94
95
class ProductGroupSearchPage_Controller extends ProductGroup_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
96
{
97
    /**
98
     * standard SS variable.
99
     *
100
     * @var array
101
     */
102
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
103
        'debug' => 'ADMIN',
104
        'filterforgroup' => true,
105
        'ProductSearchForm' => true,
106
        'searchresults' => true,
107
        'resetfilter' => true,
108
    );
109
110
    public function init()
111
    {
112
        parent::init();
113
        $array = $this->searchResultsArrayFromSession();
114
        if (count($array) > 1) {
115
            $this->isSearchResults = true;
116
        }
117
    }
118
119
120
    /**
121
     * returns child product groups for use in
122
     * 'in this section'. For example the vegetable Product Group
123
     * May have listed here: Carrot, Cabbage, etc...
124
     *
125
     * @return ArrayList (ProductGroups)
0 ignored issues
show
Documentation introduced by
Should the return type not be ArrayList|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
126
     */
127
    public function MenuChildGroups()
128
    {
129
        return;
130
    }
131
132
    /**
133
     * The link that Google et al. need to index.
134
     * @return string
135
     */
136
    public function CanonicalLink()
137
    {
138
        $link = $this->Link();
139
        $this->extend('UpdateCanonicalLink', $link);
140
141
        return $link;
142
    }
143
144
}
145