GalleryHub::onBeforeWrite()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 16
nop 0
1
<?php
2
3
/**
4
 * Generate a page that can display it's children as a grid of thumbnails
5
 * 
6
 * @package gallery
7
 */
8
class GalleryHub extends Page
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...
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $description = 'Display child galleries as a thumbnail grid';
0 ignored issues
show
Unused Code introduced by
The property $description 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...
15
16
    private static $icon = "gallery/images/gallery-hub.png";
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
17
18
    /**
19
     * @var array
20
     */
21
    private static $allowed_children = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_children 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...
22
        'GalleryPage',
23
    );
24
25
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db 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...
26
        "ShowSideBar" => "Boolean",
27
        "ShowImageTitles" => "Boolean",
28
        "ThumbnailWidth" => "Int",
29
        "ThumbnailHeight" => "Int",
30
        "ThumbnailResizeType" => "Enum(array('crop','pad','ratio','width','height'), 'crop')",
31
        "PaddedImageBackground" => "Varchar",
32
        "ThumbnailsPerPage" => "Int"
33
    );
34
35
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults 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...
36
        "ThumbnailWidth" => 150,
37
        "ThumbnailHeight" => 150,
38
        "ThumbnailsPerPage" => 18,
39
        "PaddedImageBackground" => "ffffff",
40
        "ThumbnailsPerPage" => 18
41
    );
42
43
    public function getSettingsFields()
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...
44
    {
45
        $fields = parent::getSettingsFields();
46
47
        $fields->addFieldsToTab(
48
            "Root.Settings",
49
            [
50
                CheckboxField::create('ShowSideBar'),
51
                CheckboxField::create('ShowImageTitles'),
52
                NumericField::create("ThumbnailWidth"),
53
                NumericField::create("ThumbnailHeight"),
54
                DropdownField::create("ThumbnailResizeType")
55
                    ->setSource($this->dbObject("ThumbnailResizeType")->enumValues()),
56
                NumericField::create('ThumbnailsPerPage'),
57
                TextField::create("PaddedImageBackground")
58
            ]
59
        );
60
61
        return $fields;
62
    }
63
64
    public function onBeforeWrite()
65
    {
66
        parent::onBeforeWrite();
67
68
        // default settings (if not set)
69
        $defaults = $this->config()->defaults;
70
        $this->ThumbnailWidth = ($this->ThumbnailWidth) ? $this->ThumbnailWidth : $defaults["ThumbnailWidth"];
71
        $this->ThumbnailHeight = ($this->ThumbnailHeight) ? $this->ThumbnailHeight : $defaults["ThumbnailHeight"];
72
        $this->ThumbnailsPerPage = ($this->ThumbnailsPerPage) ? $this->ThumbnailsPerPage : $defaults["ThumbnailsPerPage"];
73
        $this->PaddedImageBackground = ($this->PaddedImageBackground) ? $this->PaddedImageBackground : $defaults["PaddedImageBackground"];
74
    }
75
}
76