From 1162f87e4326868160cfddaa524efd1386b34133 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Tue, 13 Jun 2017 22:35:17 -0400 Subject: Add mesg function emailMesg() --- app/class/mesg.class.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'app/class/mesg.class.php') diff --git a/app/class/mesg.class.php b/app/class/mesg.class.php index 6c84d4f..da52fa6 100644 --- a/app/class/mesg.class.php +++ b/app/class/mesg.class.php @@ -282,6 +282,56 @@ class mesg extends object $this->delObj(); return $issue; } + + /* + * Email this message to parents, owners, members. In the case that + * this is an issue message or a reply message, the assignee or original + * author is also included. Attachments are included in mailing. Any + * duplicates in the rcpt list are removed before sending. Success + * or failure is returned. + */ + public function emailMesg() : bool + { + $parent = $this->getParent(); + + if (!$parent) + return true; + + $rcpt = $this->getMembers(); + $rcpt[] = $this->getOwner(); + + switch ($parent->objtype) + { + case "user": + $rcpt[] = $parent; + $subj = $this->author . " PM from " . $this->getAuthor()->getDisplayName(); + break; + + case "issue": + $rcpt[] = $parent->getAssignee(); + $pad = $parent->getPad(); + $subj = $parent->guid . " " . $pad->name . " [#" . $parent->numb . "] " . $parent->name; + break; + + case "mesg": + case "log": + $rcpt[] = $parent->getAuthor(); + $pad = $parent->getParent(); + $subj = $parent->guid . " " . $pad->name . " // " . $parent->name; + break; + } + + $rcpt = object::arrayUnique($rcpt); + $attachPath = ($this->getAttachment() ? "dynmic/attach/" . $this->guid : NULL); + + foreach ($rcpt as $r) + { + if (!$r->sendEmail($subj, $this->mesg, $attachPath, $this->attachment)) + return false; + } + + return true; + } } ?> -- cgit v1.2.3 From 9fd988bf44089634bd3efa8acc95368cf45c2498 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 14 Jun 2017 00:53:13 -0400 Subject: Update mesg function emailMesg() Fixed a bug and fine-tuned some of the behavior of this function. --- app/class/mesg.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/class/mesg.class.php') diff --git a/app/class/mesg.class.php b/app/class/mesg.class.php index da52fa6..2512d03 100644 --- a/app/class/mesg.class.php +++ b/app/class/mesg.class.php @@ -297,14 +297,14 @@ class mesg extends object if (!$parent) return true; - $rcpt = $this->getMembers(); - $rcpt[] = $this->getOwner(); + $rcpt = $parent->getMembers(); + $rcpt[] = $parent->getOwner(); switch ($parent->objtype) { case "user": $rcpt[] = $parent; - $subj = $this->author . " PM from " . $this->getAuthor()->getDisplayName(); + $subj = $this->author . " " . $this->getAuthor()->getDisplayName() . " // " . $this->name; break; case "issue": @@ -322,11 +322,15 @@ class mesg extends object } $rcpt = object::arrayUnique($rcpt); + $author = $this->author; + $rcpt = array_filter($rcpt, function ($val) use($author) { return $val->guid != $author; }); $attachPath = ($this->getAttachment() ? "dynmic/attach/" . $this->guid : NULL); + $mesg = $this->getAuthor()->getDisplayName() . " wrote on " . $this->created . "\n\n"; + $mesg .= $this->renderMesg(); foreach ($rcpt as $r) { - if (!$r->sendEmail($subj, $this->mesg, $attachPath, $this->attachment)) + if (!$r->sendEmail($subj, $mesg, $attachPath, $this->attachment)) return false; } -- cgit v1.2.3