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 { |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
* @config |
24
|
|
|
*/ |
25
|
|
|
private static $db = [ |
|
|
|
|
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 = [ |
|
|
|
|
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
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.