From fa8fa4f7ebbd3246c3f991630318ff855ffa0120 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sat, 9 Jul 2022 12:26:32 -0500 Subject: [PATCH] Send email to the admin when a new patron joins --- lib/Patron.php | 8 +++++++ lib/User.php | 20 +++++++++++++++++ scripts/process-pending-payments | 1 + templates/EmailAdminNewPatron.php | 32 +++++++++++++++++++++++++++ templates/EmailAdminNewPatronText.php | 9 ++++++++ 5 files changed, 70 insertions(+) create mode 100644 templates/EmailAdminNewPatron.php create mode 100644 templates/EmailAdminNewPatronText.php diff --git a/lib/Patron.php b/lib/Patron.php index 973ccb6b..cf1ea936 100644 --- a/lib/Patron.php +++ b/lib/Patron.php @@ -40,6 +40,14 @@ class Patron extends PropertiesBase{ $em->Body = Template::EmailPatronsCircleWelcome(['isAnonymous' => $this->IsAnonymous, 'isReturning' => $isReturning]); $em->TextBody = Template::EmailPatronsCircleWelcomeText(['isAnonymous' => $this->IsAnonymous, 'isReturning' => $isReturning]); $em->Send(); + + $em = new Email(); + $em->To = ADMIN_EMAIL_ADDRESS; + $em->From = ADMIN_EMAIL_ADDRESS; + $em->Subject = 'New Patrons Circle member'; + $em->Body = Template::EmailAdminNewPatron(['patron' => $this, 'payment' => $this->User->Payments[0]]); + $em->TextBody = Template::EmailAdminNewPatronText(['patron' => $this, 'payment' => $this->User->Payments[0]]);; + $em->Send(); } } diff --git a/lib/User.php b/lib/User.php index 38c898bd..58007c0f 100644 --- a/lib/User.php +++ b/lib/User.php @@ -2,12 +2,32 @@ use Ramsey\Uuid\Uuid; use Safe\DateTime; +/** + * @property Array $Payments + */ class User extends PropertiesBase{ public $UserId; public $Name; public $Email; public $Created; public $Uuid; + protected $_Payments = null; + + + // ******* + // GETTERS + // ******* + + /** + * @return array + */ + protected function GetPayments(): array{ + if($this->_Payments === null){ + $this->_Payments = Db::Query('select * from Payments where UserId = ? order by Created desc', [$this->UserId], 'Payment'); + } + + return $this->_Payments; + } // ******* diff --git a/scripts/process-pending-payments b/scripts/process-pending-payments index a0cffcb8..3d19f297 100755 --- a/scripts/process-pending-payments +++ b/scripts/process-pending-payments @@ -163,6 +163,7 @@ try{ $patron = new Patron(); $patron->UserId = $payment->UserId; $patron->User = $payment->User; + $patron->User->Payments = [$payment]; $patron->IsAnonymous = (trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::td[normalize-space(.) = "Attribution"]]'))->getText()) == 'Private'); $patron->IsSubscribedToEmails = $patron->User !== null && $patron->User->Email !== null; diff --git a/templates/EmailAdminNewPatron.php b/templates/EmailAdminNewPatron.php new file mode 100644 index 00000000..dbaa3601 --- /dev/null +++ b/templates/EmailAdminNewPatron.php @@ -0,0 +1,32 @@ + + + + New Patrons Circle member + + + + + + + + + + + + + + + + + + + + + + + + + +
Name:Name) ?>
Donation type:IsRecurring){ ?>RecurringOne-time
Donation amount:Amount)) ?>
Donation fee:Fee)) ?>
Transaction ID:TransactionId) ?>
+ + diff --git a/templates/EmailAdminNewPatronText.php b/templates/EmailAdminNewPatronText.php new file mode 100644 index 00000000..b043b9b8 --- /dev/null +++ b/templates/EmailAdminNewPatronText.php @@ -0,0 +1,9 @@ +Name: Name) ?> + +Donation type: IsRecurring){ ?>RecurringOne-time + +Donation amount: Amount)) ?> + +Donation fee: Fee)) ?> + +Transaction ID: TransactionId) ?>