|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class EmailReminder_EmailRecord extends DataObject |
|
4
|
|
|
{ |
|
5
|
|
|
private static $singular_name = "Email Reminder Record"; |
|
|
|
|
|
|
6
|
|
|
public function i18n_singular_name() |
|
7
|
|
|
{ |
|
8
|
|
|
return self::$singular_name; |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
private static $plural_name = "Email Reminder Records"; |
|
|
|
|
|
|
12
|
|
|
public function i18n_plural_name() |
|
13
|
|
|
{ |
|
14
|
|
|
return self::$plural_name; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
private static $db = array( |
|
|
|
|
|
|
18
|
|
|
'EmailTo' => 'Varchar(100)', |
|
19
|
|
|
'ExternalRecordClassName' => 'Varchar(100)', |
|
20
|
|
|
'ExternalRecordID' => 'Int', |
|
21
|
|
|
'Result' => 'Boolean', |
|
22
|
|
|
'IsTestOnly' => 'Boolean', |
|
23
|
|
|
'EmailContent' => 'HTMLText' |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
private static $indexes = array( |
|
|
|
|
|
|
27
|
|
|
'EmailTo' => true, |
|
28
|
|
|
'ExternalRecordClassName' => true, |
|
29
|
|
|
'ExternalRecordID' => true, |
|
30
|
|
|
'Result' => true, |
|
31
|
|
|
'Created' => true |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
35
|
|
|
'EmailReminder_NotificationSchedule' => 'EmailReminder_NotificationSchedule' |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
39
|
|
|
'Created.Nice' => 'When', |
|
40
|
|
|
'EmailTo' => 'Sent to', |
|
41
|
|
|
'Result.Nice' => 'Sent Succesfully', |
|
42
|
|
|
'IsTestOnly.Nice' => 'Test Only' |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
public static $default_sort = [ |
|
46
|
|
|
'Created' => 'DESC', |
|
47
|
|
|
'ID' => 'DESC' |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function canCreate($member = null) |
|
52
|
|
|
{ |
|
53
|
|
|
return false; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function canEdit($member = null) |
|
57
|
|
|
{ |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function canDelete($member = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* standard SS method. |
|
68
|
|
|
* |
|
69
|
|
|
* @return FieldList |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getCMSFields() |
|
72
|
|
|
{ |
|
73
|
|
|
$fields = parent::getCMSFields(); |
|
74
|
|
|
$fields->addFieldsToTab( |
|
75
|
|
|
'Root.Details', |
|
76
|
|
|
array( |
|
77
|
|
|
$fields->dataFieldByName("EmailTo"), |
|
78
|
|
|
$fields->dataFieldByName("ExternalRecordClassName"), |
|
79
|
|
|
$fields->dataFieldByName("ExternalRecordID"), |
|
80
|
|
|
$fields->dataFieldByName("Result"), |
|
81
|
|
|
$fields->dataFieldByName("IsTestOnly"), |
|
82
|
|
|
$fields->dataFieldByName("EmailReminder_NotificationScheduleID"), |
|
83
|
|
|
) |
|
84
|
|
|
); |
|
85
|
|
|
$fields->replaceField( |
|
86
|
|
|
'EmailContent', |
|
87
|
|
|
LiteralField::create( |
|
88
|
|
|
'EmailContent', |
|
89
|
|
|
$this->EmailContent |
|
|
|
|
|
|
90
|
|
|
) |
|
91
|
|
|
); |
|
92
|
|
|
return $fields; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* |
|
97
|
|
|
* tests to see if an email can be sent |
|
98
|
|
|
* the emails can only be sent once unless previous attempts have failed |
|
99
|
|
|
*/ |
|
100
|
|
|
public function canSendAgain() |
|
101
|
|
|
{ |
|
102
|
|
|
$send = true; |
|
103
|
|
|
if ($this->Result) { |
|
|
|
|
|
|
104
|
|
|
if ($this->IsTestOnly) { |
|
|
|
|
|
|
105
|
|
|
return true; |
|
106
|
|
|
} else { |
|
107
|
|
|
$send = false; |
|
108
|
|
|
$numberOfSecondsBeforeYouCanSendAgain = $this->EmailReminder_NotificationSchedule()->RepeatDays * 86400; |
|
|
|
|
|
|
109
|
|
|
$todaysTS = strtotime('NOW'); |
|
110
|
|
|
|
|
111
|
|
|
$creationTS = strtotime($this->Created); |
|
112
|
|
|
$difference = ($todaysTS - $creationTS); |
|
113
|
|
|
if ($difference > $numberOfSecondsBeforeYouCanSendAgain) { |
|
114
|
|
|
$send = true; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
return $send; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* |
|
123
|
|
|
* PartialMatchFilter |
|
124
|
|
|
*/ |
|
125
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
126
|
|
|
'EmailTo' => 'PartialMatchFilter', |
|
127
|
|
|
'Result' => 'ExactMatchFilter', |
|
128
|
|
|
'IsTestOnly' => 'ExactMatchFilter', |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* e.g. |
|
133
|
|
|
* $controller = singleton("MyModelAdmin"); |
|
134
|
|
|
* return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit"; |
|
135
|
|
|
*/ |
|
136
|
|
|
public function CMSEditLink() |
|
137
|
|
|
{ |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* returns list of fields as they are exported |
|
143
|
|
|
* @return array |
|
|
|
|
|
|
144
|
|
|
* Field => Label |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getExportFields() |
|
147
|
|
|
{ |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|