| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\FormBuilder; |
| 4 |
|
| 5 |
use FluentForm\App\Services\FormBuilder\ShortCodeParser; |
| 6 |
|
| 7 |
class NotificationParser |
| 8 |
{ |
| 9 |
protected static $cache = null; |
| 10 |
|
| 11 |
/** |
| 12 |
* Parse Norifications |
| 13 |
* @param array $notifications |
| 14 |
* @param int $insertId |
| 15 |
* @param array $data |
| 16 |
* @param object $form |
| 17 |
* @return bool $cache |
| 18 |
*/ |
| 19 |
public static function parse($notifications, $insertId, $data, $form, $cache = true) |
| 20 |
{ |
| 21 |
if ($cache && !is_null(static::$cache)) { |
| 22 |
return static::$cache; |
| 23 |
} |
| 24 |
|
| 25 |
foreach ($notifications as &$notification) { |
| 26 |
static::setRecepient($notification, $data); |
| 27 |
|
| 28 |
$notification = ShortCodeParser::parse( |
| 29 |
$notification, $insertId, $data, $form |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
return $cache ? (static::$cache = $notifications) : $notifications; |
| 34 |
} |
| 35 |
|
| 36 |
protected static function setRecepient(&$notification, $data) |
| 37 |
{ |
| 38 |
if (isset($notification['sendTo']) && $notification['sendTo']['type'] == 'field') { |
| 39 |
$notification['sendTo']['email'] = $data[$notification['sendTo']['field']]; |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|