FaqHolderPage   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 1
dl 0
loc 104
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A ChildGroups() 0 16 4
A setHolderPage() 0 4 1
A getHolderPage() 0 4 1
A setEntryName() 0 4 1
A getEntryName() 0 4 1
1
<?php
2
3
/**
4
 *@author nicolaas[at]sunnysideup.co.nz
5
 *@description: holds FAQs and displays them nicely.
6
 *
7
 */
8
class FaqHolderPage extends Page
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...
9
{
10
    private static $icon = "mysite/images/treeicons/FaqHolderPage";
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...
11
12
    private static $description =  "A list of Frequently Asked Questions" ;
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...
13
14
    //private static $default_parent = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
15
16
    private static $default_child = 'FaqOnePage';
0 ignored issues
show
Unused Code introduced by
The property $default_child 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...
17
18
    private static $allowed_children = array('FaqHolderPage', 'FaqOnePage');
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...
19
20
    /**
21
     * Standard SS variable.
22
     */
23
    private static $singular_name = "FAQ Holder 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...
24
    public function i18n_singular_name()
25
    {
26
        return _t("FAQHolderPage.SINGULARNAME", "FAQ Holder Page");
27
    }
28
29
    /**
30
     * Standard SS variable.
31
     */
32
    private static $plural_name = "FAQ Holder 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...
33
    public function i18n_plural_name()
34
    {
35
        return _t("FAQHolderPage.PLURALNAME", "FAQ Holder Pages");
36
    }
37
38
    /**
39
     * The holder page class in use.
40
     * You can extends this Class and change this value.
41
     * @var String
42
     */
43
    protected $holderPage = "FAQHolderPage";
44
45
    /**
46
     * The item page class in use.
47
     * You can extends this Class and change this value.
48
     * @var String
49
     */
50
    protected $entryPage = "FAQOnePage";
51
52
    /**
53
     * Returns children FAQHolderPage pages of this FAQHolderPage.
54
     *
55
     * @param Int $maxRecursiveLevel - maximum depth , e.g. 1 = one level down - so no Child Groups are returned...
56
     * @param Int $numberOfRecursions - current level of depth. DONT provide this variable...
57
     * @return ArrayList (FAQHolderPages)
58
     */
59
    public function ChildGroups($maxRecursiveLevel = 99, $numberOfRecursions = 0)
60
    {
61
        $arrayList = ArrayList::create();
62
        if ($numberOfRecursions < $maxRecursiveLevel) {
63
            $className = $this->getHolderPage();
64
            $children = $className::get()->filter(array("ParentID" => $this->ID));
65
            if ($children->count()) {
66
                foreach ($children as $child) {
67
                    $arrayList->push($child);
68
                    $arrayList->merge($child->ChildGroups($maxRecursiveLevel, $numberOfRecursions++));
69
                }
70
            }
71
        }
72
73
        return $arrayList;
74
    }
75
76
    /**
77
     * sets the classname for pages that are holder pages
78
     * @param String $name
79
     */
80
    public function setHolderPage($name)
81
    {
82
        $this->holderPage = $name;
83
    }
84
85
    /**
86
     * gets the classname for pages that are holder pages
87
     * @return String
88
     */
89
    public function getHolderPage()
90
    {
91
        return $this->holderPage;
92
    }
93
94
    /**
95
     * sets the classname for pages that are individual items
96
     * @param String $name
97
     */
98
    public function setEntryName($name)
99
    {
100
        $this->entryPage;
101
    }
102
103
    /**
104
     * gets the classname for pages that are individual items
105
     * @return String
106
     */
107
    public function getEntryName()
108
    {
109
        return $this->entryPage;
110
    }
111
}
112
113
class FaqHolderPage_Controller extends Page_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...
114
{
115
    public function init()
116
    {
117
        parent::init();
118
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
119
        Requirements::javascript("faqs/javascript/FaqHolderPage.js");
120
        Requirements::themedCSS("FaqHolderPage", "faqs");
121
    }
122
123
    /**
124
     * returns all underlying FaqOnePage pages...
125
     * for use in templates
126
     * @return DataList | Null
127
     */
128
    public function Entries()
129
    {
130
        $array = array($this->ID => $this->ID);
131
        if ($childGroups = $this->ChildGroups(4)) {
132
            if ($childGroups->count()) {
133
                foreach ($childGroups->map("ID", "ID") as $id) {
134
                    $array[$id] = $id;
135
                }
136
            }
137
        }
138
        $stage = '';
139
        if (Versioned::current_stage() == "Live") {
140
            $stage = "_Live";
141
        }
142
        $className = $this->dataRecord->getEntryName();
143
        return $className::get()
144
            ->filter(array("ParentID" => $array, "ShowInSearch" => 1))
145
            ->leftJoin("SiteTree".$stage, "SiteTree".$stage.".ParentID = MyParent.ID", "MyParent")
146
            ->leftJoin("SiteTree".$stage, "MyParent.ParentID = MyGrandParent.ID", "MyGrandParent")
147
            ->leftJoin("SiteTree".$stage, "MyGrandParent.ParentID = MyGreatGrandParent.ID", "MyGreatGrandParent")
148
            ->leftJoin("SiteTree".$stage, "MyGreatGrandParent.ParentID = MyGreatGreatGrandParent.ID", "MyGreatGreatGrandParent")
149
            ->sort(
150
                "
151
                MyGreatGreatGrandParent.Sort,
152
                MyGreatGrandParent.Sort,
153
                MyGrandParent.Sort,
154
                MyParent.Sort,
155
                SiteTree".$stage.".Sort"
156
            );
157
    }
158
159
    public function MyParentHolder()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
160
    {
161
        $className = $this->dataRecord->getHolderPage();
162
        return $className::get()->byID($this->ParentID);
163
    }
164
}
165