|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class PreviewPageRow extends ContentController |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
private static $url_segment = 'preview-page-row'; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
9
|
|
|
'preview' => 'ADMIN', |
|
10
|
|
|
'view' => true |
|
11
|
|
|
]; |
|
12
|
|
|
|
|
13
|
|
|
private $pageRows = null; |
|
14
|
|
|
|
|
15
|
|
|
public function preview($request) |
|
16
|
|
|
{ |
|
17
|
|
|
return $notFoundResponse = $this->processRequest($request, false); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* @param string | null $action |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
public function Link($action = null) |
|
26
|
|
|
{ |
|
27
|
|
|
$link = '/'.$this->Config()->get('url_segment').'/'; |
|
28
|
|
|
if ($action) { |
|
29
|
|
|
$link .= $action . '/'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return $link; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function view($request) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->processRequest($request, true); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function processRequest($request, $readyForPublic) |
|
41
|
|
|
{ |
|
42
|
|
|
$id = $request->param('ID'); |
|
43
|
|
|
$pageRowClassNames = ClassInfo::subclassesFor('PageRow'); |
|
44
|
|
|
$listOfClasses = []; |
|
45
|
|
|
foreach ($pageRowClassNames as $key => $class) { |
|
|
|
|
|
|
46
|
|
|
$listOfClasses[strtolower($class)] = $class; |
|
47
|
|
|
} |
|
48
|
|
|
$errorResponse = null; |
|
49
|
|
|
PageRow::set_current_page_object(Page::get()->first()); |
|
50
|
|
|
if ($id == 'all') { |
|
51
|
|
|
$this->pageRows = PageRow::get(); |
|
52
|
|
|
} elseif ($id == 'oneofeach') { |
|
53
|
|
|
$tempList = PageRow::get()->sort('RAND()'); |
|
54
|
|
|
$oneIDPerClassNameArray = []; |
|
55
|
|
|
foreach ($tempList as $obj) { |
|
56
|
|
|
$oneIDPerClassNameArray[$obj->ClassName] = $obj->ID; |
|
57
|
|
|
} |
|
58
|
|
|
$this->pageRows = PageRow::get()->filter(['ID' => $oneIDPerClassNameArray]); |
|
59
|
|
|
} elseif (isset($listOfClasses[$id])) { |
|
60
|
|
|
$this->pageRows = PageRow::get()->filter(['ClassName' => $listOfClasses[$id]]); |
|
61
|
|
|
} else { |
|
62
|
|
|
$id = intval($id); |
|
63
|
|
|
$this->pageRows = PageRow::get()->filter(['ID' =>$id]); |
|
64
|
|
|
} |
|
65
|
|
|
if ($readyForPublic) { |
|
66
|
|
|
$this->pageRows = $this->pageRows->filter(['ReadyForPublication' => 1]); |
|
67
|
|
|
} |
|
68
|
|
|
$this->pageRows = $this->pageRows->exclude(['ClassName' => 'DownloadBlock']); |
|
69
|
|
|
if (! $this->pageRows->count()) { |
|
70
|
|
|
$errorResponse = $this->httpError(404, 'The requested page block could not be found.'); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
if ($errorResponse) { |
|
73
|
|
|
return $errorResponse; |
|
74
|
|
|
} else { |
|
75
|
|
|
return $this->renderWith('PreviewPageRow'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function PageRowsReadyForPublication() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->pageRows; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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.