private function getCampaignWinners($campaignId, $branchId) {
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $this->connection->select('openy_campaign_winner', 'w');
    $query->join('openy_campaign_member_campaign', 'mc', 'mc.id = w.member_campaign');
    $query->condition('mc.campaign', $campaignId);
    $query->join('openy_campaign_member', 'm', 'm.id = mc.member');
    $query->condition('m.branch', $branchId);
    $query->condition('m.is_employee', FALSE);
    $query->fields('m', ['id', 'first_name', 'last_name', 'membership_id']);
    $query->fields('w', ['place']);
    $query->addField('mc', 'id', 'member_campaign');
    $results = $query->execute()->fetchAll();

    $winners = [];
    foreach ($results as $item) {
      $lastNameLetter = !empty($item->last_name) ? ' ' . strtoupper($item->last_name[0]) : '';

      $winners[$item->place][] = [
        'member_id' => $item->id,
        'member_campaign_id' => $item->member_campaign,
        'name' => $item->first_name . $lastNameLetter,
        'membership_id' => substr($item->membership_id, -4),
      ];
    }

    return $winners;
  }
private function getCampaignWinners($campaignId, $branchId) {
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $this->connection->select('openy_campaign_winner', 'w');
    $query->join('openy_campaign_member_campaign', 'mc', 'mc.id = w.member_campaign');
    $query->condition('mc.campaign', $campaignId);
    $query->join('openy_campaign_member', 'm', 'm.id = mc.member');
    $query->condition('m.branch', $branchId);
    $query->condition('m.is_employee', FALSE);
    $query->fields('m', ['id', 'first_name', 'last_name', 'membership_id']);
    $query->fields('w', ['place']);
    $query->addField('mc', 'id', 'member_campaign');
    $results = $query->execute()->fetchAll();

    $winners = [];
    foreach ($results as $item) {
      $lastNameLetter = !empty($item->last_name) ? ' ' . strtoupper($item->last_name[0]) : '';

      $winners[$item->place][] = [
        'member_id' => $item->id,
        'member_campaign_id' => $item->member_campaign,
        'name' => $item->first_name . $lastNameLetter,
        'membership_id' => substr($item->membership_id, -4),
      ];
    }

    return $winners;
  }
private function getCampaignWinners ( $ campaignId , $ branchId ) { /** @var \Drupal\Core\Database\Query\Select $query */ $ query = $ this -> connection -> select ( 'openy_campaign_winner' , 'w' ) ; $ query -> join ( 'openy_campaign_member_campaign' , 'mc' , 'mc.id = w.member_campaign' ) ; $ query -> condition ( 'mc.campaign' , $ campaignId ) ; $ query -> join ( 'openy_campaign_member' , 'm' , 'm.id = mc.member' ) ; $ query -> condition ( 'm.branch' , $ branchId ) ; $ query -> condition ( 'm.is_employee' , FALSE ) ; $ query -> fields ( 'm' , [ 'id' , 'first_name' , 'last_name' , 'membership_id' ] ) ; $ query -> fields ( 'w' , [ 'place' ] ) ; $ query -> addField ( 'mc' , 'id' , 'member_campaign' ) ; $ results = $ query -> execute ( ) -> fetchAll ( ) ; $ winners = [ ] ; foreach ( $ results as $ item ) { $ lastNameLetter = ! empty ( $ item -> last_name ) ? ' ' . strtoupper ( $ item -> last_name [ 0 ] ) : '' ; $ winners [ $ item -> place ] [ ] = [ 'member_id' => $ item -> id , 'member_campaign_id' => $ item -> member_campaign , 'name' => $ item -> first_name . $ lastNameLetter , 'membership_id' => substr ( $ item -> membership_id , - 4 ) , ] ; } return $ winners ; }
Get all winners of current Campaign by branch.

@param $campaignId
@param $branchId

@return array
Get all winners of current Campaign by branch .