Completed
Push — master ( 3fdab8...e0dbd9 )
by Nicolaas
01:55
created

clearalltemplatedescriptions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
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 {
31
            user_error("It is recommended that you install the Sunny Side Up Pretty Photo Module", E_USER_NOTICE);
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(['TemplateOverviewPage', 'Page']);
38
    }
39
40
    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...
41
    {
42
        $id = $request->param("ID");
43
        $obj = SiteTree::get()->byID(intval($id));
44
        if ($obj) {
45
            $className = $obj->ClassName;
46
            $data = $className::get()
47
                ->filter(array("ClassName" => $obj->ClassName))
48
                ->limit(200);
49
            $array = array(
50
                "Results" => $data
51
            );
52
        } else {
53
            $array = array();
54
        }
55
        return $this->customise($array)->renderWith("TemplateOverviewPageShowMoreList");
56
    }
57
58
59
    public function ConfigurationDetails()
60
    {
61
        $m = Member::currentUser();
62
        if ($m) {
63
            if ($m->inGroup("ADMIN")) {
64
                $baseFolder = Director::baseFolder();
65
                $myFile = $baseFolder."/".$this->project()."/_config.php";
66
                $fh = fopen($myFile, 'r');
67
                $string = '';
68
                while (!feof($fh)) {
69
                    $string .= fgets($fh, 1024);
70
                }
71
                fclose($fh);
72
                return $string;
73
            }
74
        }
75
    }
76
77
78
    public function TestTaskLink()
79
    {
80
        return "/dev/tasks/CheckAllTemplates/";
81
    }
82
83
    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...
84
    {
85
        return $this->Link("quicklist");
86
    }
87
88
    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...
89
    {
90
        return $this->Link("listofobjectsused/Image");
91
    }
92
93
    public function quicklist()
94
    {
95
        $list = $this->ListOfAllClasses();
96
        foreach ($list as $item) {
97
            DB::alteration_message($item->ClassName);
98
        }
99
    }
100
101
    public function listofobjectsused($request)
102
    {
103
        $classWeAreLookingFor = $request->param("ID");
104
        $classWeAreLookingFor = singleton($classWeAreLookingFor);
105
        if ($classWeAreLookingFor instanceof DataObject) {
106
            $list = $this->ListOfAllClasses();
107
            foreach ($list as $item) {
108
                $config = Config::inst();
109
                $listOfImages = $config->get($item->ClassName, "has_one")
110
                 + $config->get($item->ClassName, "has_many")
111
                 + $config->get($item->ClassName, "many_many");
112
                foreach ($listOfImages as $fieldName => $potentialImage) {
113
                    $innerSingleton = singleton($potentialImage);
114
                    if ($innerSingleton instanceof $classWeAreLookingFor) {
115
                        DB::alteration_message($item->ClassName.".". $fieldName);
116
                    }
117
                }
118
            }
119
        } else {
120
            user_error("Please specify the ID for the model you are looking for - e.g. /listofobjectsused/Image/", E_USER_ERROR);
121
        }
122
    }
123
124
    /**
125
     * returns a list of all SiteTree Classes
126
     * @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...
127
     */
128
    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...
129
    {
130
        $templateOverviewPageAPI = Injector::inst()->get('TemplateOverviewPageAPI');
131
132
        return $templateOverviewPageAPI->ListOfAllClasses();
133
    }
134
135
136
    public function TotalCount()
137
    {
138
        return count(ClassInfo::subclassesFor("SiteTree"))-1;
139
    }
140
141
142
}
143