| Total Complexity | 23 |
| Total Lines | 278 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 6 | class MySalesforceContactConfigApi extends Object |
||
| 7 | { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | private static $site_wide_fields_to_send_on_creation = []; |
||
|
1 ignored issue
–
show
|
|||
| 14 | |||
| 15 | /** |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | private static $site_wide_fields_to_send_on_update = []; |
||
|
1 ignored issue
–
show
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | private static $site_wide_filter_values = []; |
||
|
1 ignored issue
–
show
|
|||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private static $run_time_fields_to_send_on_creation = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * |
||
| 36 | * @param array|DataList|string $mixed fields to send |
||
| 37 | * |
||
| 38 | */ |
||
| 39 | public static function add_fields_to_send_on_creation($mixed) |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | private static $run_time_fields_to_send_on_update = []; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * |
||
| 54 | * @param array|DataList|string $mixed fields to send |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public static function add_fields_to_send_on_update($mixed) |
||
| 59 | { |
||
| 60 | $array = self::mixed_to_array($mixed); |
||
| 61 | |||
| 62 | self::$run_time_fields_to_send_on_update += $array; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | private static $run_time_fields_for_filter = []; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | * @param array|DataList|string $mixed fields to send |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public static function add_fields_to_use_for_filter($mixed) |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * |
||
| 87 | * @param array|DataList|null $mixed fields to send |
||
| 88 | * |
||
| 89 | * @return array |
||
| 90 | */ |
||
| 91 | public static function get_fields_to_send_on_creation($mixed = null) |
||
| 92 | { |
||
| 93 | $array = self::mixed_to_array($mixed); |
||
| 94 | return array_merge( |
||
| 95 | Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_creation'), |
||
|
1 ignored issue
–
show
|
|||
| 96 | $array, |
||
| 97 | self::$run_time_fields_to_send_on_creation |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * |
||
| 103 | * @param array|DataList|null $mixed fields to send |
||
| 104 | * |
||
| 105 | * @return array |
||
| 106 | */ |
||
| 107 | public static function get_fields_to_send_on_update($mixed = null) |
||
| 108 | { |
||
| 109 | $array = self::mixed_to_array($mixed); |
||
| 110 | |||
| 111 | return array_merge( |
||
| 112 | Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_update'), |
||
|
1 ignored issue
–
show
|
|||
| 113 | $array, |
||
| 114 | self::$run_time_fields_to_send_on_update |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * |
||
| 120 | * @param array|DataList|null $mixed fields to send |
||
| 121 | * |
||
| 122 | * @return array|DataList|null |
||
| 123 | */ |
||
| 124 | public static function get_fields_for_filter($mixed = null) |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * |
||
| 137 | * @param DataList|array|null $mixed |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | protected static function mixed_to_array($mixed = null) |
||
| 141 | { |
||
| 142 | if(is_object($mixed)) { |
||
| 143 | $array = []; |
||
| 144 | foreach($mixed as $object) { |
||
| 145 | $array[trim($object->Key)] = $object->BetterValueHumanReadable(); |
||
| 146 | } |
||
| 147 | } elseif($mixed === null) { |
||
| 148 | $array = []; |
||
| 149 | } elseif(is_string($mixed)) { |
||
| 150 | $array = [ $mixed ]; |
||
| 151 | } elseif(! is_array($array)) { |
||
| 152 | user_error('Variable '.vardump($mixed).'Should be an array'); |
||
| 153 | } |
||
| 154 | |||
| 155 | return $array; |
||
| 156 | } |
||
| 157 | |||
| 158 | public static function login_details_field( |
||
| 177 | ); |
||
| 178 | } |
||
| 179 | /** |
||
| 180 | * Field with list of contact record types shown |
||
| 181 | * @param string $fieldName |
||
| 182 | * @param string $title |
||
| 183 | * |
||
| 184 | * @return LiteralField |
||
| 185 | */ |
||
| 186 | public static function list_of_contact_record_types_field( |
||
| 187 | $fieldName = 'ListOfContactRecordTypes', |
||
| 188 | $title = 'Contact Record Types Available' |
||
| 189 | ) |
||
| 190 | { |
||
| 191 | $data = MySalesforceContactApi::retrieve_contact_record_types(); |
||
| 192 | |||
| 193 | return LiteralField::create( |
||
| 194 | 'ListOfContactRecordTypes', |
||
| 195 | '<h2>'.$title.'</h2>'. |
||
| 196 | '<pre>'.print_r($data, 1).'</pre>' |
||
| 197 | ); |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Needs to link to a many-many relationship (SalesforceDefaultContactFields) |
||
| 202 | * @param array $array fields to send |
||
| 203 | * |
||
| 204 | * @return CheckboxSetField |
||
| 205 | */ |
||
| 206 | public static function select_default_contact_fields_field($fieldName, $title, $desc = '') |
||
| 207 | { |
||
| 208 | $count = SalesforceDefaultContactField::get()->count(); |
||
| 209 | if($count === 0) { |
||
| 210 | return HiddenField::create( |
||
| 211 | $fieldName, |
||
| 212 | $title |
||
| 213 | ); |
||
| 214 | } |
||
| 215 | return CheckboxSetField::create( |
||
| 216 | $fieldName, |
||
| 217 | $title, |
||
| 218 | SalesforceDefaultContactField::get()->map()->toArray() |
||
| 219 | ) |
||
| 220 | ->setDescription(' |
||
| 221 | '.$desc.' |
||
| 222 | <br /> |
||
| 223 | You can |
||
| 224 | <a href="/admin/salesforceadmin/'.SalesforceDefaultContactField::class.'/">Add or Edit the options</a> |
||
| 225 | as required. Please change with care. |
||
| 226 | '); |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * |
||
| 231 | * @param array|DataList|null $array fields to send |
||
| 232 | * @param string $fieldName fields to send |
||
| 233 | * @param string $title fields to send |
||
| 234 | * |
||
| 235 | * @return LiteralField |
||
| 236 | */ |
||
| 237 | public static function fields_to_send_field( |
||
| 238 | $type, |
||
| 239 | $mixed = null, |
||
| 240 | $fieldName = 'FieldsToSendToSalesforce', |
||
| 241 | $title = 'Default Fields for' |
||
| 242 | ) |
||
| 243 | { |
||
| 244 | $fieldName .= ucfirst($type); |
||
| 245 | $title .= ' '.ucfirst($type); |
||
| 246 | |||
| 247 | switch( $type ) { |
||
| 248 | case 'create': |
||
| 249 | $array = self::get_fields_to_send_on_creation($mixed); |
||
| 250 | break; |
||
| 251 | case 'update': |
||
| 252 | $array = self::get_fields_to_send_on_update($mixed); |
||
| 253 | break; |
||
| 254 | case 'filter': |
||
| 255 | $array = self::get_fields_for_filter($mixed); |
||
| 256 | break; |
||
| 257 | default: |
||
| 258 | user_error('type needs to be create, update or filter - currently set to: '.$type); |
||
| 259 | break; |
||
| 260 | } |
||
| 261 | return LiteralField::create( |
||
| 262 | $fieldName, |
||
| 263 | '<h2>'.$title.'</h2>'. |
||
| 264 | self::array_to_html($array) |
||
| 265 | ); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * |
||
| 270 | * @param [type] $array [description] |
||
| 271 | * @return [type] [description] |
||
| 272 | */ |
||
| 273 | protected static function array_to_html($array) : string |
||
| 284 | } |
||
| 285 | } |
||
| 286 |