Ejemplo n.º 1
0
/**
 * Check if a user is subscribed to a container entity
 *
 * @param ElggUser   $user   The user to check
 * @param ElggEntity $entity The container entity to check against
 *
 * @return boolean True => the user has a subscription, false => no subscription or error
 */
function newsletter_check_user_subscription(ElggUser $user, ElggEntity $entity)
{
    $result = false;
    if (!empty($user) && !empty($entity)) {
        if (elgg_instanceof($user, "user") && (elgg_instanceof($entity, "site") || elgg_instanceof($entity, "group"))) {
            // include all users
            if (newsletter_include_existing_users()) {
                // exclude if blocked
                $result = !(bool) check_entity_relationship($user->getGUID(), NewsletterSubscription::BLACKLIST, $entity->getGUID());
            } else {
                // only if opt-in
                $result = (bool) check_entity_relationship($user->getGUID(), NewsletterSubscription::SUBSCRIPTION, $entity->getGUID());
            }
        }
    }
    return $result;
}
Ejemplo n.º 2
0
/**
 * Check if a user is subscribed to a container entity
 *
 * @param ElggUser   $user   The user to check
 * @param ElggEntity $entity The container entity to check against
 *
 * @return boolean True => the user has a subscription, false => no subscription or error
 */
function newsletter_check_user_subscription(ElggUser $user, ElggEntity $entity)
{
    if (!elgg_instanceof($user, 'user')) {
        return false;
    }
    if (!elgg_instanceof($entity, 'site') && !elgg_instanceof($entity, 'group')) {
        return false;
    }
    // include all users
    if (newsletter_include_existing_users()) {
        // exclude if blocked
        return !(bool) check_entity_relationship($user->getGUID(), NewsletterSubscription::BLACKLIST, $entity->getGUID());
    } else {
        // only if opt-in
        return (bool) check_entity_relationship($user->getGUID(), NewsletterSubscription::SUBSCRIPTION, $entity->getGUID());
    }
}