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
/**
 * Make sure we can autosubscribe the user to further updates
 *
 * @param string     $event  "create"
 * @param string     $type   "object"
 * @param ElggObject $object the created annotation
 *
 * @return void
 */
function content_subscriptions_create_object_handler($event, $type, ElggObject $object)
{
    if (!empty($object) && (elgg_instanceof($object, "object", "discussion_reply") || elgg_instanceof($object, "object", "comment"))) {
        $owner = $object->getOwnerEntity();
        $entity = $object->getContainerEntity();
        // add auto subscription for this user
        content_subscriptions_autosubscribe($entity->getGUID(), $owner->getGUID());
    }
}
Esempio n. 3
0
 /**
  * Make sure we can autosubscribe the user to further updates
  *
  * @param string     $event  the name of the event
  * @param string     $type   the type of the event
  * @param ElggObject $object the created comment
  *
  * @return void
  */
 public static function createObject($event, $type, \ElggObject $object)
 {
     if (!$object instanceof \ElggComment) {
         return;
     }
     $owner = $object->getOwnerEntity();
     $entity = $object->getContainerEntity();
     // add auto subscription for this user
     content_subscriptions_autosubscribe($entity->getGUID(), $owner->getGUID());
 }
Esempio n. 4
0
 /**
  * Subscribe to a question when you create a comment on an answer
  *
  * @param string      $event
  * @param string      $type
  * @param \ElggObject $object
  *
  * @return void
  */
 public static function createCommentOnAnswer($event, $type, \ElggObject $object)
 {
     if (!elgg_is_active_plugin('content_subscriptions')) {
         return;
     }
     if (!$object instanceof \ElggComment) {
         return;
     }
     $answer = $object->getContainerEntity();
     if (!$answer instanceof \ElggAnswer) {
         return;
     }
     $owner = $object->getOwnerEntity();
     $question = $answer->getContainerEntity();
     if (!content_subscriptions_can_subscribe($question, $owner->getGUID())) {
         return;
     }
     // subscribe to the question
     content_subscriptions_autosubscribe($question->getGUID(), $owner->getGUID());
 }