Skip to content

Commit e0c34b9

Browse files
committed
Some tools
1 parent 5f295cd commit e0c34b9

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

Resources/config/services.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ services:
105105
arguments: ['@Bitrix\Main\Mail\Event', '@bitrix_ordinary_tools.cfile']
106106

107107
Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\EventBridge:
108-
class: Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\EventBridge
108+
class: Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\EventBridge
109+
110+
Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\EventBridgeSms:
111+
class: Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\EventBridgeSms
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge;
4+
5+
use Bitrix\Main\ArgumentException;
6+
use Bitrix\Main\ORM\Objectify\Collection;
7+
use Bitrix\Main\ORM\Query\Query;
8+
use Bitrix\Main\Sms\Message;
9+
use Bitrix\Main\ObjectPropertyException;
10+
use Bitrix\Main\Sms\TemplateTable;
11+
use Bitrix\Main\SystemException;
12+
use RuntimeException;
13+
14+
/**
15+
* Class EventBridgeSms
16+
* @package Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge
17+
*
18+
* @since 28.07.2021
19+
*/
20+
class EventBridgeSms
21+
{
22+
/**
23+
* Получить скомпилированный текст письма для события.
24+
*
25+
* @param Collection|null $templates Шаблоны.
26+
* @param array $context Значения полей ($arFields).
27+
*
28+
* @return Message
29+
* @throws RuntimeException
30+
*/
31+
public function compileMessage($templates, array $context) : Message
32+
{
33+
if (!$templates) {
34+
throw new RuntimeException('Template SMS object cannot be NULL');
35+
}
36+
37+
$result = [];
38+
foreach ($templates as $smsTemplate) {
39+
$result[] = $smsTemplate;
40+
}
41+
42+
return Message::createFromTemplate(current($result), $context);
43+
}
44+
45+
/**
46+
* @param string $eventName Код события.
47+
* @param string $siteId ID сайта.
48+
* @param string|null $langId ID языка.
49+
*
50+
* @return Collection|null
51+
*
52+
* @throws ArgumentException | ObjectPropertyException | SystemException Битриксовые ошибки.
53+
*/
54+
public function fetchTemplates(string $eventName, string $siteId, ?string $langId = null)
55+
{
56+
$filter = Query::filter()
57+
->where('ACTIVE', 'Y')
58+
->where('SITES.LID', $siteId);
59+
60+
$filter->where('EVENT_NAME', $eventName);
61+
62+
if ($langId !== null) {
63+
$filter->where(Query::filter()
64+
->logic('or')
65+
->where('LANGUAGE_ID', $langId)
66+
->where('LANGUAGE_ID', '')
67+
->whereNull('LANGUAGE_ID'));
68+
}
69+
70+
$result = TemplateTable::getList([
71+
'select' => ['*', 'SITES.SITE_NAME', 'SITES.SERVER_NAME', 'SITES.LID'],
72+
'filter' => $filter,
73+
]);
74+
75+
return $result->fetchCollection();
76+
}
77+
}

0 commit comments

Comments
 (0)