Commit 214602c1 authored by Rodrigo's avatar Rodrigo
Browse files

Add Form Parameter class to make the customization of slugs easier.

parent 5aca756b
......@@ -7,7 +7,7 @@
* @package Gen_Registration_Tracker
* @subpackage Gen_Registration_Tracker/includes
*/
require_once plugin_dir_path( __FILE__ ) . 'class-gen-form-parameters.php';
/**
* The Class that fetches data from Caldera Forms API and arrang it in the Model classes.
*
......@@ -79,6 +79,7 @@ class Gen_Caldera_Forms_Data_Collector {
$this->error_list = new WP_Error();
$this->all_registrants = self::get_registrants_from_form( $form_id );
}
/** Function that uses Caldera Forms API methods to fetch entries from a specific form.
*
* @since 1.0.0
......@@ -135,23 +136,14 @@ class Gen_Caldera_Forms_Data_Collector {
$delegates = [];
$children = [];
if ( isset( $registration['id'] ) ) {
$registration_id = $registration['id'];
if ( isset( $registration[ Gen_Form_Parameters::ID ] ) ) {
$registration_id = $registration[ Gen_Form_Parameters::ID ];
} else {
$this->error_list->add( 'registration_id', 'Registration has no valid id.' );
}
$registrant_transportation_index = 'how_do_you_plan_to_travel_to_the_conference';
$registrant_general_assembly_accommodation_index = 'accommodation_during_the_general_assembly';
$registrant_conference_accommodation_index = 'accommodation_during_the_conference';
$registrant_pos_conference_accommodation_index = 'accommodation_during_the_rive_gathering';
$arrival_date_index = 'arrival_date';
$departure_date_index = 'departure_date';
$accommodation_price_index = 'total_accommodation_price';
$meals_price_index = 'total_meals_price';
if ( isset( $registration['how_many_people_would_you_like_to_register'] ) ) {
$number_of_registrants = $registration['how_many_people_would_you_like_to_register'];
if ( isset( $registration[ Gen_Form_Parameters::NUMBER_OF_PEOPLE ] ) ) {
$number_of_registrants = $registration[ Gen_Form_Parameters::NUMBER_OF_PEOPLE ];
} else {
$this->error_list->add( 'number_of_registrants', 'Number of registrants for the registration ' . esc_html( $registration_id ) . ' has not been defined.' );
return;
......@@ -160,55 +152,71 @@ class Gen_Caldera_Forms_Data_Collector {
// This block identifies fields that has different values for each registrant inside a registration entry.
switch ( $registrant_number ) {
case 1:
$registrant_name_index = 'full_name';
$registrant_age_index = 'age';
$registrant_diet_index = 'please_select_the_diets_that_are_relevant_for_you';
$registration_type_index = 'i_am_a';
$registration_price_index = '_price';
$registrant_name_index = Gen_Form_Parameters::NAME_FIRST;
$registrant_age_index = Gen_Form_Parameters::AGE_FIRST;
$registrant_diet_index = Gen_Form_Parameters::DIET_FIRST;
$registration_type_index = Gen_Form_Parameters::REGISTRATION_TYPE_FIRST;
$delegate_price_index = Gen_Form_Parameters::DELEGATE_REGISTRATION_PRICE_FIRST;
$attendee_price_index = Gen_Form_Parameters::ATTENDEE_REGISTRATION_PRICE_FIRST;
break;
case 2:
$registrant_name_index = 'full_name_second_person';
$registrant_age_index = 'age_second_person';
$registrant_diet_index = 'please_select_the_diets_that_are_relevant_for_the_second_registrant';
$registration_type_index = 'the_second_registrant_is_a';
$registration_price_index = '_price_second_person';
$registrant_name_index = Gen_Form_Parameters::NAME_SECOND;
$registrant_age_index = Gen_Form_Parameters::AGE_SECOND;
$registrant_diet_index = Gen_Form_Parameters::DIET_SECOND;
$registration_type_index = Gen_Form_Parameters::REGISTRATION_TYPE_SECOND;
$delegate_price_index = Gen_Form_Parameters::DELEGATE_REGISTRATION_PRICE_SECOND;
$attendee_price_index = Gen_Form_Parameters::ATTENDEE_REGISTRATION_PRICE_SECOND;
break;
case 3:
$registrant_name_index = 'full_name_third_person';
$registrant_age_index = 'age_third_person';
$registrant_diet_index = 'please_select_the_diets_that_are_relevant_for_the_third_registrant';
$registration_type_index = 'the_third_registrant_is_a';
$registration_price_index = '_price_third_person';
$registrant_name_index = Gen_Form_Parameters::NAME_THIRD;
$registrant_age_index = Gen_Form_Parameters::AGE_THIRD;
$registrant_diet_index = Gen_Form_Parameters::DIET_THIRD;
$registration_type_index = Gen_Form_Parameters::REGISTRATION_TYPE_THIRD;
$delegate_price_index = Gen_Form_Parameters::DELEGATE_REGISTRATION_PRICE_THIRD;
$attendee_price_index = Gen_Form_Parameters::ATTENDEE_REGISTRATION_PRICE_THIRD;
break;
case 4:
$registrant_name_index = 'full_name_fourth_person';
$registrant_age_index = 'age_fourth_person';
$registrant_diet_index = 'please_select_the_diets_that_are_relevant_for_the_fourth_registrant';
$registration_type_index = 'the_fourth_registrant_is_a';
$registration_price_index = '_price_fourth_person';
$registrant_name_index = Gen_Form_Parameters::NAME_FOURTH;
$registrant_age_index = Gen_Form_Parameters::AGE_FOURTH;
$registrant_diet_index = Gen_Form_Parameters::DIET_FOURTH;
$registration_type_index = Gen_Form_Parameters::REGISTRATION_TYPE_FOURTH;
$delegate_price_index = Gen_Form_Parameters::DELEGATE_REGISTRATION_PRICE_FOURTH;
$attendee_price_index = Gen_Form_Parameters::ATTENDEE_REGISTRATION_PRICE_FOURTH;
break;
case 5:
$registrant_name_index = 'full_name_fifth_person';
$registrant_age_index = 'age_fifth_person';
$registrant_diet_index = 'please_select_the_diets_that_are_relevant_for_the_fifth_registrant';
$registration_type_index = 'the_fifth_registrant_is_a';
$registration_price_index = '_price_fifth_person';
$registrant_name_index = Gen_Form_Parameters::NAME_FIFTH;
$registrant_age_index = Gen_Form_Parameters::AGE_FIFTH;
$registrant_diet_index = Gen_Form_Parameters::DIET_FIFTH;
$registration_type_index = Gen_Form_Parameters::REGISTRATION_TYPE_FIFTH;
$delegate_price_index = Gen_Form_Parameters::DELEGATE_REGISTRATION_PRICE_FIFTH;
$attendee_price_index = Gen_Form_Parameters::ATTENDEE_REGISTRATION_PRICE_FIFTH;
break;
default:
$this->error_list->add( 'number_of_registrants', self::class . ': Number of registrants for the registration ' . esc_html( $registration_id ) . ' has a value out of the range 1-5 = : ' . esc_html( $number_of_registrants ) );
return;
}
/**
* The following block fetches the information from the data source array.
*/
/**
* Registrant Name
*/
if ( isset( $registration[ $registrant_name_index ] ) ) {
$registrant_name = $registration[ $registrant_name_index ];
} else {
$this->error_list->add( 'registrant_name', self::class . ': One registrant name for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
/**
* Registrant Age
*/
if ( isset( $registration[ $registrant_age_index ] ) ) {
$registrant_age = $registration[ $registrant_age_index ];
} else {
$this->error_list->add( 'registrant_age', self::class . ': One registrant age for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
/**
* Registrant Diet
*/
if ( isset( $registration[ $registrant_diet_index ] ) ) {
$registrant_diet = $registration[ $registrant_diet_index ];
$types = explode( ',', $registrant_diet );
......@@ -224,22 +232,27 @@ class Gen_Caldera_Forms_Data_Collector {
array_push( $this->diet_types, 'No preferences' );
}
}
/**
* Registration Type
*/
if ( $registrant_age < Gen_Enum::MIN_YOUTHS_AGE ) {
$registration_type = Gen_Kid::REGISTRATION_TYPE;
$registration_price = Gen_Enum::KIDS_REGISTRATION_PRICE;
} elseif ( isset( $registration[ $registration_type_index ] ) ) {
$registration_type = $registration[ $registration_type_index ];
/**
* Registration Price
*/
if ( strpos( $registration_type, Gen_Delegate::REGISTRATION_TYPE ) !== false ) {
$registration_price_index = 'delegate' . $registration_price_index;
} else {
$registration_price_index = 'attendee' . $registration_price_index;
}
if ( isset( $registration[ $registration_price_index ] ) ) {
$registration_price = $registration[ $registration_price_index ];
if ( isset( $registration[ $delegate_price_index ] ) ) {
$registration_price = $registration[ $delegate_price_index ];
} else {
Gen_Utility::print_alert( 'Delegate price for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
$registration_price = 0;
}
} else {
if ( strpos( $registration_type, Gen_Delegate::REGISTRATION_TYPE ) !== false ) {
Gen_Utility::print_alert( 'Delegate price for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
$registration_price = 0;
if ( isset( $registration[ $attendee_price_index ] ) ) {
$registration_price = $registration[ $attendee_price_index ];
} else {
$this->error_list->add( 'registration_price', self::class . ': Registration price with slug (' . esc_html( $registration_price_index ) . ') for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
......@@ -247,45 +260,51 @@ class Gen_Caldera_Forms_Data_Collector {
} else {
$this->error_list->add( 'registrant_type', self::class . ': One registrant type for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
if ( isset( $registration[ $registrant_transportation_index ] ) ) {
$transportation = $registration[ $registrant_transportation_index ];
/**
* Transportation
*/
if ( isset( $registration[ Gen_Form_Parameters::TRANSPORTATION ] ) ) {
$transportation = $registration[ Gen_Form_Parameters::TRANSPORTATION ];
}
if ( isset( $registration[ $accommodation_price_index ] ) ) {
$accommodation_price = $registration[ $accommodation_price_index ] / $number_of_registrants;
/**
* Accommodation Price
*/
if ( isset( $registration[ Gen_Form_Parameters::ACCOMMODATION_PRICE ] ) ) {
$accommodation_price = $registration[ Gen_Form_Parameters::ACCOMMODATION_PRICE ] / $number_of_registrants;
} else {
$this->error_list->add( 'accommodation_price', self::class . ': Accommodation price for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
if ( isset( $registration[ $meals_price_index ] ) ) {
$meals_price = $registration[ $meals_price_index ] / $number_of_registrants;
/**
* Meals Price
*/
if ( isset( $registration[ Gen_Form_Parameters::MEALS_PRICE ] ) ) {
$meals_price = $registration[ Gen_Form_Parameters::MEALS_PRICE ] / $number_of_registrants;
} else {
$this->error_list->add( 'meals_price', self::class . ': Meals price for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
if ( isset( $registration[ $accommodation_price_index ] ) ) {
$accommodation_price = $registration[ $accommodation_price_index ] / $number_of_registrants;
} else {
$this->error_list->add( 'accommodation_price', self::class . ': Accommodation price for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
/**
* Accommodation Type
*/
$accommodation = [];
if ( isset( $registration[ $registrant_general_assembly_accommodation_index ] ) ) {
$accommodation['General Assembly'] = $registration[ $registrant_general_assembly_accommodation_index ];
if ( isset( $registration[ Gen_Form_Parameters::GA_ACCOMMODATION ] ) ) {
$accommodation['General Assembly'] = $registration[ Gen_Form_Parameters::GA_ACCOMMODATION ];
}
if ( isset( $registration[ $registrant_conference_accommodation_index ] ) ) {
$accommodation['Conference'] = $registration[ $registrant_conference_accommodation_index ];
if ( isset( $registration[ Gen_Form_Parameters::CONFERENCE_ACCOMMODATION ] ) ) {
$accommodation['Conference'] = $registration[ Gen_Form_Parameters::CONFERENCE_ACCOMMODATION ];
}
if ( isset( $registration[ $registrant_pos_conference_accommodation_index ] ) ) {
$accommodation['National Gathering'] = $registration[ $registrant_pos_conference_accommodation_index ];
if ( isset( $registration[ Gen_Form_Parameters::ADDITIONAL_ACCOMMODATION ] ) ) {
$accommodation['National Gathering'] = $registration[ Gen_Form_Parameters::ADDITIONAL_ACCOMMODATION ];
}
$arrival = DateTime::createFromFormat( 'd/m/Y', $registration[ $arrival_date_index ] );
$departure = DateTime::createFromFormat( 'd/m/Y', $registration[ $departure_date_index ] );
if ( isset( $registration['country'] ) ) {
$country = $registration['country'];
/**
* Dates
*/
$arrival = DateTime::createFromFormat( 'd/m/Y', $registration[ Gen_Form_Parameters::ARRIVAL_DATE ] );
$departure = DateTime::createFromFormat( 'd/m/Y', $registration[ Gen_Form_Parameters::DEPARTURE_DATE ] );
/**
* Country
*/
if ( isset( $registration[ Gen_Form_Parameters::COUNTRY ] ) ) {
$country = $registration[ Gen_Form_Parameters::COUNTRY ];
} else {
$this->error_list->add( 'registrant_country', self::class . ': The country for registration ' . esc_html( $registration_id ) . ' has not been defined.' );
}
......@@ -299,10 +318,10 @@ class Gen_Caldera_Forms_Data_Collector {
array_push( $attendees, new Gen_Attendee( $registration_id, $registrant_age, $transportation, $accommodation, $arrival, $departure, $registrant_diet, $country, $registrant_name, $registration_price, $accommodation_price, $meals_price ) );
break;
case 'Delegate':
if ( ! isset( $registration['please_enter_the_name_of_the_community__national_network_you_are_a_delegate_for'] ) ) {
if ( ! isset( $registration[ Gen_Form_Parameters::ORGANISATION ] ) ) {
$organization = 'Organization not specified';
} else {
$organization = $registration['please_enter_the_name_of_the_community__national_network_you_are_a_delegate_for'];
$organization = $registration[ Gen_Form_Parameters::ORGANISATION ];
}
array_push(
......
......@@ -19,10 +19,10 @@
*/
abstract class Gen_Enum {
/**
* Maximun age for a person to be considered a youth.
*
* @since 1.0.1
*/
* Maximun age for a person to be considered a youth.
*
* @since 1.0.1
*/
const MAX_YOUTHS_AGE = 25;
/**
* Minimun age for a person to be considered a youth.
......@@ -31,9 +31,9 @@ abstract class Gen_Enum {
*/
const MIN_YOUTHS_AGE = 13;
/**
* Registration price for Kids.
*
* @since 1.0.1
*/
* Registration price for Kids.
*
* @since 1.0.1
*/
const KIDS_REGISTRATION_PRICE = 0;
}
<?php
/**
* The file that defines a class with parameters to be associated with form slugs.
*
* @since 1.0.1
*
* @package Gen_Registration_Tracker
* @subpackage Gen_Registration_Tracker/includes
*/
/**
* The Utility class.
*
* This class implements parameters to be associated with form slugs.
* The main customization to make this plugin able to work with different events form should be made here.
*
* @since 1.0.1
* @package Gen_Registration_Tracker
* @subpackage Gen_Registration_Tracker/includes
*/
abstract class Gen_Form_Parameters {
const ID = 'id';
const TRANSPORTATION = 'how_do_you_plan_to_travel_to_the_conference';
const GA_ACCOMMODATION = 'accommodation_during_the_general_assembly';
const CONFERENCE_ACCOMMODATION = 'accommodation_during_the_conference';
const ADDITIONAL_ACCOMMODATION = 'accommodation_during_the_rive_gathering';
const ARRIVAL_DATE = 'arrival_date';
const DEPARTURE_DATE = 'departure_date';
const ACCOMMODATION_PRICE = 'total_accommodation_price';
const MEALS_PRICE = 'total_meals_price';
const NUMBER_OF_PEOPLE = 'how_many_people_would_you_like_to_register';
const COUNTRY = 'country';
/**
* Name
*/
const NAME_FIRST = 'full_name';
const NAME_SECOND = 'full_name_second_person';
const NAME_THIRD = 'full_name_third_person';
const NAME_FOURTH = 'full_name_fourth_person';
const NAME_FIFTH = 'full_name_fifth_person';
/**
* Age
*/
const AGE_FIRST = 'age';
const AGE_SECOND = 'age_second_person';
const AGE_THIRD = 'age_third_person';
const AGE_FOURTH = 'age_fourth_person';
const AGE_FIFTH = 'age_fifth_person';
/**
* Diet
*/
const DIET_FIRST = 'please_select_the_diets_that_are_relevant_for_you';
const DIET_SECOND = 'please_select_the_diets_that_are_relevant_for_the_second_registrant';
const DIET_THIRD = 'please_select_the_diets_that_are_relevant_for_the_third_registrant';
const DIET_FOURTH = 'please_select_the_diets_that_are_relevant_for_the_fourth_registrant';
const DIET_FIFTH = 'please_select_the_diets_that_are_relevant_for_the_fifth_registrant';
/**
* Registration Type
*/
const REGISTRATION_TYPE_FIRST = 'i_am_a';
const REGISTRATION_TYPE_SECOND = 'the_second_registrant_is_a';
const REGISTRATION_TYPE_THIRD = 'the_third_registrant_is_a';
const REGISTRATION_TYPE_FOURTH = 'the_fourth_registrant_is_a';
const REGISTRATION_TYPE_FIFTH = 'the_fifth_registrant_is_a';
/**
* Registration Price - Attendee
*/
const ATTENDEE_REGISTRATION_PRICE_FIRST = 'attendee_price';
const ATTENDEE_REGISTRATION_PRICE_SECOND = 'attendee_price_second_person';
const ATTENDEE_REGISTRATION_PRICE_THIRD = 'attendee_price_third_person';
const ATTENDEE_REGISTRATION_PRICE_FOURTH = 'attendee_price_fourth_person';
const ATTENDEE_REGISTRATION_PRICE_FIFTH = 'attendee_price_fifth_person';
/**
* Registration Price - Delegate
*/
const DELEGATE_REGISTRATION_PRICE_FIRST = 'delegate_price';
const DELEGATE_REGISTRATION_PRICE_SECOND = 'delegate_price_second_person';
const DELEGATE_REGISTRATION_PRICE_THIRD = 'delegate_price_third_person';
const DELEGATE_REGISTRATION_PRICE_FOURTH = 'delegate_price_fourth_person';
const DELEGATE_REGISTRATION_PRICE_FIFTH = 'delegate_price_fifth_person';
/**
* Delegate Organisation
*/
const ORGANISATION = 'please_enter_the_name_of_the_community__national_network_you_are_a_delegate_for';
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment