Completed
Push — master ( 5e49d6...04c860 )
by Nicolaas
05:31
created

code/TypographyTestPage_Controller.php (3 issues)

Severity

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
 * 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
 * TO DO: add a testing sheet with a list of checks to be made (e.g. italics, bold, paragraphy) - done YES / NO, a date and a person who checked it (member).
6
 */
7
8
class TypographyTestPage_Controller extends Page_Controller
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $include_first_heading_in_test_copy = false;
15
16
    /**
17
     * @var string
18
     */
19
    private static $css_folder = '';
20
21
    /**
22
     * use this to set up alternative form
23
     * formats
24
     * @var string
25
     */
26
    private static $form_class_name = "Form";
27
28
    public static function get_css_folder()
29
    {
30
        if (Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
31
            $folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder");
32
        } else {
33
            $folder = "themes/".SSViewer::current_theme()."/css/";
34
        }
35
        $fullFolder = Director::baseFolder().'/'.$folder;
36
        if (!file_exists($fullFolder)) {
37
            user_error("could not find the default CSS folder $fullFolder");
38
            $folder = '';
39
        }
40
        return $folder;
41
    }
42
43
    private static $allowed_actions = array(
44
        "colours" => "ADMIN",
45
        "replacecolours" => "ADMIN"
46
    );
47
48
    public function init()
49
    {
50
        parent::init();
51
        Page_Controller::init();
52
    }
53
54
    public function index()
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...
55
    {
56
        $this->Content = $this->typographyhtml();
57
        $this->Title = 'Typography Test Page';
58
        return $this->renderWith('Page');
59
    }
60
61
    public function ShowFirstHeading()
62
    {
63
        return Config::inst()->get("TypographyTestPage_Controller", "include_first_heading_in_test_copy");
64
    }
65
66
    public function colours()
67
    {
68
        $baseFolder = Director::baseFolder();
69
        require($baseFolder.'/typography/thirdparty/colourchart/csscolorchart.php');
70
        $cssPath = array($baseFolder.'/themes/', $baseFolder.$this->project()."css/");
71
        echo '<h1>CSS colors found in: ' .
72
            (is_array($cssPath)?implode($cssPath, ', '):$cssPath) . '</h1>';
73
        $themes = new CssColorChart();
74
        $colourList = $themes->listColors($cssPath);
75
        $html = DBField::create_field("HTMLText", $colourList);
76
        echo $html;
77
    }
78
79
    public function Form()
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...
80
    {
81
        $array = array();
82
        $array[] = "green";
83
        $array[] = "yellow";
84
        $array[] = "blue";
85
        $array[] = "pink";
86
        $array[] = "orange";
87
        $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1");
88
        $errorField0->setError("message shown when something is good", "good");
89
        $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2");
90
        $errorField1->setError("message shown when something is bad", "bad");
91
        $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3");
92
        $errorField2->setCustomValidationMessage("message shown when something is bad", "bad");
93
        $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4");
94
        $errorField3->setError("there is an error", "required");
95
        $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5");
96
        $errorField4->setCustomValidationMessage("custom validation error");
97
        $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default");
98
        $rightTitle->setRightTitle("right title here");
99
        $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField");
100
        $readonlyField->setValue("read only value");
101
        $groupedDropdownField = new GroupedDropdownField(
102
             $name = "dropdown",
103
             $title = "Simple Grouped Dropdown",
104
             $source = array(
105
                    "primary" => array(
106
                            "1" => "Green",
107
                            "2" => "Red",
108
                            "3" => "Blue",
109
                            "4" => "Orange"
110
                    ),
111
                    "secondary" => array(
112
                            "11" => "Light Blue",
113
                            "12" => "Dark Brown",
114
                            "13" => "Pinkish Red"
115
                    )
116
             )
117
        );
118
        $formClassName = Config::inst()->get("TypographyTestPage_Controller", "form_class_name");
119
        $form = $formClassName::create(
120
            $controller = $this,
121
            $name = "TestForm",
122
            $fields = new FieldList(
123
                // List the your fields here
124
                new HeaderField($name = "HeaderField1", $title = "Default Header Field"),
125
                new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"),
126
                new TextField($name = "TextField1", $title = "Text Field Example 1"),
127
                new TextField($name = "TextField2", $title = "Text Field Example 2"),
128
                new TextField($name = "TextField3", $title = "Text Field Example 3"),
129
                new TextField($name = "TextField4", $title = ""),
130
                new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2),
131
                new LiteralField($name = "ErrorExplanations", '<p>Below are some error messages, some of them only show up after you have placed your cursor on the field and not completed it (i.e. a reminder to complete the field)</p>'),
132
                $errorField0,
133
                $errorField1,
134
                $errorField2,
135
                $errorField3,
136
                $errorField4,
137
                new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2),
138
                $rightTitle,
139
                $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"),
140
                new EmailField("EmailField", "Email address"),
141
                new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2),
142
                new DropdownField($name = "DropdownField", $title = "Dropdown Field", array( 0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")),
143
                new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array),
144
                new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array),
145
                new CurrencyField($name = "CurrencyField", $title = "Bling bling"),
146
                new HeaderField($name = "HeaderField3", $title = "Other Fields", 3),
147
                new NumericField($name = "NumericField", $title = "Numeric Field "),
148
                new DateField($name = "DateField", $title = "Date Field"),
149
                new DateField($name = "DateTimeField", $title = "Date and Time Field"),
150
                new FileField($name = "FileField", $title = "File Field"),
151
                new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"),
152
                new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"),
153
                $groupedDropdownField,
154
                new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3),
155
                $readonlyField
156
            ),
157
            $actions = new FieldList(
158
                    // List the action buttons here
159
                    new FormAction("signup", "Sign up")
160
            ),
161
            $requiredFields = new RequiredFields(
162
                "TextField1", "TextField2", "TextField3", "ErrorField1", "ErrorField2", "EmailField", "TextField3", "RightTitleField", "CheckboxField", "CheckboxSetField"
163
            )
164
        );
165
        $textAreaField->setColumns(7);
166
        $form->setMessage("warning message", "warning");
167
        return $form;
168
    }
169
170
    public function TestForm($data)
171
    {
172
        $this->redirectBack();
173
    }
174
175
    protected function typographyhtml()
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...
176
    {
177
        return $this->renderWith('TypographySample');
178
    }
179
180
    public function RandomLinkExternal()
181
    {
182
        return "http://www.google.com/?q=".rand(0, 100000);
183
    }
184
185
    public function RandomLinkInternal()
186
    {
187
        return "/?q=".rand(0, 100000);
188
    }
189
190
    public function SiteColours()
191
    {
192
        if ($folder = TypographyTestPage_Controller::get_css_folder()) {
193
            Requirements::themedCSS("CssColorChart", "typography");
194
            //Requirements::javascript("typography/javascript/CssColorChart.js");
195
            $cssColorChart = new CssColorChart();
196
            return $cssColorChart->listColors(Director::baseFolder()."/".$folder);
197
        }
198
    }
199
200
    public function replacecolours()
201
    {
202
        if ($folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
203
            require_once(Director::baseFolder()."/typography/thirdparty/csscolorchart.php");
204
            $cssColorChart = new CssColorChart();
205
            return $cssColorChart->replaceColours(Director::baseFolder()."/".Config::inst()->get("TypographyTestPage_Controller", "css_folder"));
206
        }
207
        return "no folder specified, use TypographyTestPage_Controller::set_css_folder()";
208
    }
209
}
210