Annotations allow you to attach bits of information to entities. They are essentially the same as metadata, but with additional helper functions for performing calculations.
Inheritance: extends ElggExtender
Esempio n. 1
0
 /**
  * Listen to the creation of an annotation, if Like check auto subscribe
  *
  * @param string          $event  the name of the event
  * @param string          $type   the type of the event
  * @param \ElggAnnotation $annotation the created annotation
  *
  * @return void
  */
 public static function create($event, $type, $annotation)
 {
     if (!self::autoSubscribe()) {
         // auto subscribe isn't enabled
         return;
     }
     if (empty($annotation) || !$annotation instanceof \ElggAnnotation) {
         // not an annotation
         return;
     }
     if ($annotation->name !== 'likes') {
         // not likes
         return;
     }
     $entity = $annotation->getEntity();
     if (empty($entity) || !$entity instanceof \ElggEntity) {
         return;
     }
     $user = $annotation->getOwnerEntity();
     if (empty($user) || !$user instanceof \ElggUser) {
         return;
     }
     if (!content_subscriptions_can_subscribe($entity, $user->getGUID())) {
         // subscribing isn't allowed for this entity type/subtype
         return;
     }
     // auto subscribe to this entity
     content_subscriptions_autosubscribe($entity->getGUID(), $user->getGUID());
 }
Esempio n. 2
0
/**
 * Catch reply to discussion topic and generate notifications
 *
 * @todo this will be replaced in Elgg 1.9 and is a clone of object_notifications()
 *
 * @param string         $event
 * @param string         $type
 * @param ElggAnnotation $annotation
 * @return void
 */
function discussion_reply_notifications($event, $type, $annotation)
{
    global $CONFIG, $NOTIFICATION_HANDLERS;
    if ($annotation->name !== 'group_topic_post') {
        return;
    }
    // Have we registered notifications for this type of entity?
    $object_type = 'object';
    $object_subtype = 'groupforumtopic';
    $topic = $annotation->getEntity();
    if (!$topic) {
        return;
    }
    $poster = $annotation->getOwnerEntity();
    if (!$poster) {
        return;
    }
    if (isset($CONFIG->register_objects[$object_type][$object_subtype])) {
        $subject = $CONFIG->register_objects[$object_type][$object_subtype];
        $string = $subject . ": " . $topic->getURL();
        // Get users interested in content from this person and notify them
        // (Person defined by container_guid so we can also subscribe to groups if we want)
        foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
            $interested_users = elgg_get_entities_from_relationship(array('relationship' => 'notify' . $method, 'relationship_guid' => $topic->getContainerGUID(), 'inverse_relationship' => true, 'type' => 'user', 'limit' => 0));
            if ($interested_users && is_array($interested_users)) {
                foreach ($interested_users as $user) {
                    if ($user instanceof ElggUser && !$user->isBanned()) {
                        if ($user->guid != $poster->guid && has_access_to_entity($topic, $user) && $topic->access_id != ACCESS_PRIVATE) {
                            $body = elgg_trigger_plugin_hook('notify:annotation:message', $annotation->getSubtype(), array('annotation' => $annotation, 'to_entity' => $user, 'method' => $method), $string);
                            if (empty($body) && $body !== false) {
                                $body = $string;
                            }
                            if ($body !== false) {
                                notify_user($user->guid, $topic->getContainerGUID(), $subject, $body, null, array($method));
                            }
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 3
0
/**
 * View an item in a list
 *
 * @param ElggEntity|ElggAnnotation $item
 * @param array  $vars Additional parameters for the rendering
 *
 * @return string
 * @since 1.8.0
 * @access private
 */
function elgg_view_list_item($item, array $vars = array())
{
    global $CONFIG;
    $type = $item->getType();
    if (in_array($type, $CONFIG->entity_types)) {
        return elgg_view_entity($item, $vars);
    } else {
        if ($type == 'annotation') {
            return elgg_view_annotation($item, $vars);
        } else {
            if ($type == 'river') {
                return elgg_view_river_item($item, $vars);
            }
        }
    }
    return '';
}
/**
 * Return the URL for a comment
 *
 * @param ElggAnnotation $comment The comment object 
 * @return string
 * @access private
 */
function elgg_comment_url_handler(ElggAnnotation $comment)
{
    $entity = $comment->getEntity();
    if ($entity) {
        return $entity->getURL() . '#item-annotation-' . $comment->id;
    }
}
Esempio n. 5
0
/**
 * Log the groups a user was invited for
 *
 * @param string $event
 * @param string $type
 * @param ElggAnnotation $object
 */
function subsite_manager_delete_annotation_handler($event, $type, $object)
{
    if (!empty($object) && $object instanceof ElggAnnotation) {
        if ($object->name == "email_invitation") {
            global $SUBSITE_MANAGER_INVITED_GROUPS;
            if (!isset($SUBSITE_MANAGER_INVITED_GROUPS)) {
                $SUBSITE_MANAGER_INVITED_GROUPS = array();
            }
            $SUBSITE_MANAGER_INVITED_GROUPS[] = $object->getOwnerGUID();
        }
    }
}
Esempio n. 6
0
/**
 * Update annotation event
 *
 * @param string         $event      "create"|"update"
 * @param string         $type       "annotation"
 * @param ElggAnnotation $annotation Annotation
 * @return void
 */
function elgg_solr_annotation_update($event, $type, $annotation)
{
    $entity = $annotation->getEntity();
    if ($GLOBALS['shutdown_flag']) {
        elgg_solr_add_update_entity(null, null, $entity);
        elgg_solr_index_annotation($annotation);
    } else {
        elgg_solr_defer_index_update($entity->guid);
        elgg_solr_defer_annotation_update($annotation->id);
    }
}