cipf v 0.5.8 handle partner events
This commit is contained in:
@@ -19,6 +19,7 @@ if (!defined('ABSPATH')) {
|
||||
function handle_transfert_validation_CIPF($user_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$acf_id = 'user_'.$user_id;
|
||||
/*
|
||||
* check and reset the acf fielf for transfert
|
||||
*
|
||||
@@ -47,7 +48,7 @@ function handle_transfert_validation_CIPF($user_id) {
|
||||
update_card_date_expiration_CIPF($user_id);
|
||||
set_card_number_CIPF($user_id);
|
||||
set_card_renew_CIPF($user_id);
|
||||
reset_emails_reminders_choices_CIPF($user_id);
|
||||
reset_emails_reminders_choices_CIPF($acf_id);
|
||||
send_emails_CIPF('transfert_success', $user_id);
|
||||
}
|
||||
|
||||
@@ -61,6 +62,8 @@ function handle_transfert_validation_CIPF($user_id) {
|
||||
*/
|
||||
function handle_card_expire_CIPF($user_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
if (false === isset_acf_card_expiration_CIPF($user_id)) {
|
||||
return;
|
||||
}
|
||||
@@ -71,8 +74,8 @@ function handle_card_expire_CIPF($user_id) {
|
||||
else {
|
||||
set_account_expired_CIPF($user_id);
|
||||
}
|
||||
if (!is_email_reminder_choice_CIPF('card_expired', $user_id)) {
|
||||
set_email_reminder_choice_CIPF('card_expired', $user_id);
|
||||
if (!is_email_reminder_choice_CIPF('card_expired', $acf_id)) {
|
||||
set_email_reminder_choice_CIPF('card_expired', $acf_id);
|
||||
send_emails_CIPF('card_expired', $user_id);
|
||||
}
|
||||
}
|
||||
@@ -83,8 +86,8 @@ function handle_card_expire_CIPF($user_id) {
|
||||
else {
|
||||
set_account_valid_CIPF($user_id);
|
||||
}
|
||||
reset_emails_reminders_deletion_account_CIPF($user_id);
|
||||
unset_email_reminder_choice_CIPF('card_expired', $user_id);
|
||||
reset_emails_reminders_box_CIPF('account_deletion', $acf_id);
|
||||
unset_email_reminder_choice_CIPF('card_expired', $acf_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,38 +149,7 @@ function handle_reminders_before_card_expire_CIPF($user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_before_reminders = true;
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$duration = get_duration_CIPF($reminder_key, 'card_expiration');
|
||||
if (false === $duration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff = compare_diff_with_today_CIPF($date_limit, $duration);
|
||||
if ($diff > 0) {
|
||||
continue;
|
||||
}
|
||||
$is_before_reminders = false;
|
||||
|
||||
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
|
||||
continue;
|
||||
}
|
||||
set_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
send_emails_CIPF('card_will_expire', $user_id);
|
||||
return; // don't send multiple emails
|
||||
}
|
||||
|
||||
/*
|
||||
* if didnt return, it either means that :
|
||||
* - today is before any reminder
|
||||
* - today is after all reminders
|
||||
* use 'is_before_reminders' to know
|
||||
*
|
||||
*/
|
||||
if ($is_before_reminders) {
|
||||
reset_emails_reminders_expiration_card_CIPF($user_id);
|
||||
}
|
||||
handle_send_reminders_CIPF('user_'.$user_id, $user_id, $date_limit, 'card_expiration', 'card_will_expire');
|
||||
}
|
||||
|
||||
|
||||
@@ -197,8 +169,9 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
|
||||
if (!isset_acf_card_expiration_CIPF($user_id)) {
|
||||
return;
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
if (!is_card_date_expired_CIPF($user_id)) {
|
||||
reset_emails_reminders_deletion_account_CIPF($user_id);
|
||||
reset_emails_reminders_box_CIPF('account_deletion', $acf_id);
|
||||
return;
|
||||
}
|
||||
$date_limit = get_card_date_expiration_CIPF($user_id);
|
||||
@@ -207,90 +180,8 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
|
||||
}
|
||||
$date_deletion = $date_limit->modify($duration_deletion);
|
||||
|
||||
handle_send_reminders_CIPF($acf_id, $user_id, $date_deletion, 'account_deletion', 'account_will_be_deleted');
|
||||
|
||||
$is_before_reminders = true;
|
||||
/*
|
||||
* get the acf reminders,
|
||||
* - continue the ones not for account deletion
|
||||
* - continue if date is not yet soon enough
|
||||
* - continue if email was already sent
|
||||
*
|
||||
*/
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$duration = get_duration_CIPF($reminder_key, 'account_deletion');
|
||||
if (false === $duration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff = compare_diff_with_today_CIPF($date_deletion, $duration);
|
||||
if ($diff > 0) {
|
||||
continue;
|
||||
}
|
||||
$is_before_reminders = false;
|
||||
|
||||
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
|
||||
continue;
|
||||
}
|
||||
set_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
send_emails_CIPF('account_will_be_deleted', $user_id);
|
||||
return; // don't send multiple emails
|
||||
}
|
||||
|
||||
/*
|
||||
* if didnt return, it either means that :
|
||||
* - today is before any reminder
|
||||
* - today is after all reminders
|
||||
* use 'is_before_reminders' to know
|
||||
*
|
||||
*/
|
||||
if ($is_before_reminders) {
|
||||
reset_emails_reminders_deletion_account_CIPF($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* extract the duration
|
||||
* returns false if not for the right type
|
||||
*
|
||||
*/
|
||||
function get_duration_CIPF($reminder, $type) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$explode_reminder = explode('/', $reminder);
|
||||
$explode_reminder = array_map('trim', $explode_reminder);
|
||||
if ($explode_reminder[0] !== $type) {
|
||||
return false;
|
||||
}
|
||||
$duration = $explode_reminder[1];
|
||||
return $duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find the diffs :
|
||||
* - the intended diff between the deletion date and the reminder
|
||||
* - the diff between the deletion date and today
|
||||
* and return the difference
|
||||
*
|
||||
*/
|
||||
function compare_diff_with_today_CIPF($date, $duration) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$date_reminder = $date->modify($duration);
|
||||
$date_diff = date_diff($date, $date_reminder);
|
||||
$date_diff = (int)$date_diff->format('%R%a');
|
||||
|
||||
$date_now = date_create('now');
|
||||
$current_date_diff = date_diff($date, $date_now);
|
||||
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
||||
|
||||
return ($date_diff - $current_date_diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user