Total Complexity | 16 |
Total Lines | 149 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 = []; |
||
1 ignored issue
–
show
|
|||
15 | |||
16 | private static $site_wide_fields_to_send = []; |
||
1 ignored issue
–
show
|
|||
17 | |||
18 | private static $site_wide_filter_values = []; |
||
1 ignored issue
–
show
|
|||
19 | |||
20 | /** |
||
21 | * |
||
22 | * @param array|DataList|null $mixed fields to send |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | public static function get_fields_to_send($mixed = null) |
||
27 | { |
||
28 | $array = self::mixed_to_array($mixed); |
||
29 | |||
30 | return array_merge( |
||
31 | Config::inst()->get('SalesforceDefaultContactField', 'site_wide_fields_to_send'), |
||
32 | $array |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @param array|DataList|null $mixed fields to send |
||
39 | * |
||
40 | * @return array|DataList|null |
||
41 | */ |
||
42 | public static function get_fields_for_filter($mixed = null) |
||
43 | { |
||
44 | $array = self::mixed_to_array($mixed); |
||
45 | |||
46 | return array_merge( |
||
47 | Config::inst()->get('SalesforceDefaultContactField', 'site_wide_filter_values'), |
||
48 | $array |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Singular name for CMS |
||
54 | * @var string |
||
55 | */ |
||
56 | private static $singular_name = 'Default Contact Field'; |
||
1 ignored issue
–
show
|
|||
57 | |||
58 | /** |
||
59 | * Plural name for CMS |
||
60 | * @var string |
||
61 | */ |
||
62 | private static $plural_name = 'Default Contact Fields'; |
||
1 ignored issue
–
show
|
|||
63 | |||
64 | /** |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | private static $db = [ |
||
1 ignored issue
–
show
|
|||
69 | 'Key' => 'Varchar', |
||
70 | 'Value' => 'Varchar', |
||
71 | 'IsFilter' => 'Boolean', |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * Defines summary fields commonly used in table columns |
||
76 | * as a quick overview of the data for this dataobject |
||
77 | * @var array |
||
78 | */ |
||
79 | private static $summary_fields = [ |
||
1 ignored issue
–
show
|
|||
80 | 'Key' => 'Field Name', |
||
81 | 'Value' => 'Field Value', |
||
82 | 'IsFilter.Nice' => 'Is Filter', |
||
83 | ]; |
||
84 | |||
85 | /** |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getTitle() |
||
92 | } |
||
93 | |||
94 | |||
95 | public function requireDefaultRecords() |
||
96 | { |
||
97 | foreach($this->Config()->get('default_records') as $key => $value) { |
||
98 | $filter = [ |
||
99 | 'Key' => $key |
||
100 | ]; |
||
101 | |||
102 | $obj = SalesforceDefaultContactField::get()->filter($filter)->first(); |
||
103 | if(! $obj) { |
||
104 | $obj = SalesforceDefaultContactField::create($filter); |
||
105 | $obj->Value = $value; |
||
106 | $obj->write(); |
||
107 | } |
||
108 | |||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return mixed |
||
114 | */ |
||
115 | public function BetterValue() |
||
116 | { |
||
117 | if(strtolower($this->Value) === 'true') { |
||
118 | return true; |
||
119 | } |
||
120 | if(strtolower($this->Value) === 'false') { |
||
121 | return false; |
||
122 | } |
||
123 | if(floatval($this->Value)) { |
||
124 | return floatval($this->Value); |
||
125 | } |
||
126 | if(intval($this->Value)) { |
||
127 | return intval($this->Value); |
||
128 | } |
||
129 | |||
130 | return trim($this->Value); |
||
131 | } |
||
132 | |||
133 | |||
134 | /** |
||
135 | * |
||
136 | * @param DataList|array|null $mixed |
||
137 | * @return array |
||
138 | */ |
||
139 | protected static function mixed_to_array($mixed = null) : array |
||
156 | } |
||
157 | |||
158 | |||
159 | |||
160 | |||
162 |