public function updateMentionsFromBody(AnCommandContext $context)
    {
        $entity = $this->getItem();
        $body_mentions = $this->extractMentions($entity->body);
        $body_mentions = array_map('strtolower', $body_mentions);

        // @todo we should be accessing username, but for now we are using alias
        // until the design in the domain entities is improved
        $entity_mentions = AnConfig::unbox($entity->mentions->alias);

        if (is_array($entity_mentions)) {
            $entity_mentions = array_map('strtolower', $entity_mentions);
        }

        //update removed mentions
      if (is_array($body_mentions)) {
          foreach ($entity_mentions as $mention) {
              if (! in_array($mention, $body_mentions)) {
                  $entity->removeMention($mention);
              }
          }
      }

       //remove the body mentions that already exists in the entity mentions
      if (is_array($entity_mentions)) {
          foreach ($body_mentions as $index => $mention) {
              if (in_array($mention, $entity_mentions)) {
                  unset($body_mentions[$index]);
              }
          }
      }

       //what's left are new mentions. Add them to the entity.
       foreach ($body_mentions as $mention) {
           $entity->addMention(trim($mention));
       }

        //keep the list of new mentions so you can notify them later.
        $this->_newly_mentioned = $body_mentions;
    }
public function updateMentionsFromBody(AnCommandContext $context)
    {
        $entity = $this->getItem();
        $body_mentions = $this->extractMentions($entity->body);
        $body_mentions = array_map('strtolower', $body_mentions);

        // @todo we should be accessing username, but for now we are using alias
        // until the design in the domain entities is improved
        $entity_mentions = AnConfig::unbox($entity->mentions->alias);

        if (is_array($entity_mentions)) {
            $entity_mentions = array_map('strtolower', $entity_mentions);
        }

        //update removed mentions
      if (is_array($body_mentions)) {
          foreach ($entity_mentions as $mention) {
              if (! in_array($mention, $body_mentions)) {
                  $entity->removeMention($mention);
              }
          }
      }

       //remove the body mentions that already exists in the entity mentions
      if (is_array($entity_mentions)) {
          foreach ($body_mentions as $index => $mention) {
              if (in_array($mention, $entity_mentions)) {
                  unset($body_mentions[$index]);
              }
          }
      }

       //what's left are new mentions. Add them to the entity.
       foreach ($body_mentions as $mention) {
           $entity->addMention(trim($mention));
       }

        //keep the list of new mentions so you can notify them later.
        $this->_newly_mentioned = $body_mentions;
    }
public function updateMentionsFromBody ( AnCommandContext $ context ) { $ entity = $ this -> getItem ( ) ; $ body_mentions = $ this -> extractMentions ( $ entity -> body ) ; $ body_mentions = array_map ( 'strtolower' , $ body_mentions ) ; // @todo we should be accessing username, but for now we are using alias // until the design in the domain entities is improved $ entity_mentions = AnConfig :: unbox ( $ entity -> mentions -> alias ) ; if ( is_array ( $ entity_mentions ) ) { $ entity_mentions = array_map ( 'strtolower' , $ entity_mentions ) ; } //update removed mentions if ( is_array ( $ body_mentions ) ) { foreach ( $ entity_mentions as $ mention ) { if ( ! in_array ( $ mention , $ body_mentions ) ) { $ entity -> removeMention ( $ mention ) ; } } } //remove the body mentions that already exists in the entity mentions if ( is_array ( $ entity_mentions ) ) { foreach ( $ body_mentions as $ index => $ mention ) { if ( in_array ( $ mention , $ entity_mentions ) ) { unset ( $ body_mentions [ $ index ] ) ; } } } //what's left are new mentions. Add them to the entity. foreach ( $ body_mentions as $ mention ) { $ entity -> addMention ( trim ( $ mention ) ) ; } //keep the list of new mentions so you can notify them later. $ this -> _newly_mentioned = $ body_mentions ; }
Extracts mention usernames from the entity body and updates the entity.

@param AnCommandContext $context

@return bool
Extracts mention usernames from the entity body and updates the entity .