|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class CountryPrice_Translation extends DataObject |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
private static $db = array( |
|
|
|
|
|
|
8
|
|
|
'Title' => 'Varchar(200)', |
|
9
|
|
|
'Content' => 'HTMLText', |
|
10
|
|
|
'WithoutTranslation' => 'Boolean' |
|
11
|
|
|
); |
|
12
|
|
|
|
|
13
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
14
|
|
|
'Title' => 'Page Title', |
|
15
|
|
|
'Content' => 'Page Content', |
|
16
|
|
|
'EcommerceCountryID' => 'Country', |
|
17
|
|
|
'WithoutTranslation' => 'Without Translation' |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
21
|
|
|
'EcommerceCountry' => 'EcommerceCountry', |
|
22
|
|
|
'Parent' => 'SiteTree' |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
26
|
|
|
'EcommerceCountry.Name' => 'Country', |
|
27
|
|
|
'Title' => 'Title', |
|
28
|
|
|
'WithoutTranslation.Nice' => 'Price Difference Only' |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $locale_get_parameter = 'ecomlocale'; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Standard SS variable. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private static $singular_name = 'Translation'; |
|
|
|
|
|
|
42
|
|
|
public function i18n_singular_name() |
|
43
|
|
|
{ |
|
44
|
|
|
return self::$singular_name; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Standard SS variable. |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $plural_name = 'Translations'; |
|
|
|
|
|
|
53
|
|
|
public function i18n_plural_name() |
|
54
|
|
|
{ |
|
55
|
|
|
return self::$plural_name; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* CMS Fields |
|
60
|
|
|
* @return FieldList |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getCMSFields() |
|
63
|
|
|
{ |
|
64
|
|
|
$fields = parent::getCMSFields(); |
|
65
|
|
|
$countries = CountryPrice_EcommerceCountry::get_real_countries_list()->map()->toArray(); |
|
66
|
|
|
$fields->addFieldToTab( |
|
67
|
|
|
'Root.Main', |
|
68
|
|
|
DropdownField::create( |
|
69
|
|
|
'EcommerceCountryID', |
|
70
|
|
|
$fields->dataFieldByName('EcommerceCountryID')->Title(), |
|
71
|
|
|
array('' => '-- make sure to select a country --')+$countries |
|
72
|
|
|
), |
|
73
|
|
|
'Title' |
|
74
|
|
|
); |
|
75
|
|
|
$withoutTranslationField = $fields->dataFieldByName('WithoutTranslation'); |
|
76
|
|
|
$fields->addFieldToTab( |
|
77
|
|
|
'Root.Main', |
|
78
|
|
|
CheckboxField::create( |
|
79
|
|
|
'WithoutTranslation', |
|
80
|
|
|
$withoutTranslationField->Title() |
|
81
|
|
|
)->setRightTitle('The page is <em>translated</em> for search engines because it has prices for this country. '), |
|
82
|
|
|
'Title' |
|
83
|
|
|
); |
|
84
|
|
|
$fields->removeFieldFromTab("Root.Main", 'ParentID'); |
|
85
|
|
|
return $fields; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function canCreate($member = null) |
|
89
|
|
|
{ |
|
90
|
|
|
if (CountryPrice_EcommerceCountry::get_real_countries_list()->count()) { |
|
91
|
|
|
return parent::canCreate($member); |
|
92
|
|
|
} |
|
93
|
|
|
return false; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function validate() |
|
100
|
|
|
{ |
|
101
|
|
|
$validation = parent::validate(); |
|
102
|
|
|
if ($validation->valid()) { |
|
103
|
|
|
if ($this->exists()) { |
|
104
|
|
|
$existing = CountryPrice_Translation::get() |
|
105
|
|
|
->exclude(array("ID" => $this->ID)) |
|
106
|
|
|
->filter( |
|
107
|
|
|
array( |
|
108
|
|
|
"EcommerceCountryID" => $this->EcommerceCountryID, |
|
|
|
|
|
|
109
|
|
|
"ParentID" => $this->ParentID |
|
|
|
|
|
|
110
|
|
|
) |
|
111
|
|
|
); |
|
112
|
|
|
if ($existing->count() > 0) { |
|
113
|
|
|
$validation->error( |
|
114
|
|
|
'There is already an entry for this country and page' |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
return $validation; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* 'PageField' => 'Title' |
|
124
|
|
|
* 'TranslationField' => 'Title' |
|
125
|
|
|
* |
|
126
|
|
|
* @return ArrayList |
|
127
|
|
|
*/ |
|
128
|
|
|
public function FieldsToReplace() |
|
129
|
|
|
{ |
|
130
|
|
|
$al = ArrayList::create(); |
|
131
|
|
|
$al->push( |
|
132
|
|
|
ArrayData::create( |
|
133
|
|
|
array( |
|
134
|
|
|
'PageField' => 'Title', |
|
135
|
|
|
'TranslationField' => 'Title' |
|
136
|
|
|
) |
|
137
|
|
|
) |
|
138
|
|
|
); |
|
139
|
|
|
$al->push( |
|
140
|
|
|
ArrayData::create( |
|
141
|
|
|
array( |
|
142
|
|
|
'PageField' => 'Content', |
|
143
|
|
|
'TranslationField' => 'Content' |
|
144
|
|
|
) |
|
145
|
|
|
) |
|
146
|
|
|
); |
|
147
|
|
|
$this->extend('updateFieldsToReplace', $al); |
|
148
|
|
|
return $al; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
function Link() |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$link = $this->Parent()->Link(); |
|
|
|
|
|
|
154
|
|
|
if($this->EcommerceCountryID) { |
|
|
|
|
|
|
155
|
|
|
$link .= '?'.$this->Config()->get('locale_get_parameter').'='.$this->EcommerceCountry()->Code; |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
return $link; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
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.