PriceListPage   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 5
dl 0
loc 113
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A getCMSFields() 0 6 1
D currentFinalProducts() 0 35 10
1
<?php
2
3
/**
4
 *@author nicolaas[at]
5
 *@description
6
 *
7
 * Provides a price list
8
 *
9
 *
10
 *
11
 *
12
 **/
13
14
class PriceListPage 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...
15
{
16
17
    /**
18
     * Standard SS variable.
19
     */
20
    private static $singular_name = "Price List 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...
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...
21
    public function i18n_singular_name()
22
    {
23
        return _t("ProductGroup.PRICELISTPAGE", "Price List Page");
24
    }
25
26
    /**
27
     * Standard SS variable.
28
     */
29
    private static $plural_name = "Price List 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...
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...
30
    public function i18n_plural_name()
31
    {
32
        return _t("ProductGroup.PRICELISTPAGES", "Price List Pages");
33
    }
34
35
    /**
36
     * standard SS variable
37
     * @static Array | String
38
     *
39
     */
40
    private static $icon = "ecommerce_complex_pricing/images/treeicons/PriceListPage";
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...
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...
41
42
    /**
43
     * standard SS variable
44
     * @static Array
45
     *
46
     */
47
    private static $db = 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...
Unused Code introduced by
The property $db 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...
48
        "NumberOfLevelsToHide" => "Int"
49
    );
50
51
    /**
52
     * standard SS variable
53
     * @static Array
54
     *
55
     */
56
    private static $defaults = 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...
Unused Code introduced by
The property $defaults 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...
57
        "LevelOfProductsToShow" => -1,
58
        "NumberOfProductsPerPage" => 100,
59
        "NumberOfLevelsToHide" => 1
60
    );
61
62
63
    /**
64
     * standard SS variable
65
     * @static Array
66
     *
67
     */
68
    private static $allowed_children = "none";
0 ignored issues
show
Unused Code introduced by
The property $allowed_children 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...
69
70
71
    /**
72
     * standard SS Method
73
     * return FieldSet
74
     *
75
     */
76
    public function getCMSFields()
77
    {
78
        $fields = parent::getCMSFields();
79
        $fields->addFieldToTab('Root.ProductDisplay', new NumericField("NumberOfLevelsToHide", _t("PriceListPage.NUMBEROFLEVELSTOHIDE", "Number of levels to hide from the top down (e.g. set to one to hide main (top) product group holder). To hide all the parent product groups you can set this variable to something like 999.")));
80
        return $fields;
81
    }
82
83
84
    /**
85
     * Retrieve a set of products, based on the given parameters.
86
     * Add Parent Group Pages to diplay within list.
87
     *
88
     * Note that you can hide the "top level"
89
     * @return DataObjectSet | Null
0 ignored issues
show
Documentation introduced by
Should the return type not be DataList|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...
90
     */
91
    public function currentFinalProducts($alternativeSort = null)
92
    {
93
        $products = parent::currentFinalProducts($alternativeSort);
94
        if ($products) {
95
            foreach ($products as $product) {
96
                $product->ParentSegments = null;
97
                if ($this->NumberOfLevelsToHide < 20) {
98
                    $segmentArray = array();
99
                    $item = $product;
100
                    while ($item && $item->ParentID) {
101
                        $item = ProductGroup::get()->byID($item->ParentID);
102
                        if ($item) {
103
                            $segmentArray[] = array(
104
                                "URLSegment" => $item->URLSegment,
105
                                "ID" => $item->ID,
106
                                "ClassName" => $item->ClassName,
107
                                "Title" => $item->Title,
108
                                "Link" => $item->Link()
109
                            );
110
                        }
111
                    }
112
                    if (count($segmentArray)) {
113
                        $product->ParentSegments = new ArrayList();
114
                        $segmentArray = array_reverse($segmentArray);
115
                        foreach ($segmentArray as $key => $segment) {
116
                            if ($key > $this->NumberOfLevelsToHide) {
117
                                $product->ParentSegments->push(new ArrayData($segment));
118
                            }
119
                        }
120
                    }
121
                }
122
            }
123
        }
124
        return $products;
125
    }
126
}
127
128
class PriceListPage_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...
129
{
130
    public function init()
131
    {
132
        parent::init();
133
        Requirements::themedCSS("PriceListPage", "ecommerce_complex_pricing");
134
    }
135
}
136