Fixed formatting bugs in the outgoing emails

This commit is contained in:
Erik Thuning 2022-05-02 15:21:56 +02:00
parent 0ee0f81024
commit 15f4597637

@ -9,8 +9,8 @@ class Cron {
$this->now = new DateTimeImmutable();
$this->sender = $sender;
$this->error = $error;
$warn_time = DateInterval::createFromDateString('3 days');
$this->warn_date = $this->now->add($warn_time);
$this->warn_time = DateInterval::createFromDateString('3 days');
$this->warn_date = $this->now->add($this->warn_time);
$this->run_interval = DateInterval::createFromDateString('1 day');
$this->kvs = new Kvs();
$this->ldap = new Ldap();
@ -58,7 +58,7 @@ class Cron {
if(!$expiring) {
return '';
}
$days = $this->warn_date->d;
$days = $this->warn_time->d;
switch($lang) {
case 'sv':
$msg = "Följande lån går ut om mindre än ".$days." dagar:";
@ -76,16 +76,16 @@ class Cron {
default:
throw new Exception("Invalid language: ".$lang);
}
$msg .= "\n\n";
$lines = array();
foreach($expiring as $loan) {
$product = $loan->get_product();
$serial = $product->get_serial();
$brand = $product->get_brand();
$name = $product->get_name();
$endtime = format_date($loan->get_endtime());
$msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
$lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
}
return $msg;
return $msg."\n\n".implode("\n", $lines);
}
private function make_overdue_notice($lang, $overdue) {
@ -108,16 +108,16 @@ class Cron {
default:
throw new Exception("Invalid language: ".$lang);
}
$msg .= "\n\n";
$lines = array();
foreach($overdue as $loan) {
$product = $loan->get_product();
$serial = $product->get_serial();
$brand = $product->get_brand();
$name = $product->get_name();
$endtime = format_date($loan->get_endtime());
$msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
$lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
}
return $msg;
return $msg."\n\n".implode("\n", $lines);
}
private function make_return_info($lang, $count) {
@ -148,25 +148,31 @@ class Cron {
}
private function send_reminder($user, $expiring, $expired) {
private function send_reminder($user, $expiring, $overdue) {
$uid = $user->get_name();
$name = $this->ldap->get_firstname($uid);
$subject = $this->make_subject(count($expiring), count($expired));
$expiring_count = count($expiring);
$overdue_count = count($overdue);
$total = $expiring_count + $overdue_count;
$subject = $this->make_subject($expiring_count, $overdue_count);
$info_sv = array();
$info_sv[] = $this->make_expiring_notice('sv', $expiring);
$info_sv[] = $this->make_overdue_notice('sv', $expired);
$info_sv = implode("\n\n", $info_sv);
$returns_sv = $this->make_return_info(
'sv', count($expiring) + count($expired));
$info_en = array();
$info_en[] = $this->make_expiring_notice('en', $expiring);
$info_en[] = $this->make_overdue_notice('en', $expired);
if($expiring_count > 0) {
$info_sv[] = $this->make_expiring_notice('sv', $expiring);
$info_en[] = $this->make_expiring_notice('en', $expiring);
}
if($overdue_count > 0) {
$info_sv[] = $this->make_overdue_notice('sv', $overdue);
$info_en[] = $this->make_overdue_notice('en', $overdue);
}
$info_sv = implode("\n\n", $info_sv);
$returns_sv = $this->make_return_info('sv', $total);
$info_en = implode("\n\n", $info_en);
$returns_en = $this->make_return_info(
'en', count($expiring) + count($expired));
$returns_en = $this->make_return_info('en', $total);
$message = <<<EOF
Hej $name!