Completed
Push — master ( 63cfe4...886ab6 )
by Nicolaas
01:32
created

code/SiteMapPage.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
/**
5
 * @author Nicolaas [at] sunnysideup.co.nz
6
 *
7
 *
8
 **/
9
10
11
class SiteMapPage extends Page
12
{
13
    private static $db = array(
14
        "ShowAllPages" => "Boolean"
15
    );
16
17
    private static $description = "Sitemap Page: shows all the pages of a site in a tree format";
18
19
    private static $add_action = 'Site Map Page';
20
21
    private static $icon = 'sitemappage/images/treeicons/SiteMapPage';
22
23
    public function canCreate($member = null)
24
    {
25
        return ! SiteMapPage::get()->count();
26
    }
27
28
    public function getCMSFields()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
    {
30
        $fields = parent::getCMSFields();
31
        $fields->addFieldToTab("Root.Display", new CheckboxField("ShowAllPages", "Show all pages from the start"));
32
        return $fields;
33
    }
34
}
35
36
class SiteMapPage_Controller extends Page_Controller
37
{
38
    public function init()
39
    {
40
        parent::init();
41
        if (!$this->ShowAllPages) {
42
            Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
43
            Requirements::javascript('sitemappage/javascript/SiteMapPage.js');
44
            Requirements::themedCSS('SiteMapPage', "sitemappage");
45
        } else {
46
            Requirements::themedCSS('SiteMapPageOpen', "sitemappage");
47
        }
48
    }
49
50
    public function LevelOneSiteMapPages()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
51
    {
52
        $homePage = SiteTree::get()->filter(array("ParentID" => 0))->first();
53
        return $homePage->SiteMapPages($noParent = true);
54
    }
55
}
56