S
S
SpeakeazyYT22018-07-05 15:03:26
1C-Bitrix
SpeakeazyYT2, 2018-07-05 15:03:26

How to update the activity period of being in a user's group in automatic mode if a request is sent to add to groups from the lane. Act.???

How to update the activity period of being in a user's group in automatic mode if a request is sent to add to groups from the lane. Act.??? I'm doing now adding a user to a group with a period of activity. You need to do this, if a person is already in this group and the activity period of being in this group is registered and a request is sent to re-add this person to this group with a different activity period, then the old data of the activity period was overwritten with new ones. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2018-07-06
@SpeakeazyYT2

Everything is simple here:

$user_id = 2;

$arGroups_db = CUser::GetUserGroupList( $user_id );

$aimGroupId = 4; //id группы, куда добавляем
$aimGroupLastDate = '09.05.2018 23:59:59'; // дата, которая нужна, если из какой-то переменной в timestamp, то используйте ConvertTimeStamp($var, "FULL"), она приведёт формат к текущему формату базы битрикса
$aimGroupUpdated = false;

while ($arGroup = $arGroups_db->Fetch()){

    if ($arGroup['GROUP_ID'] == $aimGroupId) {
        $arGroup['DATE_ACTIVE_TO'] = $aimGroupLastDate;
        $aimGroupUpdated = true;
    }

    $arGroups[] = $arGroup;
}

if (!$aimGroupUpdated) {
    $arGroups[] = [
        'GROUP_ID' => $aimGroupId,
        'DATE_ACTIVE_FROM' => ConvertTimeStamp(time(), "FULL"),
        'DATE_ACTIVE_TO' => $aimGroupLastDate
    ];
}

CUser::SetUserGroup($user_id, $arGroups);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question