'radio', 'multi_options' => ( 'en' == FQP\FQP::get_curr_lang() ) ? [ 'Mr' => 'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs' ] : [ 'Herr' => 'Herr', 'Frau' => 'Frau' ], 'attribs' => [ 'required' => true ], ]; $fields['first_name'] = [ 'type' => 'text', 'label' => 'First Name', 'attribs' => [ 'required' => true, ], ]; $fields['last_name'] = [ 'type' => 'text', 'label' => 'Last Name', 'attribs' => [ 'required' => true, ], ]; $fields['street'] = [ 'type' => 'text', 'label' => 'Street', 'attribs' => [ 'required' => true, ] ]; $fields['zip'] = [ 'type' => 'text', 'label' => 'Zip', 'attribs' => [ 'required' => true, ], ]; $fields['city'] = [ 'type' => 'text', 'label' => 'City', 'attribs' => [ 'required' => true, ], ]; $fields['nationality'] = [ 'type' => 'select', 'label' => 'Nationality', 'multi_options' => FQP\DB::get_nationality(), 'attribs' => [ 'required' => true ], ]; $fields['birth_date'] = [ 'type' => 'date', 'label' => 'Birth date', 'attribs' => [ 'required' => true, 'placeholder' => ( 'de' == FQP\FQP::get_curr_lang() ) ? 'tt.mm.jjjj' : 'dd.mm.yyyy' ], ]; static::$fields['person'] = $fields; } protected static function init_function_in_company_fields() { $fields = []; if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG ] ) ) { $fields['vr_function_in_company'] = [ 'type' => 'select', 'label' => 'EN Funktion im Unternehmen', 'multi_options' => FQP\DB::get_vr_function_in_company(), 'description' => 'EN Die AG benötigt zwingend einen Aufsichtsrat und Vorstand.', 'attribs' => [ 'required' => true, ], ]; } if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_LTD, FQP\FQP::ENTRY_TYPE_COLLECTIVE_COMPANY ] ) ) { $fields['function_in_company'] = [ 'type' => 'select', 'label' => 'Function in the company', 'multi_options' => FQP\DB::get_function_in_company(), 'description' => static::get_function_in_company_description(), 'attribs' => [ 'required' => true, ], ]; } if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG, FQP\FQP::ENTRY_TYPE_LTD, FQP\FQP::ENTRY_TYPE_COLLECTIVE_COMPANY ] ) ) { $fields['signature_authorization'] = [ 'type' => 'select', 'label' => 'EN Zeichnungsberechtigung', 'multi_options' => FQP\DB::get_signature_authorization(), 'attribs' => [ 'required' => true, ], ]; } static::$fields['function_in_company'] = $fields; } public static function get_fields( $type = 'person' ) { if ( empty( static::$fields[$type] ) ) { $method = "init_{$type}_fields"; if ( ! method_exists( __CLASS__, $method )) { return false; } static::{$method}(); } return static::$fields[$type]; } public static function sanitize_data( &$data ) { if ( !is_array( $data ) ) { $data = []; } $errors = []; $required_msg = fqp__( '%s is required' ); $wrong_fmt_mgs = fqp__( '%s is in wrong format' ); $fields = static::get_fields( $data['person_type'] ); if ( $fields ) { foreach ( $fields as $name => $specs ) { if ( @$specs['attribs']['required'] && empty( $data[$name] ) ) { $title = ( ! empty( $specs['label'] ) ) ? $specs['label'] : $specs['attribs']['placeholder']; $errors[] = esc_html( sprintf( $required_msg, fqp__( $title ) ) ); } } } else { $errors[] = 'Unknown person type!'; } if ( ! preg_match( '/^\d{1,2}\.\d{1,2}\.\d{4}$/', $data['birth_date'] ) ) { $errors[] = esc_html( sprintf( $wrong_fmt_mgs, fqp__( 'Birth date' ) ) ); } return ( empty( $errors ) ) ? true : $errors; } public static function get_filter_fields() { return []; } public static function filter_data( &$data ) { $fields['person'] = static::get_fields( 'person' ) + static::get_fields( 'function_in_company' ); $filtered = []; foreach ( array_keys( $fields ) as $type ) { if ( ! empty( $data[$type] ) ) { foreach ( $data[$type] as $person_id => $person) { foreach ( array_keys( $fields[$type] ) as $field ) { $filtered[$type][$person_id][$field] = fqp_array_get( $person, $field ); } } } } $data = $filtered; } }