|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class TemplateoverviewPageAPI extends Object |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
private static $list_of_all_classes = array(); |
|
9
|
|
|
|
|
10
|
|
|
private static $classes_to_exclude = array("SiteTree", "RedirectorPage", "VirtualPage"); |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
* @var Bool |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $showAll = false; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
* @var int |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $counter = 0; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function ListOfAllClasses($checkCurrentClass = true) |
|
26
|
|
|
{ |
|
27
|
|
|
if (!self::$list_of_all_classes) { |
|
|
|
|
|
|
28
|
|
|
$ArrayOfAllClasses = array(); |
|
29
|
|
|
//$classes = ClassInfo::subclassesFor("SiteTree"); |
|
|
|
|
|
|
30
|
|
|
$classes = SiteTree::page_type_classes(); |
|
31
|
|
|
$classesToRemove = array(); |
|
32
|
|
|
|
|
33
|
|
|
foreach ($classes as $className) { |
|
34
|
|
|
if (!in_array($className, $this->config()->get("classes_to_exclude"))) { |
|
35
|
|
|
if ($this->showAll) { |
|
36
|
|
|
$objects = $className::get() |
|
37
|
|
|
->filter(array("ClassName" => $className)) |
|
38
|
|
|
->sort("RAND() ASC") |
|
39
|
|
|
->limit(25); |
|
40
|
|
|
$count = 0; |
|
41
|
|
|
if ($objects->count()) { |
|
42
|
|
|
foreach ($objects as $obj) { |
|
43
|
|
|
if (!$count) { |
|
44
|
|
|
if ($ancestorToHide = $obj->stat('hide_ancestor')) { |
|
45
|
|
|
$classesToRemove[] = $ancestorToHide; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
$object = $this->createPageObject($obj, $count++); |
|
49
|
|
|
$ArrayOfAllClasses[$object->indexNumber] = clone $object; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
$obj = null; |
|
|
|
|
|
|
54
|
|
|
$obj = $className::get() |
|
55
|
|
|
->filter(array("ClassName" => $className)) |
|
56
|
|
|
->sort("RAND() ASC") |
|
57
|
|
|
->limit(1) |
|
58
|
|
|
->first(); |
|
59
|
|
|
if ($obj) { |
|
60
|
|
|
$count = SiteTree::get()->filter(array("ClassName" => $obj->ClassName))->count(); |
|
61
|
|
|
} else { |
|
62
|
|
|
$obj = $className::create(); |
|
63
|
|
|
$count = 0; |
|
64
|
|
|
} |
|
65
|
|
|
if ($ancestorToHide = $obj->stat('hide_ancestor')) { |
|
66
|
|
|
$classesToRemove[] = $ancestorToHide; |
|
67
|
|
|
} |
|
68
|
|
|
$object = $this->createPageObject($obj, $count); |
|
69
|
|
|
$ArrayOfAllClasses[$object->indexNumber] = clone $object; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
//remove the hidden ancestors... |
|
75
|
|
|
if ($classesToRemove && count($classesToRemove)) { |
|
|
|
|
|
|
76
|
|
|
$classesToRemove = array_unique($classesToRemove); |
|
77
|
|
|
// unset from $classes |
|
78
|
|
|
foreach ($ArrayOfAllClasses as $tempKey => $tempClass) { |
|
79
|
|
|
if (in_array($tempClass->ClassName, $classesToRemove)) { |
|
80
|
|
|
unset($ArrayOfAllClasses[$tempKey]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
ksort($ArrayOfAllClasses); |
|
85
|
|
|
self::$list_of_all_classes = new ArrayList(); |
|
|
|
|
|
|
86
|
|
|
$currentClassname = ''; |
|
87
|
|
|
if ($checkCurrentClass) { |
|
88
|
|
|
if ($c = Controller::curr()) { |
|
89
|
|
|
if ($d = $c->dataRecord) { |
|
90
|
|
|
$currentClassname = $d->ClassName; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
if (count($ArrayOfAllClasses)) { |
|
95
|
|
|
foreach ($ArrayOfAllClasses as $item) { |
|
96
|
|
|
if ($item->ClassName == $currentClassname) { |
|
97
|
|
|
$item->LinkingMode = "current"; |
|
98
|
|
|
} else { |
|
99
|
|
|
$item->LinkingMode = "link"; |
|
100
|
|
|
} |
|
101
|
|
|
self::$list_of_all_classes->push($item); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
return self::$list_of_all_classes; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function ShowAll() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->showAll = true; |
|
111
|
|
|
return array(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param SiteTree $obj |
|
117
|
|
|
* @param Int $count |
|
118
|
|
|
* @param String $ClassName |
|
|
|
|
|
|
119
|
|
|
* @return ArrayData |
|
120
|
|
|
*/ |
|
121
|
|
|
private function createPageObject($obj, $count) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->counter++; |
|
124
|
|
|
$listArray = array(); |
|
125
|
|
|
$indexNumber = (10000 * $count) + $this->counter; |
|
126
|
|
|
$listArray["indexNumber"] = $indexNumber; |
|
127
|
|
|
$listArray["ClassName"] = $obj->ClassName; |
|
128
|
|
|
$listArray["Count"] = $count; |
|
129
|
|
|
$listArray["ID"] = $obj->ID; |
|
130
|
|
|
$listArray["URLSegment"] = $obj->URLSegment; |
|
131
|
|
|
$listArray["TypoURLSegment"] = $this->Link(); |
|
132
|
|
|
$listArray["Title"] = $obj->MenuTitle; |
|
133
|
|
|
$listArray["PreviewLink"] = $obj->PreviewLink(); |
|
134
|
|
|
$listArray["CMSEditLink"] = $obj->CMSEditLink(); |
|
135
|
|
|
$staticIcon = $obj->stat("icon", true); |
|
136
|
|
|
if (is_array($staticIcon)) { |
|
137
|
|
|
$iconArray = $obj->stat("icon"); |
|
138
|
|
|
$icon = $iconArray[0]; |
|
139
|
|
|
} else { |
|
140
|
|
|
$icon = $obj->stat("icon"); |
|
141
|
|
|
} |
|
142
|
|
|
$iconFile = Director::baseFolder().'/'.$icon; |
|
143
|
|
|
if (!file_exists($iconFile)) { |
|
144
|
|
|
$icon = $icon."-file.gif"; |
|
145
|
|
|
} |
|
146
|
|
|
$listArray["Icon"] = $icon; |
|
147
|
|
|
return new ArrayData($listArray); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
//not used! |
|
151
|
|
|
public function NoSubClasses($obj) |
|
152
|
|
|
{ |
|
153
|
|
|
$array = ClassInfo::subclassesFor($obj->ClassName); |
|
154
|
|
|
if (count($array)) { |
|
155
|
|
|
foreach ($array as $class) { |
|
|
|
|
|
|
156
|
|
|
if ($class::get()->byID($obj->ID)) { |
|
157
|
|
|
return false; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
return true; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
function Link($action = null) |
|
|
|
|
|
|
165
|
|
|
{ |
|
166
|
|
|
$v = '/templates'; |
|
167
|
|
|
if($action) { |
|
168
|
|
|
$v .= $action . '/'; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return $v; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
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.