cipf v 0.5.8 handle partner events

This commit is contained in:
asus
2024-04-12 17:13:57 +02:00
parent 6aa3915ef9
commit bfa68a4dd7
11 changed files with 300 additions and 217 deletions

View File

@@ -110,4 +110,91 @@ function send_emails_CIPF($email_name, $user_id = null) {
/*
* get the acf reminders,
* - continue the ones not for the reminder_type
* - continue if date is not yet soon enough
* - continue if email was already sent
*
*/
function handle_send_reminders_CIPF($acf_id, $user_id, $date_limit, $reminder_type, $email_type) {
$is_before_reminders = true;
$reminders_choices = get_emails_reminders_choices_CIPF($acf_id);
foreach ($reminders_choices as $reminder_key => $value) {
$duration = get_duration_CIPF($reminder_key, $reminder_type);
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, $acf_id)) {
continue;
}
set_email_reminder_choice_CIPF($reminder_key, $acf_id);
send_emails_CIPF($email_type, $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_box_CIPF($reminder_type, $acf_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);
}
?>