move notification mail into notification service

This commit is contained in:
Uwe Steinmann 2021-05-19 15:13:49 +02:00
parent 6feb6d7121
commit 92ff13afc6
2 changed files with 109 additions and 103 deletions

View File

@ -461,6 +461,7 @@ class SeedDMS_NotificationService {
} /* }}} */
public function sendChangedAttributesMail($document, $user, $oldattributes) { /* {{{ */
$dms = $document->getDMS();
$folder = $document->getFolder();
$notifyList = $document->getNotifyList();
@ -514,6 +515,60 @@ class SeedDMS_NotificationService {
}
} /* }}} */
public function sendChangedFolderAttributesMail($folder, $user, $oldattributes) { /* {{{ */
$dms = $folder->getDMS();
$notifyList = $folder->getNotifyList();
$newattributes = $folder->getAttributes();
if($oldattributes) {
foreach($oldattributes as $attrdefid=>$attribute) {
if(!isset($newattributes[$attrdefid]) || $newattributes[$attrdefid]->getValueAsArray() !== $oldattributes[$attrdefid]->getValueAsArray()) {
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $attribute->getAttributeDefinition()->getName();
$params['attribute_old_value'] = $oldattributes[$attrdefid]->getValue();
$params['attribute_new_value'] = isset($newattributes[$attrdefid]) ? $newattributes[$attrdefid]->getValue() : '';
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $this->settings->_siteName;
$params['http_root'] = $this->settings->_httpRoot;
$this->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$this->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
}
}
}
/* Check for new attributes which didn't have a value before */
if($newattributes) {
foreach($newattributes as $attrdefid=>$attribute) {
if(!isset($oldattributes[$attrdefid]) && $attribute) {
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $dms->getAttributeDefinition($attrdefid)->getName();
$params['attribute_old_value'] = '';
$params['attribute_new_value'] = $attribute->getValue();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $this->settings->_siteName;
$params['http_root'] = $this->settings->_httpRoot;
$this->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$this->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
}
}
}
} /* }}} */
public function sendChangedCommentMail($document, $user, $oldcomment) { /* {{{ */
if($oldcomment != $document->getComment()) {
$notifyList = $document->getNotifyList();
@ -542,6 +597,31 @@ class SeedDMS_NotificationService {
}
} /* }}} */
public function sendChangedFolderCommentMail($folder, $user, $oldcomment) { /* {{{ */
if($oldcomment != $folder->getComment()) {
$notifyList = $folder->getNotifyList();
$subject = "folder_comment_changed_email_subject";
$message = "folder_comment_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['old_comment'] = $oldcomment;
$params['new_comment'] = $comment;
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $this->settings->_siteName;
$params['http_root'] = $this->settings->_httpRoot;
$this->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$this->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
// if user is not owner send notification to owner
// if ($user->getID() != $folder->getOwner()->getID())
// $notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params, SeedDMS_NotificationService::RECV_OWNER);
}
} /* }}} */
public function sendChangedVersionCommentMail($content, $user, $oldcomment) { /* {{{ */
// FIXME: use extra mail template which includes the version
if($oldcomment != $content->getComment()) {
@ -600,6 +680,30 @@ class SeedDMS_NotificationService {
}
} /* }}} */
public function sendChangedFolderNameMail($folder, $user, $oldname) { /* {{{ */
if($oldname != $folder->getName()) {
$notifyList = $folder->getNotifyList();
$subject = "folder_renamed_email_subject";
$message = "folder_renamed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['old_name'] = $oldname;
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $this->settings->_siteName;
$params['http_root'] = $this->settings->_httpRoot;
$this->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$this->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
// if user is not owner send notification to owner
// if ($user->getID() != $folder->getOwner()->getID())
// $this->toIndividual($user, $folder->getOwner(), $subject, $message, $params, SeedDMS_NotificationService::RECV_OWNER);
}
} /* }}} */
public function sendMovedDocumentMail($document, $user, $oldfolder) { /* {{{ */
$targetfolder = $document->getFolder();
if($targetfolder->getId() == $oldfolder->getId())

View File

@ -97,111 +97,13 @@ if(!$controller->run()) {
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())), $errmsg);
}
if($oldname != $name) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $folder->getNotifyList();
// Send notification to subscribers.
if($notifier) {
$notifier->sendChangedFolderNameMail($folder, $user, $oldname);
$subject = "folder_renamed_email_subject";
$message = "folder_renamed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['old_name'] = $oldname;
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
// if user is not owner send notification to owner
// if ($user->getID() != $folder->getOwner()->getID())
// $notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params, SeedDMS_NotificationService::RECV_OWNER);
}
}
$notifier->sendChangedFolderCommentMail($folder, $user, $oldcomment);
if($oldcomment != $comment) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $folder->getNotifyList();
$subject = "folder_comment_changed_email_subject";
$message = "folder_comment_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['old_comment'] = $oldcomment;
$params['new_comment'] = $comment;
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
// if user is not owner send notification to owner
// if ($user->getID() != $folder->getOwner()->getID())
// $notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params, SeedDMS_NotificationService::RECV_OWNER);
}
}
$newattributes = $folder->getAttributes();
if($oldattributes) {
foreach($oldattributes as $attrdefid=>$attribute) {
if(!isset($newattributes[$attrdefid]) || $newattributes[$attrdefid]->getValueAsArray() !== $oldattributes[$attrdefid]->getValueAsArray()) {
if($notifier) {
$notifyList = $folder->getNotifyList();
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $attribute->getAttributeDefinition()->getName();
$params['attribute_old_value'] = $oldattributes[$attrdefid]->getValue();
$params['attribute_new_value'] = isset($newattributes[$attrdefid]) ? $newattributes[$attrdefid]->getValue() : '';
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
}
}
}
}
/* Check for new attributes which didn't have a value before */
if($newattributes) {
foreach($newattributes as $attrdefid=>$attribute) {
if(!isset($oldattributes[$attrdefid]) && $attribute) {
if($notifier) {
$notifyList = $folder->getNotifyList();
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $dms->getAttributeDefinition($attrdefid)->getName();
$params['attribute_old_value'] = '';
$params['attribute_new_value'] = $attribute->getValue();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
}
}
}
$notifier->sendChangedFolderAttributesMail($folder, $user, $oldattributes);
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_folder_edited')));