Completed
Push — master ( e0dbd9...522473 )
by Nicolaas
01:52
created

TemplateOverviewPage_Controller::Content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *@author: nicolaas [at] sunnysideup.co.nz
4
 *@description Add a page to your site that allows you to view all the html that can be used in the typography section - if applied correctly.
5
 */
6
7
8
9
class TemplateOverviewPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        "showmore" => true,
13
        "quicklist" => true,
14
        "listofobjectsused" => true
15
    );
16
17
    public function init()
18
    {
19
        parent::init();
20
        if (!Director::is_cli() && !Director::isDev() && !Permission::check('ADMIN')) {
21
            return Security::permissionFailure();
22
        }
23
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
24
        Requirements::javascript('templateoverview/javascript/TemplateOverviewPage.js');
25
        Requirements::css("templateoverview/css/TemplateOverviewPage.css");
26
        if (class_exists("PrettyPhoto")) {
27
            if(method_exists('PrettyPhoto','include_code')) {
28
                PrettyPhoto::include_code();
29
            }
30
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
31
            //user_error("It is recommended that you install the Sunny Side Up Pretty Photo Module", E_USER_NOTICE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
        }
33
    }
34
35
    function index()
0 ignored issues
show
Documentation introduced by
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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
    {
37
        return $this->renderWith(['Page', 'Page']);
38
    }
39
40
    function Content()
0 ignored issues
show
Documentation introduced by
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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
    {
42
        return $this->renderWith('TemplateOverviewPage');
43
    }
44
45
    public function showmore($request)
0 ignored issues
show
Documentation introduced by
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...
46
    {
47
        $id = $request->param("ID");
48
        $obj = SiteTree::get()->byID(intval($id));
49
        if ($obj) {
50
            $className = $obj->ClassName;
51
            $data = $className::get()
52
                ->filter(array("ClassName" => $obj->ClassName))
53
                ->limit(200);
54
            $array = array(
55
                "Results" => $data
56
            );
57
        } else {
58
            $array = array();
59
        }
60
        return $this->customise($array)->renderWith("TemplateOverviewPageShowMoreList");
61
    }
62
63
64
    public function ConfigurationDetails()
65
    {
66
        $m = Member::currentUser();
67
        if ($m) {
68
            if ($m->inGroup("ADMIN")) {
69
                $baseFolder = Director::baseFolder();
70
                $myFile = $baseFolder."/".$this->project()."/_config.php";
71
                $fh = fopen($myFile, 'r');
72
                $string = '';
73
                while (!feof($fh)) {
74
                    $string .= fgets($fh, 1024);
75
                }
76
                fclose($fh);
77
                return $string;
78
            }
79
        }
80
    }
81
82
83
    public function TestTaskLink()
84
    {
85
        return "/dev/tasks/CheckAllTemplates/";
86
    }
87
88
    public function QuickListLink()
0 ignored issues
show
Documentation introduced by
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...
89
    {
90
        return $this->Link("quicklist");
91
    }
92
93
    public function ImagesListLink()
0 ignored issues
show
Documentation introduced by
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...
94
    {
95
        return $this->Link("listofobjectsused/Image");
96
    }
97
98
    public function quicklist()
99
    {
100
        $list = $this->ListOfAllClasses();
101
        foreach ($list as $item) {
102
            DB::alteration_message($item->ClassName);
103
        }
104
    }
105
106
    public function listofobjectsused($request)
107
    {
108
        $classWeAreLookingFor = $request->param("ID");
109
        $classWeAreLookingFor = singleton($classWeAreLookingFor);
110
        if ($classWeAreLookingFor instanceof DataObject) {
111
            $list = $this->ListOfAllClasses();
112
            foreach ($list as $item) {
113
                $config = Config::inst();
114
                $listOfImages = $config->get($item->ClassName, "has_one")
115
                 + $config->get($item->ClassName, "has_many")
116
                 + $config->get($item->ClassName, "many_many");
117
                foreach ($listOfImages as $fieldName => $potentialImage) {
118
                    $innerSingleton = singleton($potentialImage);
119
                    if ($innerSingleton instanceof $classWeAreLookingFor) {
120
                        DB::alteration_message($item->ClassName.".". $fieldName);
121
                    }
122
                }
123
            }
124
        } else {
125
            user_error("Please specify the ID for the model you are looking for - e.g. /listofobjectsused/Image/", E_USER_ERROR);
126
        }
127
    }
128
129
    /**
130
     * returns a list of all SiteTree Classes
131
     * @return Array(String)
0 ignored issues
show
Documentation introduced by
The doc-type Array(String) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
132
     */
133
    public function ListOfAllClasses()
0 ignored issues
show
Documentation introduced by
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...
134
    {
135
        $templateOverviewPageAPI = Injector::inst()->get('TemplateOverviewPageAPI');
136
137
        return $templateOverviewPageAPI->ListOfAllClasses();
138
    }
139
140
141
    public function TotalCount()
142
    {
143
        return count(ClassInfo::subclassesFor("SiteTree"))-1;
144
    }
145
146
147
}
148