Completed
Branch master (003c26)
by Pixelneat
02:56
created

Marker::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author    Donatas Navidonskis <[email protected]>
5
 * @since     2017
6
 * @class     Marker
7
 *
8
 * @property int     BlockID
9
 * @property int     MarkerID
10
 * @property string  InstanceId
11
 * @property string  Address
12
 * @property string  Content
13
 * @property string  Coordinates
14
 * @property boolean DisplayWindow
15
 *
16
 * @method MapBlock Block
17
 * @method \Image Marker
18
 */
19
class Marker extends \DataObject {
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...
20
21
    /**
22
     * @var array
23
     * @config
24
     */
25
    private static $db = [
1 ignored issue
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...
26
        'InstanceId'    => 'Varchar',
27
        'Address'       => 'Varchar',
28
        'Content'       => 'HTMLText',
29
        'Coordinates'   => 'Varchar(255)',
30
        'DisplayWindow' => 'Boolean(true)',
31
    ];
32
33
    /**
34
     * @var array
35
     * @config
36
     */
37
    private static $has_one = [
1 ignored issue
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 $has_one 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...
38
        'Block'  => 'MapBlock',
39
        'Marker' => 'Image',
40
    ];
41
42
    /**
43
     * @return array
44
     */
45
    public function summaryFields() {
46
        return [
47
            'InstanceId'  => $this->fieldLabel('InstanceId'),
48
            'Address'     => $this->fieldLabel('Address'),
49
            'Coordinates' => $this->fieldLabel('Coordinates'),
50
        ];
51
    }
52
53
    /**
54
     * @return \FieldList
55
     */
56
    public function getCMSFields() {
57
        $fields = parent::getCMSFields();
58
59
        $fields->addFieldsToTab('Root.Main', [
60
            $instanceId = \TextField::create('InstanceId', $this->fieldLabel('InstanceId')),
61
            $address = \TextField::create('Address', $this->fieldLabel('Address')),
62
            $content = \HtmlEditorField::create('Content', $this->fieldLabel('Content')),
63
            $coordinates = \TextField::create('Coordinates', $this->fieldLabel('Coordinates')),
64
            $displayWindow = \CheckboxField::create('DisplayWindow', $this->fieldLabel('DisplayWindow')),
65
            $block = \DropdownField::create('BlockID', $this->fieldLabel('Block'), MapBlock::get()->map()),
66
            $marker = \UploadField::create('Marker', $this->fieldLabel('Marker')),
67
        ]);
68
69
        $marker
70
            ->setAllowedFileCategories('image')
71
            ->setAllowedMaxFileNumber(1)
72
            ->setFolderName('Uploads/Blocks/Markers');
73
74
        $content
75
            ->setRows(15);
76
77
        $this->extend('updateCMSFields', $fields);
78
79
        return $fields;
80
    }
81
82
    /**
83
     * @param bool $includeRelations
84
     *
85
     * @return array
86
     */
87
    public function fieldLabels($includeRelations = true) {
88
        return array_merge(parent::fieldLabels($includeRelations), [
89
            'InstanceId'    => _t('Marker.INSTANCE_ID', 'Instance Id'),
90
            'Address'       => _t('Marker.ADDRESS', 'Address'),
91
            'Content'       => _t('Marker.CONTENT', 'Content'),
92
            'Coordinates'   => _t('Marker.COORDINATES', 'Coordinates'),
93
            'DisplayWindow' => _t('Marker.DISPLAY_WINDOW', 'Display content in window popup?'),
94
            'Block'         => _t('Marker.BLOCK', 'Block'),
95
            'Marker'        => _t('Marker.MARKER', 'Marker'),
96
        ]);
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getTitle() {
103
        return $this->InstanceId;
104
    }
105
106
    /**
107
     * @param string $instanceId
108
     *
109
     * @return Marker
110
     */
111
    public static function getByInstanceId($instanceId) {
112
        return static::get()->filter('InstanceId', $instanceId)->first();
113
    }
114
}