diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index f95fdc3..b319dc8 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -33,7 +33,6 @@ include_once(Plgntls::root_path() . 'php/paypal/paypal.php'); // profs include_once(Plgntls::root_path() . 'php/profs_profil.php'); include_once(Plgntls::root_path() . 'php/profs_form_commande.php'); -include_once(Plgntls::root_path() . 'php/profs_dates.php'); include_once(Plgntls::root_path() . 'php/profs_handle_states.php'); // partners include_once(Plgntls::root_path() . 'php/partners_register.php'); @@ -41,6 +40,7 @@ include_once(Plgntls::root_path() . 'php/partners_page.php'); include_once(Plgntls::root_path() . 'php/partners_form.php'); // utils include_once(Plgntls::root_path() . 'php/_utils_acf_fields.php'); +include_once(Plgntls::root_path() . 'php/_utils_acf_dates.php'); include_once(Plgntls::root_path() . 'php/_utils_redirections.php'); include_once(Plgntls::root_path() . 'php/_utils_display_css.php'); include_once(Plgntls::root_path() . 'php/_utils_checks_roles.php'); @@ -83,7 +83,6 @@ class Cipf { const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon']; const ACF_CARD_ORDER_ID = ['_name'=>'order_id']; const ACF_HISTORY = ['_name'=>'history']; - const ACF_PROF_DELETE_ACCOUNT = ['_name'=>'date_suppression_compte']; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; @@ -132,15 +131,6 @@ class Cipf { // SHORTCODES - // SCHEDULED EVENTS - const DURATION_OLD_ORDER_ID = '3 days'; - const DURATION_ACCOUNT_DELETE_AFTER_EXPIRE = '+6 months'; - const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST = '1 month'; - const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST = '7 days'; - const DURATION_REMINDER_BEFORE_ACCOUNT_DELETE_FIRST = '1 month'; - const DURATION_REMINDER_BEFORE_ACCOUNT_DELETE_LAST = '7 days'; - const DURATION_REMINDER_BEFORE_OFFER_EXPIRE = '7 days'; - // OPTIONS const OPTION_PAYPAL = [ '_name'=>'cipf_paypal_credentials', @@ -280,9 +270,18 @@ contactez la fipf directement", const FORM_PROF_COMMANDE_ID = 'prof_commande'; const FORM_PROF_TRANSFERT_ID = 'prof_valide_virement'; + // DURATIONS + const DURATION_CARD_VALIDITY = '+1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') + const DURATION_OLD_ORDER_ID = '+3 days'; + const DURATION_ACCOUNT_DELETE_AFTER_EXPIRE = '+6 months'; + const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST = '-1 month'; + const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST = '-7 days'; + const DURATION_REMINDER_BEFORE_ACCOUNT_DELETE_FIRST = '-1 month'; + const DURATION_REMINDER_BEFORE_ACCOUNT_DELETE_LAST = '-7 days'; + const DURATION_REMINDER_BEFORE_OFFER_EXPIRE = '-7 days'; + // OTHER const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible - const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php) const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php const INPUT_HIDDEN_ROLE = 'cipf_user_role'; diff --git a/plugins/cipf_plugin/php/_actions_scheduled_events.php b/plugins/cipf_plugin/php/_actions_scheduled_events.php index 809b2cb..1b32635 100644 --- a/plugins/cipf_plugin/php/_actions_scheduled_events.php +++ b/plugins/cipf_plugin/php/_actions_scheduled_events.php @@ -85,7 +85,7 @@ function schedule_prof_account_deletion_CIPF($user_id) { Plgntls::debug_infos(); // $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; // -// $date_limit = get_date_limit_CIPF($user_id); +// $date_limit = get_card_date_expiration_CIPF($user_id); // if (false === $date_limit) { // return; // } diff --git a/plugins/cipf_plugin/php/_utils_acf_dates.php b/plugins/cipf_plugin/php/_utils_acf_dates.php new file mode 100644 index 0000000..9380930 --- /dev/null +++ b/plugins/cipf_plugin/php/_utils_acf_dates.php @@ -0,0 +1,223 @@ +format('%R%a'); + + if ($date_diff < 0) { + return true; + } + else { + return false; + } +} + + +/* +* add duration to date object +* duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php +* +*/ +function get_new_date_CIPF($date, $duration) { + Plgntls::debug_infos(); + + $current_date = $date; + // empty return true for false, null, empty string and array, and 0 + if (empty($date)) { + $current_date = date_create('today'); + } + else if (!$current_date instanceof DateTimeInterface) { + $current_date = date_create('today'); + } + + /* + * update date limit validity to add 1 year + * + */ + return $new_date = $current_date->add(date_interval_create_from_date_string($duration)); +} + + +/* +* update acf field with new date +* +*/ +function set_acf_date_CIPF($acf_date_field_to_update, $new_date, $user_id) { + Plgntls::debug_infos(); + + $acf_id = 'user_'.$user_id; + $acf_date_format = 'Y-m-d H:i:s'; + + set_acf_field_CIPF($acf_date_field_to_update, $new_date->format($acf_date_format), $acf_id); +} + + + + + + + + + +/*********************************************************************/ + + + + + + +/* +* card date expiration +* +*/ +function get_card_date_expiration_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + return get_date_CIPF($acf_card_expiration, $user_id); +} +function is_card_date_expired_CIPF($user_id = null) { + Plgntls::debug_infos(); + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + + $card_date = get_card_date_expiration_CIPF($user_id); + return is_date_expired_CIPF($card_date); +} +function isset_acf_card_expiration_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + return isset_acf_field_CIPF($acf_card_expiration, $acf_id); +} +function update_card_date_expiration_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_card_field = Cipf::ACF_CARD_EXPIRATION; + $card_duration = Cipf::DURATION_CARD_VALIDITY; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + + $date = get_card_date_expiration_CIPF($user_id); + $new_date = get_new_date_CIPF($date, $card_duration); + set_acf_date_CIPF($acf_card_field, $new_date, $user_id); +} + + + + + + +/* +* prof account deletion + +- get prof deletion date +- is prof deletion date expired + +* +*/ +function get_prof_accound_deletion_date_CIPF($user_id = null) { + Plgntls::debug_infos(); + $delete_duration = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $card_expiration_date = get_card_date_expiration_CIPF($user_id); + return get_new_date_CIPF($card_expiration_date, $delete_duration); +} +function is_prof_account_deletion_expired_CIPF($user_id = null) { + Plgntls::debug_infos(); + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + + $account_date = get_prof_accound_deletion_date_CIPF($user_id); + return is_date_expired_CIPF($account_date); +} + + +?> diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index 7a3b96b..beb858b 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -44,10 +44,6 @@ if (!defined('ABSPATH')) { * * [/] order id ('order_id') * -* [/] card expiration date ('fin_de_validite') -* -* [/] prof deletion date ('date_suppression_compte') -* * */ @@ -545,25 +541,6 @@ function reset_acf_cgv_CIPF($user_id = null) { -/* -* fin_de_validite -* -*/ -function isset_acf_card_expiration_CIPF($user_id = null) { - Plgntls::debug_infos(); - $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; - - if (is_null($user_id)) { - $user_id = get_current_user_id(); - } - $acf_id = 'user_'.$user_id; - return isset_acf_field_CIPF($acf_card_expiration, $acf_id); -} - - - - - /* * date_suppression_compte diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index b7db0ca..20c5839 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -141,7 +141,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) { Plgntls::debug_infos(); schedule_delete_orderid_CIPF($order_id, $user_id); - update_card_expiration_CIPF($user_id); + update_card_date_expiration_CIPF($user_id); if (is_card_new_CIPF()) { set_card_number_CIPF($user_id); diff --git a/plugins/cipf_plugin/php/profs_dates.php b/plugins/cipf_plugin/php/profs_dates.php deleted file mode 100644 index 10e24f9..0000000 --- a/plugins/cipf_plugin/php/profs_dates.php +++ /dev/null @@ -1,208 +0,0 @@ -format('%R%a'); -} - - - - -/* -* returns true if date is in paste or is empty -* use card_date_exists_CIPF to check if the field is empty -* -*/ -function is_card_date_expired_CIPF($user_id = null) { - Plgntls::debug_infos(); - - /* - * define user_id - * - */ - if (is_null($user_id)) { - $user_id = get_current_user_id(); - } - - /* - * check if expired - * - */ - $date_diff = card_date_diff_CIPF($user_id); - if ($date_diff === false) { - return true; - } - else if ($date_diff < 0) { - return true; - } - return false; -} - - - - -/* -* returns true if date is empty -* -*/ -function card_date_exists_CIPF($user_id = null) { - Plgntls::debug_infos(); - $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; - - /* - * define ids - * - */ - if (is_null($user_id)) { - $user_id = get_current_user_id(); - } - $acf_id = 'user_'.$user_id; - - /* - * get acf date field - * - */ - $date_now = date_create('today'); -// // we dont use utility fonction 'get_acf_field_CIPF' because we want to know if it was not init. Do we ? -// $current_date = get_field($acf_card_expiration['_name'], $acf_id); -// -// if (empty($current_date)) { -// return false; -// } -// if (is_null($current_date)) { -// return false; -// } -// return true; - return isset_acf_card_expiration_CIPF($user_id); -} - - - - -/* -* will add card_duration to card -* card_duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php -* -*/ -function update_card_expiration_CIPF($user_id = null) { - Plgntls::debug_infos(); - $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; - $card_duration = Cipf::CARD_VALIDITY_TIME; - - /* - * define acf id and acf date format - * - */ - if (is_null($user_id)) { - $user_id = get_current_user_id(); - } - $acf_id = 'user_'.$user_id; - $acf_date_format = 'Y-m-d H:i:s'; - - /* - * get date limit as DateTime object - * - */ - $current_date_limit = get_date_limit_CIPF($user_id); - if ($current_date_limit === false) { - $current_date_limit = date_create('today'); - } - - /* - * update date limit validity to add 1 year - * - */ - $date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration)); - set_acf_field_CIPF($acf_card_expiration, $date_plus_one_year->format($acf_date_format), $acf_id); -} - - - - - -?> diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index ddda50b..6614437 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -44,7 +44,7 @@ function handle_transfert_validation_CIPF($user_id) { * */ set_account_valid_CIPF($user_id); - update_card_expiration_CIPF($user_id); + update_card_date_expiration_CIPF($user_id); set_card_number_CIPF($user_id); set_card_renew_CIPF($user_id); send_emails_CIPF('transfert_success', $user_id); @@ -60,7 +60,7 @@ function handle_transfert_validation_CIPF($user_id) { */ function handle_card_expire_CIPF($user_id) { Plgntls::debug_infos(); - if (false === card_date_exists_CIPF($user_id)) { + if (false === isset_acf_card_expiration_CIPF($user_id)) { return; } if (is_card_date_expired_CIPF($user_id)) {