You are here

public function HeartbeatStreamServices::createHashStreamForUidsByType in Heartbeat 8

File

src/HeartbeatStreamServices.php, line 282

Class

HeartbeatStreamServices
Class HeartbeatStreamServices.

Namespace

Drupal\heartbeat

Code

public function createHashStreamForUidsByType($uids, $type, $tid) {
  $query = $this->database
    ->query('
      SELECT id
      FROM heartbeat_field_revision hr
      INNER JOIN node n ON n.nid = hr.nid
      INNER JOIN node__field_tags fu ON fu.entity_id = n.nid
      WHERE fu.field_tags_target_id = :tid', array(
    ':tid' => $tid,
  ));
  $hids = array();
  foreach ($query
    ->fetchAll() as $id) {
    $hids[] = $id->id;
  }
  if (!empty($hids)) {
    $beats = $this->entityTypeManager
      ->getStorage('heartbeat')
      ->loadMultiple($this->entityQuery
      ->get('heartbeat')
      ->condition('status', 1)
      ->condition('uid', $uids, 'IN')
      ->condition('id', $hids, 'IN')
      ->sort('created', 'DESC')
      ->execute());
    if (count($beats) > 0) {
      $this->lastId = call_user_func('end', array_keys($beats));
      $this->configFactory
        ->getEditable('heartbeat_update_feed.settings')
        ->set('lastId', $this->lastId)
        ->set('update', FALSE)
        ->set('timestamp', array_values($beats)[0]
        ->getRevisionCreationTime())
        ->save();
      return $beats;
    }
  }
  return null;
}