|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* this can be linked to pages / other objects using many_many relationships |
|
5
|
|
|
* so that you can send default record values to Salesforce |
|
6
|
|
|
*/ |
|
7
|
|
|
class SalesForceDefaultContactField extends DataObject |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @param array $array fields to send |
|
13
|
|
|
* |
|
14
|
|
|
* @return LiteralField |
|
15
|
|
|
*/ |
|
16
|
|
|
public static function field_showing_fields_to_send($array) |
|
17
|
|
|
{ |
|
18
|
|
|
$htmlArray = []; |
|
19
|
|
|
foreach($array as $field => $value) { |
|
20
|
|
|
$htmlArray[] = $field.' = '.$value.' ('.gettype($value).')'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
return LiteralField::create( |
|
24
|
|
|
'FieldsToSendToSalesforce', |
|
25
|
|
|
'<h2>Fields Added:</h2><p>'.implode('</p><p>', $htmlArray).'</p>' |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private static $db = [ |
|
|
|
|
|
|
34
|
|
|
'Key' => 'Varchar', |
|
35
|
|
|
'Value' => 'Varchar' |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Defines summary fields commonly used in table columns |
|
40
|
|
|
* as a quick overview of the data for this dataobject |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
44
|
|
|
'Key' => 'Field Name', |
|
45
|
|
|
'Value' => 'Field Value' |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getTitle() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->Key . ' - '.$this->Value; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* contact fields that should be created by default... |
|
59
|
|
|
* @var array |
|
60
|
|
|
*/ |
|
61
|
|
|
private static $defaults_records = []; |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function requireDefaultRecords() |
|
64
|
|
|
{ |
|
65
|
|
|
foreach($this->Config()->get('default_records') as $key => $value) { |
|
66
|
|
|
$filter = [ |
|
67
|
|
|
'Key' => $key |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
$obj = SalesForceDefaultContactField::get()->filter($filter)->first(); |
|
71
|
|
|
if(! $obj) { |
|
72
|
|
|
$obj->create($filter); |
|
73
|
|
|
$obj->Value = $value; |
|
74
|
|
|
$obj->write(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
|
|
public function BetterValue() |
|
84
|
|
|
{ |
|
85
|
|
|
if(strtolower($this->Value) === 'true') { |
|
86
|
|
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
if(strtolower($this->Value) === 'false') { |
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
if(floatval($this->Value)) { |
|
92
|
|
|
return floatval($this->Value); |
|
93
|
|
|
} |
|
94
|
|
|
if(intval($this->Value)) { |
|
95
|
|
|
return intval($this->Value); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|