jetformbuilder
/
includes
/
integrations
/
active-campaign
/
api
/
retrieve-custom-fields-action.php
add-tag-to-contact.php
3 years ago
base-action.php
3 years ago
create-tag-action.php
3 years ago
list-all-tags.php
3 years ago
retrieve-custom-fields-action.php
3 years ago
retrieve-lists-action.php
3 years ago
sync-contact-action.php
3 years ago
update-list-status.php
3 years ago
retrieve-custom-fields-action.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Integrations\Active_Campaign\Api; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Classes\Arrayable\Arrayable; |
| 8 | |
| 9 | class Retrieve_Custom_Fields_Action extends Base_Action implements Arrayable { |
| 10 | |
| 11 | protected $method = \WP_REST_Server::READABLE; |
| 12 | |
| 13 | public function action_endpoint() { |
| 14 | return 'fields'; |
| 15 | } |
| 16 | |
| 17 | public function action_query_args(): array { |
| 18 | return array( |
| 19 | 'limit' => -1, |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | public function to_array(): array { |
| 24 | $response = array(); |
| 25 | |
| 26 | foreach ( $this->response_body['fields'] as $field ) { |
| 27 | $response[] = array( |
| 28 | 'value' => $field['id'], |
| 29 | 'label' => $field['title'], |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | return $response; |
| 34 | } |
| 35 | |
| 36 | public function get_field_id( string $key ): int { |
| 37 | foreach ( $this->response_body['fields'] as $field ) { |
| 38 | if ( $field['perstag'] !== $key ) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | return (int) $field['id']; |
| 43 | } |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | } |