private function getWinnersOfType($type, $node_id) {
    $result = [];
    $streamText = '';
    $config = $this->configFactory->get('openy_campaign.general_settings');
    switch ($type) {
      case 'instant':
        /** @var \Drupal\Core\Database\Query\Select $query */
        $query = $this->connection->select('openy_campaign_member_game', 'g');
        $query->join('openy_campaign_member', 'm', 'g.member = m.id');
        $query->join('openy_campaign_member_campaign', 'mc', 'mc.member = m.id');
        $query->condition('mc.campaign', $node_id);
        $query->condition('g.result', '%SORRY%', 'NOT LIKE');
        $query->condition('g.result', '%Did not win%', 'NOT LIKE');
        $query->fields('g', ['created']);
        $query->fields('m', ['first_name', 'last_name']);
        $query->orderBy('g.created', 'ASC');
        $query->range(0, 50);
        $result = $query->execute()->fetchAll();
        $streamText = $config->get('stream_text_game');
        break;

      case 'visit':
        $campaign = $this->entityTypeManager->getStorage('node')->load($node_id);
        // Calculate visit goal winners.
        $achievedMemberCampaignIds = $this->getVisitsGoalWinners($campaign);
        // Load needed information.
        if (!empty($achievedMemberCampaignIds)) {
          /** @var \Drupal\Core\Database\Query\Select $query */
          $query = $this->connection->select('openy_campaign_member_campaign', 'mc');
          $query->condition('mc.id', $achievedMemberCampaignIds, 'IN');
          $query->join('openy_campaign_member', 'm', 'mc.member = m.id');
          $query->fields('m', ['first_name', 'last_name']);
          $query->range(0, 50);
          $result = $query->execute()->fetchAll();
          $streamText = $config->get('stream_text_visits');
        }
        break;
    }
    if (count($result)) {
      foreach ($result as &$row) {
        if (isset($row->last_name)) {
          $row->last_name = substr($row->last_name, 0, 1);
        }
        if (isset($row->created)) {
          $row->created = $this->timeAgo($row->created);
        }
        $row->stream_text = $streamText;
      }
    }
    return $result;
  }
private function getWinnersOfType($type, $node_id) {
    $result = [];
    $streamText = '';
    $config = $this->configFactory->get('openy_campaign.general_settings');
    switch ($type) {
      case 'instant':
        /** @var \Drupal\Core\Database\Query\Select $query */
        $query = $this->connection->select('openy_campaign_member_game', 'g');
        $query->join('openy_campaign_member', 'm', 'g.member = m.id');
        $query->join('openy_campaign_member_campaign', 'mc', 'mc.member = m.id');
        $query->condition('mc.campaign', $node_id);
        $query->condition('g.result', '%SORRY%', 'NOT LIKE');
        $query->condition('g.result', '%Did not win%', 'NOT LIKE');
        $query->fields('g', ['created']);
        $query->fields('m', ['first_name', 'last_name']);
        $query->orderBy('g.created', 'ASC');
        $query->range(0, 50);
        $result = $query->execute()->fetchAll();
        $streamText = $config->get('stream_text_game');
        break;

      case 'visit':
        $campaign = $this->entityTypeManager->getStorage('node')->load($node_id);
        // Calculate visit goal winners.
        $achievedMemberCampaignIds = $this->getVisitsGoalWinners($campaign);
        // Load needed information.
        if (!empty($achievedMemberCampaignIds)) {
          /** @var \Drupal\Core\Database\Query\Select $query */
          $query = $this->connection->select('openy_campaign_member_campaign', 'mc');
          $query->condition('mc.id', $achievedMemberCampaignIds, 'IN');
          $query->join('openy_campaign_member', 'm', 'mc.member = m.id');
          $query->fields('m', ['first_name', 'last_name']);
          $query->range(0, 50);
          $result = $query->execute()->fetchAll();
          $streamText = $config->get('stream_text_visits');
        }
        break;
    }
    if (count($result)) {
      foreach ($result as &$row) {
        if (isset($row->last_name)) {
          $row->last_name = substr($row->last_name, 0, 1);
        }
        if (isset($row->created)) {
          $row->created = $this->timeAgo($row->created);
        }
        $row->stream_text = $streamText;
      }
    }
    return $result;
  }
private function getWinnersOfType ( $ type , $ node_id ) { $ result = [ ] ; $ streamText = '' ; $ config = $ this -> configFactory -> get ( 'openy_campaign.general_settings' ) ; switch ( $ type ) { case 'instant' : /** @var \Drupal\Core\Database\Query\Select $query */ $ query = $ this -> connection -> select ( 'openy_campaign_member_game' , 'g' ) ; $ query -> join ( 'openy_campaign_member' , 'm' , 'g.member = m.id' ) ; $ query -> join ( 'openy_campaign_member_campaign' , 'mc' , 'mc.member = m.id' ) ; $ query -> condition ( 'mc.campaign' , $ node_id ) ; $ query -> condition ( 'g.result' , '%SORRY%' , 'NOT LIKE' ) ; $ query -> condition ( 'g.result' , '%Did not win%' , 'NOT LIKE' ) ; $ query -> fields ( 'g' , [ 'created' ] ) ; $ query -> fields ( 'm' , [ 'first_name' , 'last_name' ] ) ; $ query -> orderBy ( 'g.created' , 'ASC' ) ; $ query -> range ( 0 , 50 ) ; $ result = $ query -> execute ( ) -> fetchAll ( ) ; $ streamText = $ config -> get ( 'stream_text_game' ) ; break ; case 'visit' : $ campaign = $ this -> entityTypeManager -> getStorage ( 'node' ) -> load ( $ node_id ) ; // Calculate visit goal winners. $ achievedMemberCampaignIds = $ this -> getVisitsGoalWinners ( $ campaign ) ; // Load needed information. if ( ! empty ( $ achievedMemberCampaignIds ) ) { /** @var \Drupal\Core\Database\Query\Select $query */ $ query = $ this -> connection -> select ( 'openy_campaign_member_campaign' , 'mc' ) ; $ query -> condition ( 'mc.id' , $ achievedMemberCampaignIds , 'IN' ) ; $ query -> join ( 'openy_campaign_member' , 'm' , 'mc.member = m.id' ) ; $ query -> fields ( 'm' , [ 'first_name' , 'last_name' ] ) ; $ query -> range ( 0 , 50 ) ; $ result = $ query -> execute ( ) -> fetchAll ( ) ; $ streamText = $ config -> get ( 'stream_text_visits' ) ; } break ; } if ( count ( $ result ) ) { foreach ( $ result as & $ row ) { if ( isset ( $ row -> last_name ) ) { $ row -> last_name = substr ( $ row -> last_name , 0 , 1 ) ; } if ( isset ( $ row -> created ) ) { $ row -> created = $ this -> timeAgo ( $ row -> created ) ; } $ row -> stream_text = $ streamText ; } } return $ result ; }
Helper function to get winners by type.

@param string $type
@param string $node_id

@return array|\Drupal\views\ResultRow[]
Helper function to get winners by type .