1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @author nicolaas [at] sunnysideup.co.nz |
5
|
|
|
*/ |
6
|
|
|
class TrainingMemberDecorator extends DataExtension |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
9
|
|
|
'Training' => 'TrainingPage' |
10
|
|
|
); |
11
|
|
|
private static $db = array( |
|
|
|
|
12
|
|
|
'Organisation' => 'Varchar', |
13
|
|
|
'Phone' => 'Varchar' |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
public function getTrainingFields() |
19
|
|
|
{ |
20
|
|
|
$fields = new FieldList( |
21
|
|
|
new TextField('FirstName', 'First Name'), |
22
|
|
|
new TextField('Surname', 'Surname'), |
23
|
|
|
new TextField('Organisation'), |
24
|
|
|
new EmailField('Email', 'Email'), |
25
|
|
|
new TextField('Phone') |
26
|
|
|
); |
27
|
|
|
return $fields; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getTrainingRequiredFields() |
31
|
|
|
{ |
32
|
|
|
$fields = array( |
33
|
|
|
'FirstName', |
34
|
|
|
'Surname', |
35
|
|
|
'Organisation', |
36
|
|
|
'Email', |
37
|
|
|
'Phone' |
38
|
|
|
); |
39
|
|
|
return $fields; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function createOrMerge($data) |
43
|
|
|
{ |
44
|
|
|
// Because we are using a ConfirmedPasswordField, the password will |
45
|
|
|
// be an array of two fields |
46
|
|
View Code Duplication |
if (isset($data['Password']) && is_array($data['Password'])) { |
|
|
|
|
47
|
|
|
$data['Password'] = $data['Password']['_Password']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// We need to ensure that the unique field is never overwritten |
51
|
|
|
$uniqueField = Member::get_unique_identifier_field(); |
|
|
|
|
52
|
|
View Code Duplication |
if (isset($data[$uniqueField])) { |
|
|
|
|
53
|
|
|
$SQL_unique = Convert::raw2sql($data[$uniqueField]); |
54
|
|
|
$existingUniqueMember = Member::get()->filter(array($uniqueField => $SQL_unique))->first(); |
55
|
|
|
if ($existingUniqueMember && $existingUniqueMember->exists()) { |
56
|
|
|
if (Member::currentUserID() != $existingUniqueMember->ID) { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!$member = Member::currentUser()) { |
63
|
|
|
$member = new Member(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$member->update($data); |
67
|
|
|
|
68
|
|
|
return $member; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.