From 96ca0725287ecec200b2b12edd3a3c08c62eeb8c Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 30 Aug 2021 16:03:00 +0200 Subject: [PATCH] add methods sendRequestWorkflowActionMail and sendTriggerWorkflowTransitionMail --- inc/inc.ClassNotificationService.php | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/inc/inc.ClassNotificationService.php b/inc/inc.ClassNotificationService.php index e3dbd8804..55c3c8c1b 100644 --- a/inc/inc.ClassNotificationService.php +++ b/inc/inc.ClassNotificationService.php @@ -1038,5 +1038,86 @@ class SeedDMS_NotificationService { } } /* }}} */ + public function sendTriggerWorkflowTransitionMail($content, $user, $wkflog) { /* {{{ */ + $document = $content->getDocument(); + $workflow = $wkflog->getWorkflow(); + $transition = $wkflog->getTransition(); + $nl = $document->getNotifyList(); + $folder = $document->getFolder(); + $subject = "transition_triggered_email_subject"; + $message = "transition_triggered_email_body"; + $params = array(); + $params['name'] = $document->getName(); + $params['version'] = $content->getVersion(); + $params['workflow'] = $workflow->getName(); + $params['action'] = $transition->getAction()->getName(); + $params['folder_path'] = $folder->getFolderPathPlain(); + $params['comment'] = $wkflog->getComment(); + $params['previous_state'] = $transition->getState()->getName(); + $params['current_state'] = $transition->getNextState()->getName(); + $params['username'] = $user->getFullName(); + $params['sitename'] = $this->settings->_siteName; + $params['http_root'] = $this->settings->_httpRoot; + $params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); + + // Send notification to subscribers. + $this->toList($user, $nl["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); + foreach ($nl["groups"] as $grp) { + $this->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); + } + } /* }}} */ + + /** + * This notification is sent when a workflow action needed. + * If a transition is passed this must be the translation lately fired, hence + * the state of the workflow is next state of the transition. If no transition + * is passed, the workflow just started and is still in its initial state. + */ + public function sendRequestWorkflowActionMail($content, $user, $transition=null) { /* {{{ */ + $document = $content->getDocument(); + $folder = $document->getFolder(); + if($transition) { + $workflow = $transition->getWorkflow(); + $state = $transition->getNextState(); + } else { + $workflow = $content->getWorkflow(); + $state = $workflow->getInitState(); + } + + if($this->settings->_enableNotificationWorkflow) { + $subject = "request_workflow_action_email_subject"; + $message = "request_workflow_action_email_body"; + $params = array(); + $params['name'] = $document->getName(); + $params['version'] = $content->getVersion(); + $params['workflow'] = $workflow->getName(); + $params['folder_path'] = $folder->getFolderPathPlain(); + if($transition) + $params['current_state'] = $transition->getNextState()->getName(); + else + $params['current_state'] = $workflow->getInitState()->getName(); + $params['username'] = $user->getFullName(); + $params['sitename'] = $this->settings->_siteName; + $params['http_root'] = $this->settings->_httpRoot; + $params['url'] = getBaseUrl().$this->settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); + + $usersinformed = array(); + $groupsinformed = array(); + foreach($workflow->getNextTransitions($state) as $ntransition) { + foreach($ntransition->getUsers() as $tuser) { + if(!in_array($tuser->getUser()->getID(), $usersinformed)) { + $usersinformed[] = $tuser->getUser()->getID(); + $this->toIndividual($user, $tuser->getUser(), $subject, $message, $params, SeedDMS_NotificationService::RECV_WORKFLOW); + } + } + foreach($ntransition->getGroups() as $tuser) { + if(!in_array($tuser->getGroup()->getID(), $groupsinformed)) { + $groupsinformed[] = $tuser->getGroup()->getID(); + $this->toGroup($user, $tuser->getGroup(), $subject, $message, $params, SeedDMS_NotificationService::RECV_WORKFLOW); + } + } + } + } + } /* }}} */ }