protected function buildAggregatedActivites($data, $activity_fields) {
    $activities = [];
    $common_destinations = $this->activityDestinationManager->getListByProperties('isCommon', TRUE);
    $personal_destinations = $this->activityDestinationManager->getListByProperties('isCommon', FALSE);

    // Get related activities.
    $related_activities = $this->getAggregationRelatedActivities($data);
    if (!empty($related_activities)) {
      // Update related activities.
      foreach ($related_activities as $related_activity) {
        $destination = $related_activity->field_activity_destinations->value;
        // If user already have related activity we remove it and create new.
        // And we also remove related activities from common streams.
        if ($related_activity->getOwnerId() == $this->getActor($data) || in_array($destination, $common_destinations)) {
          // @TODO: Consider if need to delete or unpublish old activites.
          $related_activity->delete();
        }
        else {
          // For other users we leave activity only on their profile stream.
          $related_activity->set('field_activity_destinations', ['stream_profile']);
          $related_activity->save();
        }
      }

      // Clone activity fields for separate profile stream activity.
      $profile_activity_fields = $activity_fields;

      // Update output text for activity on not user related streams.
      $arguments = [];
      $message = Message::load($data['mid']);
      $count = $this->getAggregationAuthorsCount($data);
      if (is_numeric($count) && $count > 1) {
        $arguments = ['@count' => $count - 1];
      }
      $activity_fields['field_activity_output_text'] = $this->getFieldOutputText($message, $arguments);
      $activity_fields['field_activity_destinations'] = $this->getFieldDestinations($data, $common_destinations);

      // Create separate activity for activity on user related streams.
      $profile_activity_fields['field_activity_destinations'] = $this->getFieldDestinations($data, $personal_destinations);
      $activity = Activity::create($profile_activity_fields);
      $activity->save();
      $activities[] = $activity;
    }

    $activity = Activity::create($activity_fields);
    $activity->save();
    $activities[] = $activity;

    return $activities;
  }
protected function buildAggregatedActivites($data, $activity_fields) {
    $activities = [];
    $common_destinations = $this->activityDestinationManager->getListByProperties('isCommon', TRUE);
    $personal_destinations = $this->activityDestinationManager->getListByProperties('isCommon', FALSE);

    // Get related activities.
    $related_activities = $this->getAggregationRelatedActivities($data);
    if (!empty($related_activities)) {
      // Update related activities.
      foreach ($related_activities as $related_activity) {
        $destination = $related_activity->field_activity_destinations->value;
        // If user already have related activity we remove it and create new.
        // And we also remove related activities from common streams.
        if ($related_activity->getOwnerId() == $this->getActor($data) || in_array($destination, $common_destinations)) {
          // @TODO: Consider if need to delete or unpublish old activites.
          $related_activity->delete();
        }
        else {
          // For other users we leave activity only on their profile stream.
          $related_activity->set('field_activity_destinations', ['stream_profile']);
          $related_activity->save();
        }
      }

      // Clone activity fields for separate profile stream activity.
      $profile_activity_fields = $activity_fields;

      // Update output text for activity on not user related streams.
      $arguments = [];
      $message = Message::load($data['mid']);
      $count = $this->getAggregationAuthorsCount($data);
      if (is_numeric($count) && $count > 1) {
        $arguments = ['@count' => $count - 1];
      }
      $activity_fields['field_activity_output_text'] = $this->getFieldOutputText($message, $arguments);
      $activity_fields['field_activity_destinations'] = $this->getFieldDestinations($data, $common_destinations);

      // Create separate activity for activity on user related streams.
      $profile_activity_fields['field_activity_destinations'] = $this->getFieldDestinations($data, $personal_destinations);
      $activity = Activity::create($profile_activity_fields);
      $activity->save();
      $activities[] = $activity;
    }

    $activity = Activity::create($activity_fields);
    $activity->save();
    $activities[] = $activity;

    return $activities;
  }
protected function buildAggregatedActivites ( $ data , $ activity_fields ) { $ activities = [ ] ; $ common_destinations = $ this -> activityDestinationManager -> getListByProperties ( 'isCommon' , TRUE ) ; $ personal_destinations = $ this -> activityDestinationManager -> getListByProperties ( 'isCommon' , FALSE ) ; // Get related activities. $ related_activities = $ this -> getAggregationRelatedActivities ( $ data ) ; if ( ! empty ( $ related_activities ) ) { // Update related activities. foreach ( $ related_activities as $ related_activity ) { $ destination = $ related_activity -> field_activity_destinations -> value ; // If user already have related activity we remove it and create new. // And we also remove related activities from common streams. if ( $ related_activity -> getOwnerId ( ) == $ this -> getActor ( $ data ) || in_array ( $ destination , $ common_destinations ) ) { // @TODO: Consider if need to delete or unpublish old activites. $ related_activity -> delete ( ) ; } else { // For other users we leave activity only on their profile stream. $ related_activity -> set ( 'field_activity_destinations' , [ 'stream_profile' ] ) ; $ related_activity -> save ( ) ; } } // Clone activity fields for separate profile stream activity. $ profile_activity_fields = $ activity_fields ; // Update output text for activity on not user related streams. $ arguments = [ ] ; $ message = Message :: load ( $ data [ 'mid' ] ) ; $ count = $ this -> getAggregationAuthorsCount ( $ data ) ; if ( is_numeric ( $ count ) && $ count > 1 ) { $ arguments = [ '@count' => $ count - 1 ] ; } $ activity_fields [ 'field_activity_output_text' ] = $ this -> getFieldOutputText ( $ message , $ arguments ) ; $ activity_fields [ 'field_activity_destinations' ] = $ this -> getFieldDestinations ( $ data , $ common_destinations ) ; // Create separate activity for activity on user related streams. $ profile_activity_fields [ 'field_activity_destinations' ] = $ this -> getFieldDestinations ( $ data , $ personal_destinations ) ; $ activity = Activity :: create ( $ profile_activity_fields ) ; $ activity -> save ( ) ; $ activities [ ] = $ activity ; } $ activity = Activity :: create ( $ activity_fields ) ; $ activity -> save ( ) ; $ activities [ ] = $ activity ; return $ activities ; }
Build the aggregated activities based on a data array.
Build the aggregated activities based on a data array .