Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vgrish
Created March 12, 2017 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrish/8e843f4673db25f1852198bc36fdd327 to your computer and use it in GitHub Desktop.
Save vgrish/8e843f4673db25f1852198bc36fdd327 to your computer and use it in GitHub Desktop.
<?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