ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSendMailActivity.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5require_once './Services/WorkflowEngine/interfaces/ilActivity.php';
7require_once './Services/WorkflowEngine/interfaces/ilNode.php';
8
20{
22 private $context;
23
26
28 protected $name;
29
31 private $parameters;
32
34 private $outputs;
35
41 public function __construct(ilNode $a_context)
42 {
43 $this->context = $a_context;
44 }
45
53 public function execute()
54 {
56 $workflow = $this->getContext()->getContext();
57 $definitions = $workflow->getInstanceVars();
58
59 $recipient = '';
60 $subject = '';
61 foreach ($this->parameters as $parameter) {
62 foreach ($definitions as $definition) {
63 if ($definition['id'] = $parameter) {
64 switch (strtolower($definition['role'])) {
65 case 'emailaddress':
66 $recipient = $definition['value'];
67 break;
68 case 'subject':
69 $subject = $definition['value'];
70 break;
71 }
72 }
73 }
74 }
75
76 $mail_data = $this->context->getContext()->getMessageDefinition($this->message_name);
77 $mail_text = $this->decodeMessageText($mail_data['content']);
78 $mail_text = $this->processPlaceholders($mail_text);
79
80 require_once './Services/WorkflowEngine/classes/activities/class.ilWorkflowEngineMailNotification.php';
82 $mail->setSubjectText($subject);
83 $mail->setBodyText($mail_text);
84
85 $mail->send($recipient);
86 }
87
93 public function getContext()
94 {
95 return $this->context;
96 }
97
101 public function setName($name)
102 {
103 $this->name = $name;
104 }
105
109 public function getName()
110 {
111 return $this->name;
112 }
113
117 public function getMessageName()
118 {
119 return $this->message_name;
120 }
121
126 {
127 $this->message_name = $message_name;
128 }
129
133 public function getParameters()
134 {
135 return $this->parameters;
136 }
137
141 public function setParameters($parameters)
142 {
143 $this->parameters = $parameters;
144 }
145
149 public function getOutputs()
150 {
151 return $this->outputs;
152 }
153
157 public function setOutputs($outputs)
158 {
159 $this->outputs = $outputs;
160 }
161
162 public function decodeMessageText($message_text)
163 {
164 return base64_decode($message_text);
165 }
166
167 public function processPlaceholders($message_text)
168 {
169 $matches = array();
170 preg_match_all('/\[(.*?)\]/', $message_text, $matches, PREG_PATTERN_ORDER);
171
172 foreach ($matches[0] as $match) {
173 $placeholder = substr($match, 1, strlen($match) - 2);
174
175 $handled = false;
176 if (strtolower(substr($placeholder, 0, strlen('EVENTLINK'))) == 'eventlink') {
177 $handled = true;
178 $content = $this->getEventLink($match);
179 }
180
181 if (!$handled) {
182 $content = $this->context->getContext()->getInstanceVarById($placeholder);
183 }
184
185 if (strlen($content)) {
186 $message_text = str_replace($match, $content, $message_text);
187 }
188 }
189 return $message_text;
190 }
191
192 public function getEventLink($eventlink_string)
193 {
194 $type = substr($eventlink_string, 1, strpos($eventlink_string, ' ') - 1);
195 $params = substr($eventlink_string, strpos($eventlink_string, ' ') + 1, -1);
196
197 $matches = array();
198 preg_match_all('/\{{(.*?)\}}/', $params, $matches, PREG_PATTERN_ORDER);
199 foreach ($matches[1] as $match) {
200 if ($match == 'THIS:WFID') {
201 $params = str_replace('{{' . $match . '}}', $this->getContext()->getContext()->getDbId(), $params);
202 }
203 }
204 $pieces = explode(':', $params);
206 global $DIC;
207 $ilias = $DIC['ilias'];
208
209 $address = ilUtil::_getHttpPath() . '/goto.php?target=wfe_WF'
210 . $pieces[0] . 'EVT' . $pieces[1] . '&client_id=' . $ilias->getClientId();
211
212 return $address;
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
getContext()
Returns a reference to the parent node.
__construct(ilNode $a_context)
Default constructor.
static _getHttpPath()
ilActivity Interface is part of the petri net based workflow engine.
Definition: ilActivity.php:16
@noinspection PhpIncludeInspection
Definition: ilNode.php:26
ilWorkflowEngineElement Interface is part of the petri net based workflow engine.
$type
$DIC
Definition: xapitoken.php:46