class-zcrm-custom-fields.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CommerceBird; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | use CMBIRD_API_Handler_Zoho; |
| 10 | |
| 11 | class ZCRM_Custom_Fields { |
| 12 | |
| 13 | /** |
| 14 | * create API Get call to Zoho CRM to get all custom fields |
| 15 | * |
| 16 | * @param module $module - module name |
| 17 | * @return array | \WP_Error |
| 18 | */ |
| 19 | public function cmbird_get_custom_fields( $module ) { |
| 20 | $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' ); |
| 21 | $url = $zoho_crm_url . 'crm/v6/settings/fields?module=' . $module; |
| 22 | $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho(); |
| 23 | $json = $execute_curl_call_handle->execute_curl_call_get( $url ); |
| 24 | if ( is_wp_error( $json ) ) { |
| 25 | return $json; |
| 26 | } else { |
| 27 | // Parse the response |
| 28 | $parsed_fields = array(); |
| 29 | |
| 30 | foreach ( $json->fields as $field ) { |
| 31 | $parsed_fields[] = array( |
| 32 | 'id' => $field->id, |
| 33 | 'apiName' => $field->api_name, |
| 34 | 'visible' => (bool) $field->visible, |
| 35 | 'fieldLabel' => $field->field_label, |
| 36 | 'displayLabel' => $field->display_label, |
| 37 | 'customField' => (bool) $field->custom_field, |
| 38 | 'dataType' => $field->data_type, |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | return $parsed_fields; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |