Completed
Push — master ( 58895a...0930e8 )
by Robbie
15s
created

SitemapPageController::showpage()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 5
nop 1
dl 0
loc 29
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace CWP\CWP\PageTypes;
4
5
use PageController;
0 ignored issues
show
Bug introduced by
The type PageController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\CMS\Model\SiteTree;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Dev\Deprecation;
9
10
class SitemapPageController extends PageController
11
{
12
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
13
        'showpage',
14
    ];
15
16
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
17
        'page/$ID' => 'showpage',
18
    ];
19
20
    public function Page($link)
21
    {
22
        if ($link instanceof HTTPRequest) {
23
            Deprecation::notice('2.0', 'Using page() as a url handler is deprecated. Use showpage() action instead');
24
            return $this->showpage($link);
25
        }
26
        return parent::Page($link);
27
    }
28
29
    public function showpage($request)
30
    {
31
        $id = (int) $request->param('ID');
32
        if (!$id) {
33
            return false;
34
        }
35
        $page = SiteTree::get()->byId($id);
36
37
        // does the page exist?
38
        if (!($page && $page->exists())) {
39
            return $this->httpError(404);
40
        }
41
42
        // can the page be viewed?
43
        if (!$page->canView()) {
44
            return $this->httpError(403);
45
        }
46
47
        $viewer = $this->customise([
48
            'IsAjax' => $request->isAjax(),
49
            'SelectedPage' => $page,
50
            'Children' => $page->Children(),
51
        ]);
52
53
        if ($request->isAjax()) {
54
            return $viewer->renderWith('SitemapNodeChildren');
55
        }
56
57
        return $viewer;
58
    }
59
}
60