Created
March 12, 2017 09:50
-
-
Save vgrish/8e843f4673db25f1852198bc36fdd327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @var array $scriptProperties */ | |
if ($modx->event->name != "psOnSubscriptionSave") { | |
return; | |
} | |
$mode = $modx->getOption('mode', $scriptProperties); | |
$subscription = $modx->getOption('subscription', $scriptProperties); | |
if (!$subscription) { | |
return; | |
} | |
/* проверяем подписной ресурс */ | |
$rid = $subscription->get('resource_id'); | |
if ($rid != 33) { | |
return; | |
} | |
$uid = $subscription->get('user_id'); | |
/** @var modUser $user */ | |
$user = $modx->getObject('modUser', $uid); | |
if (!$user) { | |
return; | |
} | |
$active = $subscription->get('active'); | |
switch (true) { | |
/* если подписка новая */ | |
case $mode == modSystemEvent::MODE_NEW: | |
/* если подписка активна */ | |
case !empty($active): | |
$user->joinGroup('NoAd'); | |
break; | |
/* если подписка неактивна */ | |
case empty($active): | |
$user->leaveGroup('NoAd'); | |
break; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment