GalleryPage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 94
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 27 2
1
<?php
2
3
/**
4
 * A single page that can display many images as thumbnails.
5
 * 
6
 * @package gallery
7
 */
8
class GalleryPage extends GalleryHub
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
     * @var string
12
     */
13
    private static $description = 'Display a "gallery" of images';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
14
15
    private static $icon = "gallery/images/gallery.png";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
16
17
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
18
        "ImageWidth" => "Int",
19
        "ImageHeight" => "Int",
20
        "ImageResizeType" => "Enum(array('crop','pad','ratio','width','height'), 'ratio')"
21
    );
22
23
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
24
        "ImageWidth" => 950,
25
        "ImageHeight" => 500,
26
        "ShowSideBar" => 1
27
    );
28
29
    private static $many_many = array(
0 ignored issues
show
Unused Code introduced by
The property $many_many 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...
30
        'Images' => 'Image'
31
    );
32
33
    private static $many_many_extraFields = array(
0 ignored issues
show
Unused Code introduced by
The property $many_many_extraFields 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...
34
        'Images' => array('SortOrder' => 'Int')
35
    );
36
37
    /**
38
     * Return sorted images
39
     *
40
     * @return ArrayList
41
     */
42
    public function SortedImages()
43
    {
44
        return $this->Images()->Sort('SortOrder');
45
    }
46
47
    public function getCMSFields()
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...
48
    {
49
        $self =& $this;
50
        
51
        $this->beforeUpdateCMSFields(function ($fields) use ($self) {
52
            if (!$self->canEdit()) {
53
                return;
54
            }
55
            
56
            $fields->removeByName('HideDescription');
57
            
58
            $upload_folder = Controller::join_links(
59
                "gallery",
60
                $self->ID
61
            );
62
            
63
            $fields->addFieldToTab(
64
                "Root.Gallery",
65
                SortableUploadField::create(
66
                    'Images',
67
                    $this->fieldLabel('Images')
68
                )->setFolderName($upload_folder)
69
            );
70
        });
71
            
72
        return parent::getCMSFields();
73
    }
74
75
    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...
76
        $fields = parent::getSettingsFields();
77
78
        $fields->addFieldsToTab(
79
            'Root.Settings',
80
            array(
81
                NumericField::create("ImageWidth"),
82
                NumericField::create("ImageHeight"),
83
                DropdownField::create("ImageResizeType")
84
                    ->setSource($this->dbObject("ImageResizeType")->enumValues())
85
            )
86
        );
87
88
        return $fields;
89
    }
90
91
    public function onBeforeWrite()
92
    {
93
        parent::onBeforeWrite();
94
95
        // default settings (if not set)
96
        $defaults = $this->config()->defaults;
97
        $this->ImageWidth = ($this->ImageWidth) ? $this->ImageWidth : $defaults["ImageWidth"];
98
        $this->ImageHeight = ($this->ImageHeight) ? $this->ImageHeight : $defaults["ImageHeight"];
99
    }
100
101
}
102