Completed
Push — master ( b28689...af1efd )
by Nicolaas
03:41
created

code/ProductGroupSearchPage.php (6 issues)

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
 * 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
10
{
11
    /**
12
     * standard SS variable.
13
     *
14
     * @static String | Array
15
     */
16
    private static $icon = 'ecommerce/images/icons/productgroupsearchpage';
0 ignored issues
show
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
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
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
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
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
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('FILTER');
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
96
{
97
    /**
98
     * standard SS variable.
99
     *
100
     * @var array
101
     */
102
    private static $allowed_actions = array(
0 ignored issues
show
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
     * get the search results.
121
     *
122
     * @param HTTPRequest
123
     */
124
    public function searchresults($request)
125
    {
126
        $this->isSearchResults = true;
127
        //set the filter and the sort...
128
        $this->addSecondaryTitle();
129
        $this->products = $this->paginateList($this->ProductsShowable(null));
130
131
        return array();
132
    }
133
134
    /**
135
     * returns child product groups for use in
136
     * 'in this section'. For example the vegetable Product Group
137
     * May have listed here: Carrot, Cabbage, etc...
138
     *
139
     * @return ArrayList (ProductGroups)
140
     */
141
    public function MenuChildGroups()
142
    {
143
        return;
144
    }
145
146
    /**
147
     * The link that Google et al. need to index.
148
     * @return string
149
     */
150
    public function CanonicalLink()
151
    {
152
        $link = $this->Link();
153
        $this->extend('UpdateCanonicalLink', $link);
154
155
        return $link;
156
    }
157
158
}
159