Skip to content

Instantly share code, notes, and snippets.

@SergeyZaigraev
Created May 15, 2017 06:39
Show Gist options
  • Save SergeyZaigraev/fbc7e038b99e902c10ef8cc39aa4faa5 to your computer and use it in GitHub Desktop.
Save SergeyZaigraev/fbc7e038b99e902c10ef8cc39aa4faa5 to your computer and use it in GitHub Desktop.
Trigger for Email distribution. Пример собственного триггера.
<?
class SenderTriggerUserGroup extends \Bitrix\Sender\Trigger {
public function getName() {
return 'Первый заход на сайт (+группа)';
}
public function getCode() {
return "user_group";
}
public function getEventModuleId() {
return 'main';
}
public function getEventType() {
return "OnAfterUserAuthorize";
}
public function getRecipient() {
$event = $this->getParam('EVENT');
$user = $event[0]['user_fields'];
return array('NAME' => $user['NAME'],
'EMAIL' => $user['EMAIL'],
'USER_ID' => $user['ID']
);
}
public function filter() {
$groupID = $this->getFieldValue('GROUP');
$event = $this->getParam('EVENT');
$user = $event[0]['user_fields'];
$chain = $this->getParam('CHAIN');
$dbUsers = CUser::GetList(
$by = "ID",
$order = "desc",
array(
"ID" => $user['ID'],
"GROUPS_ID" => array($groupID),
),
array(
"SELECT"=>
array(
"UF_TRIGGERS_SEND"
),
)
);
if($arUser = $dbUsers->Fetch()) {
if(!is_array($arUser['UF_TRIGGERS_SEND']))
$arUser['UF_TRIGGERS_SEND'] = array();
if(in_array($chain['MAILING_ID'],$arUser['UF_TRIGGERS_SEND'])){
return false;
}
$u = new CUser;
$arUser['UF_TRIGGERS_SEND'][] = $chain['MAILING_ID'];
$u->Update($user['ID'], array(
"UF_TRIGGERS_SEND" => $arUser['UF_TRIGGERS_SEND']
));
return true;
} else {
return false;
}
}
public function getForm() {
$selectedID = $this->getFieldValue('GROUP');
ob_start();
?>
<table>
<tr>
<td>Группа:</td>
<td>
<select style="max-width:400px" name="<?=$this->getFieldName('GROUP'); ?>">
<option value="">(любая)</option>
<?
$res = CGroup::GetList(($by = 'c_sort'), ($dir = 'asc'), array());
while($r = $res->fetch()) {
echo '<option value="' . $r['ID'] . '"' . ($selectedID == $r['ID'] ? '
selected="selected"' : '') . '>' . $r['NAME'] . '</option>';
}
?>
</select>
</td>
</tr>
</table>
<?
return ob_get_clean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment