Completed
Pull Request — master (#664)
by
unknown
06:45
created

TimezoneMemberExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimezones() 0 4 1
A updateCMSFields() 0 9 1
1
<?php
2
/**
3
 * Class TimezoneMemberExtension.
4
 *
5
 * Adds all available timezones as an optional field to SilverStripe {@link Member}.
6
 */
7
class TimezoneMemberExtension extends DataExtension {
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...
8
	private static $db = [
9
		'Timezone' => 'Varchar(255)',
10
	];
11
12
	public function getTimezones() {
13
		$timezones = timezone_identifiers_list();
14
		return array_combine($timezones, $timezones);
15
	}
16
17
	public function updateCMSFields(FieldList $fields) {   
18
		$fields->removeFieldFromTab('Root', 'Timezone');
19
		$field = DropdownField::create(
20
		  'Timezone',
21
		  'Timezone',
22
		  $this->getTimezones())->setEmptyString('For NZ, choose Pacific/Auckland');
23
		$fields->addFieldToTab('Root.timezone', $field);
24
		return $fields;
25
	}
26
27
}
28