Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
senderconnector.php
1<?php
2namespace Bitrix\Subscribe;
3
6
7Loc::loadMessages(__FILE__);
8
10{
17 public static function onConnectorListSubscriber($data)
18 {
19 $data['CONNECTOR'] = 'Bitrix\Subscribe\SenderConnectorSubscriber';
20 return $data;
21 }
22}
23
24if (Loader::includeModule('sender'))
25{
26 class SenderConnectorSubscriber extends \Bitrix\Sender\Connector
27 {
33 public function getName()
34 {
35 return Loc::getMessage('sender_connector_subscriber_name');
36 }
37
43 public function getCode()
44 {
45 return 'subscriber';
46 }
47
53 public function getData()
54 {
55 $filter = [];
56
57 $rubric = $this->getFieldValue('RUBRIC', null);
58 if ($rubric)
59 {
60 $filter['=RUBRICS.ID'] = $rubric;
61 }
62
63 $active = $this->getFieldValue('ACTIVE', null);
64 if ($active)
65 {
66 $filter['=ACTIVE'] = $active;
67 }
68
69 $confirmed = $this->getFieldValue('CONFIRMED', null);
70 if ($confirmed)
71 {
72 $filter['=CONFIRMED'] = $confirmed;
73 }
74
75 $dateInsertFrom = $this->getFieldValue('DATE_INSERT_FROM', null);
77 {
78 $dateInsertFrom = \Bitrix\Main\Type\DateTime::tryParse($dateInsertFrom);
80 {
81 $dateInsertFrom->setTime(0, 0, 0);
82 $filter['>=DATE_INSERT'] = $dateInsertFrom;
83 }
84 }
85
86 $dateInsertTo = $this->getFieldValue('DATE_INSERT_TO', null);
87 if ($dateInsertTo)
88 {
89 $dateInsertTo = \Bitrix\Main\Type\DateTime::tryParse($dateInsertTo);
90 if ($dateInsertTo)
91 {
92 $dateInsertTo->setTime(23, 59, 59);
93 $filter['<=DATE_INSERT'] = $dateInsertTo;
94 }
95 }
96
97 $subscriberList = SubscriptionTable::getList([
98 'select' => ['*', 'USER_NAME' => 'USER.NAME', 'USER_LAST_NAME' => 'USER.LAST_NAME'],
99 'filter' => $filter,
100 'order' => ['ID' => 'ASC'],
101 ]);
102 $subscriberList->addFetchDataModifier([$this, 'onDataFetch']);
103
104 return $subscriberList;
105 }
106
114 public function onDataFetch(&$fields)
115 {
116 if (isset($fields['USER_NAME']))
117 {
118 $fields['NAME'] = $fields['USER_NAME'];
119 }
120
121 if (!$fields['NAME'] && isset($fields['USER_LAST_NAME']))
122 {
123 $fields['NAME'] = $fields['USER_LAST_NAME'];
124 }
125
126 return $fields;
127 }
128
134 public function getForm()
135 {
137 '' => Loc::getMessage('sender_connector_subscriber_all'),
138 'Y' => Loc::getMessage('sender_connector_subscriber_y'),
139 'N' => Loc::getMessage('sender_connector_subscriber_n'),
140 ];
141
142 $rubricInput = '<select name="' . $this->getFieldName('RUBRIC') . '">';
143 $rubricList = RubricTable::getList([
144 'select' => ['ID', 'NAME'],
145 'order' => ['SORT' => 'ASC', 'NAME' => 'ASC'],
146 ]);
147 while ($rubric = $rubricList->fetch())
148 {
149 $inputSelected = ($rubric['ID'] == $this->getFieldValue('RUBRIC') ? 'selected' : '');
150 $rubricInput .= '<option value="' . $rubric['ID'] . '" ' . $inputSelected . '>';
151 $rubricInput .= htmlspecialcharsEx('[' . $rubric['ID'] . '] ' . $rubric['NAME']);
152 $rubricInput .= '</option>';
153 }
154 $rubricInput .= '</select>';
155
156 $activeInput = '<select name="' . $this->getFieldName('ACTIVE') . '">';
157 foreach ($dropdownValues as $k => $v)
158 {
159 $inputSelected = ($k == $this->getFieldValue('ACTIVE') ? 'selected' : '');
160 $activeInput .= '<option value="' . $k . '" ' . $inputSelected . '>';
162 $activeInput .= '</option>';
163 }
164 $activeInput .= '</select>';
165
166 $confirmedInput = '<select name="' . $this->getFieldName('CONFIRMED') . '">';
167 foreach ($dropdownValues as $k => $v)
168 {
169 $inputSelected = ($k == $this->getFieldValue('CONFIRMED') ? 'selected' : '');
170 $confirmedInput .= '<option value="' . $k . '" ' . $inputSelected . '>';
172 $confirmedInput .= '</option>';
173 }
174 $confirmedInput .= '</select>';
175
177 $this->getFieldName('DATE_INSERT_FROM'),
178 $this->getFieldValue('DATE_INSERT_FROM'),
179 $this->getFieldName('DATE_INSERT_TO'),
180 $this->getFieldValue('DATE_INSERT_TO'),
181 $this->getFieldFormName()
182 );
183
184 return '
185 <table>
186 <tr>
187 <td>' . Loc::getMessage('sender_connector_subscriber_rubric') . '</td>
188 <td>' . $rubricInput . '</td>
189 </tr>
190 <tr>
191 <td>' . Loc::getMessage('sender_connector_subscriber_active') . '</td>
192 <td>' . $activeInput . '</td>
193 </tr>
194 <tr>
195 <td>' . Loc::getMessage('sender_connector_subscriber_confirmed') . '</td>
196 <td>' . $confirmedInput . '</td>
197 </tr>
198 <tr>
199 <td>' . Loc::getMessage('sender_connector_subscriber_dateinsert') . '</td>
200 <td>' . $dateInsertInput . '</td>
201 </tr>
202 </table>
203 ';
204 }
205 }
206}
207
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29