Example #1
0
$current_user = elgg_get_logged_in_user_entity();
$guid = (int) get_input('guid', 0);
if (!$guid || !($user = get_entity($guid))) {
    forward();
}
if ($user->guid != $current_user->guid && !$current_user->isAdmin()) {
    forward();
}
// Get group memberships and condense them down to an array of guids
$groups = array();
$options = array('relationship' => 'member', 'relationship_guid' => $user->guid, 'type' => 'group', 'limit' => false);
if ($groupmemberships = elgg_get_entities_from_relationship($options)) {
    foreach ($groupmemberships as $groupmembership) {
        $groups[] = $groupmembership->guid;
    }
}
if (!empty($groups)) {
    $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
    foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
        $subscriptions[$method] = get_input($method . 'subscriptions', array());
        foreach ($groups as $group) {
            if (in_array($group, $subscriptions[$method])) {
                elgg_add_subscription($user->guid, $method, $group);
            } else {
                elgg_remove_subscription($user->guid, $method, $group);
            }
        }
    }
}
system_message(elgg_echo('notifications:subscriptions:success'));
forward(REFERER);
Example #2
0
<?php

/**
 * Saves subscription record notification settings
 */
$guid = get_input('guid');
$user = get_entity($guid);
if (!$user || !$user->canEdit()) {
    register_error(elgg_echo('actionnotauthorized'));
    forward('', '403');
}
$methods = elgg_get_notification_methods();
if (empty($methods)) {
    forward(REFERRER, '404');
}
$subscriptions = (array) get_input('subscriptions', []);
foreach ($subscriptions as $target_guid => $preferred_methods) {
    if (!is_array($preferred_methods)) {
        $preferred_methods = [];
    }
    foreach ($methods as $method) {
        if (in_array($method, $preferred_methods)) {
            elgg_add_subscription($user->guid, $method, $target_guid);
        } else {
            elgg_remove_subscription($user->guid, $method, $target_guid);
        }
    }
}
system_message(elgg_echo('notifications:subscriptions:success'));
Example #3
0
}
$options = ['type' => 'user', 'relationship' => 'member', 'relationship_guid' => $group->getGUID(), 'inverse_relationship' => true, 'limit' => false];
$members = new ElggBatch('elgg_get_entities_from_relationship', $options);
switch ($toggle) {
    case 'enable':
        // fix notifications settings for site amd email
        $auto_notification_handlers = ['site', 'email'];
        // enable notification for everyone
        foreach ($members as $member) {
            foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                if (in_array($method, $auto_notification_handlers)) {
                    elgg_add_subscription($member->getGUID(), $method, $group->getGUID());
                }
            }
        }
        system_message(elgg_echo('group_tools:action:notifications:success:enable'));
        break;
    case 'disable':
        // disable notification for everyone
        foreach ($members as $member) {
            foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                elgg_remove_subscription($member->getGUID(), $method, $group->getGUID());
            }
        }
        system_message(elgg_echo('group_tools:action:notifications:success:disable'));
        break;
    default:
        register_error(elgg_echo('group_tools:action:notifications:error:toggle'));
        break;
}
forward($group->getURL());
/**
 * Unsubscribe a user from updates and set a flag so auto updates don't recreate the updates
 *
 * @param int $entity_guid the content entity to unsubscribe from
 * @param int $user_guid   the user to unsubscribe (defaults to current user)
 *
 * @return bool
 */
function content_subscriptions_unsubscribe($entity_guid, $user_guid = 0)
{
    $entity_guid = sanitise_int($entity_guid, false);
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($entity_guid) || empty($user_guid)) {
        return false;
    }
    // check if we have a subscription
    $sub = content_subscriptions_check_subscription($entity_guid, $user_guid, true);
    // make sure we can't autosubscribe
    add_entity_relationship($user_guid, CONTENT_SUBSCRIPTIONS_BLOCK, $entity_guid);
    // quick return if no subscriptions
    if (empty($sub)) {
        return true;
    }
    // remove subscriptions
    foreach ($sub as $service) {
        elgg_remove_subscription($user_guid, $service, $entity_guid);
    }
    return true;
}
Example #5
0
File: start.php Project: elgg/elgg
/**
 * Update notifications when a relationship is deleted
 *
 * @param string            $event        "delete"
 * @param string            $object_type  "relationship"
 * @param \ElggRelationship $relationship Relationship obj
 * @return void
 */
function notifications_relationship_remove($event, $object_type, $relationship)
{
    if (!in_array($relationship->relationship, ['member', 'friend'])) {
        return;
    }
    $methods = array_keys(_elgg_services()->notifications->getMethodsAsDeprecatedGlobal());
    foreach ($methods as $method) {
        elgg_remove_subscription($relationship->guid_one, $method, $relationship->guid_two);
    }
}