diff --git a/scripts/daily_digest.php b/scripts/daily_digest.php new file mode 100644 index 0000000000000000000000000000000000000000..b6175e38be3343509e89389c877e5a9f37f114ce --- /dev/null +++ b/scripts/daily_digest.php @@ -0,0 +1,75 @@ +<?php + +$config_file = __DIR__ . '/../config.sample.php'; +if (file_exists(__DIR__ . '/../config.inc.php')) { + $config_file = __DIR__ . '/../config.inc.php'; +} +require_once $config_file; +require_once __DIR__ . '/../vendor/composer/autoload.php'; + +use Models\Lockup; +use Models\User; +use \Emailer as Emailer; + +# for each approver +$approvers = User::find('all', array('conditions' => array('role' => 'approver'))); +foreach ($approvers as $approver) { + # find all lockups that they have that are awaiting communicator approval + # (that were generated in the last 24 hours) + $lockups = Lockup::find('all', array('conditions' => + array('approver_id = ? AND status = ? AND date_created >= ?', $approver->id, 'awaiting_approval', + date('Y-m-d H:i:s', time() - 24*60*60)))); + + # send an email if there is at least 1 of these + if (count($lockups) > 0) { + $lockup_names = array(); + foreach ($lockups as $lockup) { + $lockup_names[] = $lockup->getName(); + } + + $body = ' +Hello, ' . $approver->name . '. We have ' . count($lockups) . ' new lockups awaiting your approval. +<br><br> +' . implode($lockup_names, '<br>') . ' +<br><br> +Please visit <a href="http://lockups.unl.edu/lockups/manage/">http://lockups.unl.edu/lockups/manage/</a> to view these lockups. +<br><br> +UNL Lockup Factory +'; + + Emailer::sendMail($approver->email, "UNL Lockup Factory Digest", $body); + echo 'sent mail to ' . $approver->email; + echo $body; + } +} + +# also do this for creative +$creative_emails = array('mplioplis2@unl.edu'); # configurable value + +# find all lockups that they have that are awaiting communicator approval +# (that were generated in the last 24 hours) +$lockups = Lockup::find('all', array('conditions' => + array('creative_status = ? AND date_created >= ?', 'awaiting_approval', + date('Y-m-d H:i:s', time() - 24*60*60)))); + +# send an email if there is at least 1 of these +if (count($lockups) > 0) { + $lockup_names = array(); + foreach ($lockups as $lockup) { + $lockup_names[] = $lockup->getName(); + } + + $body = ' +Hello. We have ' . count($lockups) . ' new lockups awaiting creative approval. +<br><br> +' . implode($lockup_names, '<br>') . ' +<br><br> +Please visit <a href="http://lockups.unl.edu/lockups/manage/">http://lockups.unl.edu/lockups/manage/</a> to view these lockups. +<br><br> +UNL Lockup Factory +'; + + Emailer::sendMail($creative_emails, "UNL Lockup Factory Digest", $body); + echo 'sent mail to creative'; + echo $body; +} diff --git a/src/Emailer.php b/src/Emailer.php index 7f2675c44461a0f1e2eaf7fc4b258b29230da639..bbda1c5d744c3f16a618417d528e0a228b4fc7c4 100644 --- a/src/Emailer.php +++ b/src/Emailer.php @@ -28,6 +28,7 @@ class Emailer { self::$mailer->addAddress($to); } self::$mailer->addReplyTo('lemburg@unl.edu', 'Tyler Lemburg'); + self::$mailer->addReplyTo('mplioplis2@unl.edu', 'Marcelo Plioplis'); self::$mailer->isHTML(true); self::$mailer->Subject = $subject;