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 |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
private static $icon = "mysite/images/treeicons/FaqHolderPage"; |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $description = "A list of Frequently Asked Questions" ; |
|
|
|
|
13
|
|
|
|
14
|
|
|
//private static $default_parent = ''; |
|
|
|
|
15
|
|
|
|
16
|
|
|
private static $default_child = 'FaqOnePage'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
private static $allowed_children = array('FaqHolderPage', 'FaqOnePage'); |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Standard SS variable. |
22
|
|
|
*/ |
23
|
|
|
private static $singular_name = "FAQ Holder Page"; |
|
|
|
|
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"; |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
MyGreatGreatGrandParent.Sort ASC, |
151
|
|
|
MyGreatGrandParent.Sort ASC, |
152
|
|
|
MyGrandParent.Sort ASC, |
153
|
|
|
MyParent.Sort ASC, |
154
|
|
|
SiteTree".$stage.".Sort ASC" |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
function MyParentHolder() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$className = $this->dataRecord->getHolderPage(); |
161
|
|
|
return $className::get()->byID($this->ParentID); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.