1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
**/ |
8
|
|
|
|
9
|
|
|
class SilverstripeColumnsPageControllerExtension extends Extension |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
private static $allowed_actions = [ |
|
|
|
|
12
|
|
|
'myspecificpagemenuitems' => true |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function HasFullWidthContent() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
if ($this->owner->hasMethod('HasFullWidthContentOverloaded')) { |
21
|
|
|
$v = $this->owner->HasFullWidthContentOverloaded(); |
22
|
|
|
if ($v !== null) { |
23
|
|
|
return $v; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
if ($this->owner->owner->getFullWidthContent()) { |
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
public function HasSideBar() |
35
|
|
|
{ |
36
|
|
|
if ($this->owner->hasMethod('HasSideBarOverloaded')) { |
37
|
|
|
$v = $this->owner->HasSideBarOverloaded(); |
38
|
|
|
if ($v !== null) { |
39
|
|
|
return $v; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
if ( |
43
|
|
|
( |
44
|
|
|
$this->owner->UseDefaultSideBarContent() && |
45
|
|
|
strlen($this->owner->getMyDefaultSidebarContent()) > 17 |
46
|
|
|
) |
47
|
|
|
|| |
48
|
|
|
$this->owner->MySidebarImage() |
49
|
|
|
) { |
50
|
|
|
return true; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param boolean $asClassName |
56
|
|
|
* |
57
|
|
|
* @return string | int |
58
|
|
|
*/ |
59
|
|
|
public function NumberOfColumns($asClassName = true) |
60
|
|
|
{ |
61
|
|
|
if ($this->owner->hasMethod('NumberOfColumnsOverloaded')) { |
62
|
|
|
return $this->owner->NumberOfColumnsOverloaded(); |
63
|
|
|
if ($v !== null) { |
|
|
|
|
64
|
|
|
return $v; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
$count = 1; |
68
|
|
|
if ($this->owner->HasSideBar()) { |
69
|
|
|
$count++; |
70
|
|
|
} |
71
|
|
|
if ($asClassName) { |
72
|
|
|
$array = array( |
73
|
|
|
1 => 'one', |
74
|
|
|
2 => 'two', |
75
|
|
|
3 => 'three' |
76
|
|
|
); |
77
|
|
|
return $array[$count]; |
78
|
|
|
} else { |
79
|
|
|
return $count; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* returns a data list of items that have been edited last - up to one day ago. |
86
|
|
|
* This ensures that we do not show stuff we have just fixed up... |
87
|
|
|
* @return DataList |
88
|
|
|
*/ |
89
|
|
|
public function RecentlyUpdated($limit = 5) |
90
|
|
|
{ |
91
|
|
|
if ($this->owner->hasMethod('RecentlyUpdatedOverloaded')) { |
92
|
|
|
$v = $this->owner->RecentlyUpdatedOverloaded(); |
93
|
|
|
if ($v !== null) { |
94
|
|
|
return $v; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
return Page::get() |
98
|
|
|
->filter( |
99
|
|
|
array( |
100
|
|
|
'ShowInSearch' => true, |
101
|
|
|
'LastEdited:LessThan' => date('Y-m-d h:i:s', time() - 86400) |
102
|
|
|
) |
103
|
|
|
) |
104
|
|
|
->sort(array('LastEdited' => 'DESC')) |
105
|
|
|
->limit($limit); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Children Menu Items |
110
|
|
|
* @return null | DataList |
111
|
|
|
*/ |
112
|
|
View Code Duplication |
public function InThisSection() |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
if ($this->owner->hasMethod('InThisSectionOverloaded')) { |
115
|
|
|
$v = $this->owner->InThisSectionOverloaded(); |
116
|
|
|
if ($v !== null) { |
117
|
|
|
return $v; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $this->owner->ChildrenShowInMenu(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Sibling Menu Items |
126
|
|
|
* @return null | DataList |
127
|
|
|
*/ |
128
|
|
|
public function AlsoSee() |
129
|
|
|
{ |
130
|
|
|
if ($this->owner->hasMethod('AlsoSeeOverloaded')) { |
131
|
|
|
$v = $this->owner->AlsoSeeOverloaded(); |
132
|
|
|
if ($v !== null) { |
133
|
|
|
return $v; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
if ($this->owner->ParentID) { |
137
|
|
|
$list = Page::get()->filter(['ShowInMenus' => 1, 'ParentID' => $this->owner->dataRecord->ParentID]); |
138
|
|
|
$list = $list->exclude(['ID' => $this->owner->ID]); |
139
|
|
|
|
140
|
|
|
return $list; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* returns relevant menus items for |
146
|
|
|
* @param SS_Request |
147
|
|
|
* @return string (html) |
148
|
|
|
*/ |
149
|
|
|
public function myspecificpagemenuitems($request) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
if ($this->owner->hasMethod('MySpecificPageMenuItemsOverloaded')) { |
152
|
|
|
$v = $this->owner->MySpecificPageMenuItemsOverloaded(); |
153
|
|
|
if ($v !== null) { |
154
|
|
|
return $v; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
$id = intval($this->owner->request->param('ID')); |
158
|
|
|
$this->owner->setShowMenuItemsFor($id); |
159
|
|
|
return ArrayData::create( |
160
|
|
|
[ |
161
|
|
|
'MyMenuItems' => $this->owner->MyMenuItems(), |
162
|
|
|
'MyMenuItemsParentPage' => $this->owner->MyMenuItemsParentPage(), |
163
|
|
|
'MyMenuItemsParentLink' => $this->owner->MyMenuItemsParentLink() |
164
|
|
|
] |
165
|
|
|
) |
166
|
|
|
->renderWith('MyMenuItems'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function IsNotHome() |
171
|
|
|
{ |
172
|
|
|
$link = $this->owner->Link(); |
173
|
|
|
|
174
|
|
|
return $link === 'home' || $link = '/'; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
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.