Esempio n. 1
0
 /**
  * Prevent subscribers for the tag notifications
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param array  $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void|array
  */
 public static function getSubscribers($hook, $type, $return_value, $params)
 {
     if (!self::validateNotificationEvent($params)) {
         // not the correct notification event
         return;
     }
     /* @var $event \Elgg\Notifications\Event */
     $event = elgg_extract('event', $params);
     /* @var $relationship \ElggRelationship */
     $relationship = $event->getObject();
     $entity = get_entity($relationship->guid_two);
     $sending_tags = tag_tools_get_unsent_tags($entity);
     if (empty($sending_tags)) {
         return [];
     }
     $tag_subscribers = [];
     // get interested users
     $user_options = ['type' => 'user', 'annotation_name_value_pairs' => ['name' => 'follow_tag', 'value' => $sending_tags], 'limit' => false];
     $users_batch = new \ElggBatch('elgg_get_entities_from_annotations', $user_options);
     /* @var $user \ElggUser */
     foreach ($users_batch as $user) {
         // check user access
         if (!has_access_to_entity($entity, $user)) {
             continue;
         }
         // get the notification settings of the user for one of the sending tags
         // this will prevent duplicate notifications,
         foreach ($sending_tags as $tag) {
             if (!tag_tools_is_user_following_tag($tag, $user->getGUID())) {
                 // user is not following this tag, check the next
                 continue;
             }
             $notifiction_settings = tag_tools_get_user_tag_notification_settings($tag, $user->getGUID());
             if (empty($notifiction_settings)) {
                 // no notification settings for this tag
                 continue;
             }
             if (isset($tag_subscribers[$user->getGUID()])) {
                 $tag_subscribers[$user->getGUID()] = array_merge($tag_subscribers[$user->getGUID()], $notifiction_settings);
                 $tag_subscribers[$user->getGUID()] = array_unique($tag_subscribers[$user->getGUID()]);
             } else {
                 $tag_subscribers[$user->getGUID()] = $notifiction_settings;
             }
         }
     }
     if (!empty($tag_subscribers)) {
         return $tag_subscribers;
     }
     return [];
 }
Esempio n. 2
0
/**
 * Check if a user has selected the notification method for a tag
 *
 * @param string $tag       the tag to check
 * @param string $method    the notification method to check
 * @param int    $user_guid the user to check for (default: current user)
 *
 * @return bool
 */
function tag_tools_check_user_tag_notification_method($tag, $method, $user_guid = 0)
{
    if (empty($tag)) {
        return false;
    }
    if (empty($method)) {
        return false;
    }
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return false;
    }
    $tag_settings = tag_tools_get_user_tag_notification_settings($tag, $user_guid);
    if (empty($tag_settings)) {
        // user has disabled notifications for this tag
        return false;
    }
    // check if the user has selected the notification method
    return in_array($method, $tag_settings);
}