From 4d7906be40f147c3b464357f00c19456e74d59c3 Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 1 Apr 2024 01:39:38 +0200 Subject: [PATCH] prof more checks at profil and when fipf validate transfert --- .../cipf_plugin/php/profs_handle_states.php | 51 +++++++++++++------ plugins/cipf_plugin/php/profs_profil.php | 6 ++- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index 55e465f..b98a561 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -12,27 +12,41 @@ if (!defined('ABSPATH')) { /* -* if field transfert-validation is not checked, do nothing -* else -* first reset the field -* then -* if no transfert was waiting, do nothing -* when transfert is validate : -* - change card to valid -* - update date +* if the acf field for transfert validation is checked, +* it means we need to validate the transfert * */ function handle_transfert_validation_CIPF($user_id) { Plgntls::debug_infos(); + + /* + * check and reset the acf fielf for transfert + * + */ if (false === is_transfert_success_CIPF($user_id)) { return; } reset_acf_transfert_CIPF($user_id); + + /* + * if the account is not in transfert state, nothing to do + * + */ if (false === is_account_waiting_transfert_CIPF($user_id)) { return; } + + /* + * set account valid + * create card number + * add one year + * change state 'commande'->'renouvellement' + * + */ set_account_valid_CIPF($user_id); update_card_expiration_CIPF($user_id); + set_card_number_CIPF($user_id); + set_card_renew_CIPF($user_id); } @@ -48,14 +62,21 @@ function handle_card_expire_CIPF($user_id) { if (false === card_date_exists_CIPF($user_id)) { return; } - if (false === is_card_date_expired_CIPF($user_id)) { - return; + if (is_card_date_expired_CIPF($user_id)) { + if (is_account_waiting_transfert_CIPF($user_id)) { + set_account_waiting_invalid_CIPF($user_id); + } + else { + set_account_expired_CIPF($user_id); + } } - if (false === is_account_expired_CIPF($user_id)) { - set_account_expired_CIPF($user_id); - } - if (is_account_waiting_valid_CIPF($user_id)) { - set_account_waiting_invalid_CIPF($user_id); + else { + if (is_account_waiting_transfert_CIPF($user_id)) { + set_account_waiting_valid_CIPF($user_id); + } + else { + set_account_valid_CIPF($user_id); + } } } diff --git a/plugins/cipf_plugin/php/profs_profil.php b/plugins/cipf_plugin/php/profs_profil.php index 79086f5..55aceee 100644 --- a/plugins/cipf_plugin/php/profs_profil.php +++ b/plugins/cipf_plugin/php/profs_profil.php @@ -51,7 +51,11 @@ function prof_profil_check_CIPF() { // the way to find the id of the author of an author_page $author_id = get_queried_object_id(); - // in case event didn't fire, handle card_expiration + /* + * in case event didn't fire, handle card changes + * + */ + handle_transfert_validation_CIPF($user_id); handle_card_expire_CIPF($author_id); } add_action('wp', 'prof_profil_check_CIPF', 11);