ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
63 foreach($definitions as $definition)
64 {
65 if($definition['id'] = $parameter)
66 {
67 switch (strtolower($definition['role']))
68 {
69 case 'emailaddress':
70 $recipient = $definition['value'];
71 break;
72 case 'subject':
73 $subject = $definition['value'];
74 break;
75 }
76 }
77 }
78 }
79
80 $mail_data = $this->context->getContext()->getMessageDefinition($this->message_name);
81 $mail_text = $this->decodeMessageText($mail_data['content']);
82 $mail_text = $this->processPlaceholders($mail_text);
83
84 require_once './Services/WorkflowEngine/classes/activities/class.ilWorkflowEngineMailNotification.php';
86 $mail->setSubjectText($subject);
87 $mail->setBodyText($mail_text);
88
89 $mail->send($recipient);
90 }
91
97 public function getContext()
98 {
99 return $this->context;
100 }
101
105 public function setName($name)
106 {
107 $this->name = $name;
108 }
109
113 public function getName()
114 {
115 return $this->name;
116 }
117
121 public function getMessageName()
122 {
123 return $this->message_name;
124 }
125
130 {
131 $this->message_name = $message_name;
132 }
133
137 public function getParameters()
138 {
139 return $this->parameters;
140 }
141
145 public function setParameters($parameters)
146 {
147 $this->parameters = $parameters;
148 }
149
153 public function getOutputs()
154 {
155 return $this->outputs;
156 }
157
161 public function setOutputs($outputs)
162 {
163 $this->outputs = $outputs;
164 }
165
166 public function decodeMessageText($message_text)
167 {
168 return base64_decode($message_text);
169 }
170
171 public function processPlaceholders($message_text)
172 {
173 $matches = array();
174 preg_match_all('/\[(.*?)\]/',$message_text, $matches, PREG_PATTERN_ORDER);
175
176 foreach($matches[0] as $match)
177 {
178 $placeholder = substr($match, 1, strlen($match)-2);
179
180 $handled = false;
181 if(strtolower(substr($placeholder, 0 , strlen('EVENTLINK'))) == 'eventlink')
182 {
183 $handled = true;
184 $content = $this->getEventLink($match);
185 }
186
187 if(!$handled)
188 {
189 $content = $this->context->getContext()->getInstanceVarById($placeholder);
190 }
191
192 if(strlen($content))
193 {
194 $message_text = str_replace($match, $content, $message_text);
195 }
196 }
197 return $message_text;
198 }
199
200 public function getEventLink($eventlink_string)
201 {
202 $type = substr($eventlink_string, 1, strpos($eventlink_string, ' ')-1);
203 $params = substr($eventlink_string, strpos($eventlink_string, ' ')+1, -1);
204
205 $matches = array();
206 preg_match_all('/\{{(.*?)\}}/',$params, $matches, PREG_PATTERN_ORDER);
207 foreach($matches[1] as $match)
208 {
209 if($match == 'THIS:WFID')
210 {
211 $params = str_replace('{{'.$match.'}}',$this->getContext()->getContext()->getDbId(),$params);
212 }
213 }
214 $pieces = explode(':', $params);
216 global $DIC;
217 $ilias = $DIC['ilias'];
218
219 $address = ilUtil::_getHttpPath() . '/goto.php?target=wfe_WF'
220 . $pieces[0] . 'EVT' . $pieces[1] . '&client_id=' . $ilias->getClientId();
221
222 return $address;
223 }
224}
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()
$params
Definition: example_049.php:96
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.
global $DIC