|
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
|
|
|
* contact fields that should be created by default... |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
private static $defaults_records = []; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Singular name for CMS |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private static $singular_name = 'Default Contact Field'; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Plural name for CMS |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private static $plural_name = 'Default Contact Fields'; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
private static $db = [ |
|
|
|
|
|
|
33
|
|
|
'Key' => 'Varchar', |
|
34
|
|
|
'Value' => 'Varchar', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Defines summary fields commonly used in table columns |
|
39
|
|
|
* as a quick overview of the data for this dataobject |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
43
|
|
|
'Key' => 'Field Name', |
|
44
|
|
|
'Value' => 'Field Value', |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getTitle() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->Key . ' = '.$this->BetterValueHumanReadable(); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function requireDefaultRecords() |
|
58
|
|
|
{ |
|
59
|
|
|
foreach($this->Config()->get('default_records') as $key => $value) { |
|
60
|
|
|
$filter = [ |
|
61
|
|
|
'Key' => $key |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
$obj = SalesforceDefaultContactField::get()->filter($filter)->first(); |
|
65
|
|
|
if(! $obj) { |
|
66
|
|
|
$obj = SalesforceDefaultContactField::create($filter); |
|
67
|
|
|
$obj->Value = $value; |
|
68
|
|
|
$obj->write(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function BetterValue() |
|
78
|
|
|
{ |
|
79
|
|
|
if(strtolower($this->Value) === 'true' || intval($this->Value) === 1) { |
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
elseif(strtolower($this->Value) === 'false' || empty($this->Value) || intval($this->Value) === 0) { |
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
elseif(is_numeric($this->Value)) { |
|
86
|
|
|
return floatval($this->Value); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return trim($this->Value); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function BetterValueHumanReadable() |
|
93
|
|
|
{ |
|
94
|
|
|
$value = $this->BetterValue(); |
|
95
|
|
|
if(gettype($value) === 'boolean') { |
|
96
|
|
|
return $value ? 'true' : 'false'; |
|
97
|
|
|
} else { |
|
98
|
|
|
return $value; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|