1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DMSDocumentCartSubmission extends DataObject |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $db = array( |
|
|
|
|
6
|
|
|
'ReceiverName' => 'Varchar(100)', |
7
|
|
|
'ReceiverPhone' => 'Varchar(20)', |
8
|
|
|
'ReceiverEmail' => 'Varchar(254)', |
9
|
|
|
'DeliveryAddressLine1' => 'Varchar(200)', |
10
|
|
|
'DeliveryAddressLine2' => 'Varchar(200)', |
11
|
|
|
'DeliveryAddressCountry' => 'Varchar(50)', |
12
|
|
|
'DeliveryAddressPostCode' => 'Varchar(20)', |
13
|
|
|
'CreatedAt' => 'Datetime', |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
private static $has_many = array( |
|
|
|
|
17
|
|
|
'Items' => 'DMSDocumentCartSubmissionItem', |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
private static $summary_fields = array( |
|
|
|
|
21
|
|
|
'ReceiverName' => 'Receiver Name', |
22
|
|
|
'ReceiverPhone' => 'Receiver Phone', |
23
|
|
|
'ReceiverEmail' => 'Receiver Email', |
24
|
|
|
'Items.Count' => 'No. Items', |
25
|
|
|
'CreatedAt.Nice' => 'Created At' |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
private static $singular_name = 'Cart Submission'; |
|
|
|
|
29
|
|
|
private static $plural_name = 'Cart Submissions'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Removing the add and existing GridField components to ensure that the model admin for submissions doesn't |
33
|
|
|
* let you add new records |
34
|
|
|
* |
35
|
|
|
* @return FieldList |
36
|
|
|
*/ |
37
|
|
|
public function getCMSFields() |
38
|
|
|
{ |
39
|
|
|
// PHP 5.3 support |
40
|
|
|
$self = $this; |
41
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) { |
42
|
|
|
$fields->addFieldToTab( |
43
|
|
|
'Root.Main', |
44
|
|
|
$fields->fieldByName('Root.Main.CreatedAt')->performReadonlyTransformation() |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$gridField = GridField::create('Items', null, $self->Items(), $config = new GridFieldConfig_RecordEditor); |
|
|
|
|
48
|
|
|
$fields->addFieldToTab('Root.Items', $gridField); |
49
|
|
|
|
50
|
|
|
foreach (array('GridFieldAddExistingAutocompleter', 'GridFieldAddNewButton') as $component) { |
51
|
|
|
$config->removeComponentsByType($component); |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
return parent::getCMSFields(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set the created at datetime if it hasn't been set already |
59
|
|
|
*/ |
60
|
|
|
public function onBeforeWrite() |
61
|
|
|
{ |
62
|
|
|
if (!$this->CreatedAt) { |
|
|
|
|
63
|
|
|
$this->CreatedAt = SS_Datetime::now(); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
return parent::onBeforeWrite(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.