42 if ($id && $this->load($id))
45 foreach ($configuration->getOptions() as $option)
47 $key = $option->getCode();
48 $value = isset($data[$key]) ? $data[$key] :
null;
49 if ($option->getType() === $option::TYPE_FILE)
51 $value = ($value <>
'') ? explode(
',', $value) : $value;
54 $configuration->set($key, $value);
57 $configuration->setId($id);
60 return $configuration;
71 $this->setId($configuration->getId());
72 $result = $configuration->checkOptions();
73 if (!$result->isSuccess())
79 foreach ($configuration->getOptions() as $option)
82 if ($option->getType() === $option::TYPE_FILE)
84 $value = is_array($value) ? implode(
',', $value) : $value;
88 'CODE' => $option->getCode(),
89 'TYPE' => $option->getType(),
94 if (count($data) == 0)
96 $result->addError(
new Error(
'No options.'));
103 $result->addErrors($this->errors->toArray());
107 $configuration->setId($this->
getId());
290 $fields = $data[
'FIELDS'];
291 $utmTags = $data[
'UTM'];
292 unset($data[
'FIELDS']);
295 if (!is_array($fields) && count($fields) === 0)
297 $this->addError(
'No message fields.');
301 $id = $this->saveByEntity(MessageTable::getEntity(), $id, $data);
307 MessageFieldTable::deleteByMessageId($id);
308 foreach ($fields as $field)
315 if (in_array($field[
'CODE'], [
'MESSAGE_PERSONALIZE',
'SUBJECT_PERSONALIZE',
'TITLE_PERSONALIZE']))
320 if (in_array($field[
'CODE'], [
'MESSAGE',
'SUBJECT',
'TITLE']))
322 preg_match_all(
"/#([0-9a-zA-Z_.|]+?)#/", $field[
'VALUE'], $matchesFindPlaceHolders);
323 $matchesFindPlaceHoldersCount = count($matchesFindPlaceHolders[1]);
324 if ($matchesFindPlaceHoldersCount > 0)
326 $list = json_encode($matchesFindPlaceHolders);
327 MessageFieldTable::add(
330 'TYPE' => $field[
'TYPE'],
331 'CODE' => $field[
'CODE'] .
'_PERSONALIZE',
337 MessageFieldTable::add([
339 'TYPE' => $field[
'TYPE'],
340 'CODE' => $field[
'CODE'],
341 'VALUE' => $field[
'VALUE'],
348 foreach ($utmTags as $utm)
350 if (empty($utm[
'VALUE']) || empty($utm[
'CODE']))
354 MessageUtmTable::add(
357 'CODE' => $utm[
'CODE'],
358 'VALUE' => $utm[
'VALUE'],