public static function deleteWinners($campaignId, $isAll = TRUE) {
    $connection = \Drupal::service('database');
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $connection->select('openy_campaign_winner', 'w');
    $query->fields('w', ['id']);
    $query->join('openy_campaign_member_campaign', 'mc', 'w.member_campaign = mc.id');

    // Delete only winners with defined activity.
    if (!$isAll) {
      $query->condition('w.activity', 0, '!=');
    }
    $query->condition('mc.campaign', $campaignId);

    $winnerIDs = $query->execute()->fetchCol();

    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
    $storage = \Drupal::service('entity_type.manager')->getStorage('openy_campaign_winner');
    $winners = $storage->loadMultiple($winnerIDs);
    $storage->delete($winners);
  }
public static function deleteWinners($campaignId, $isAll = TRUE) {
    $connection = \Drupal::service('database');
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $connection->select('openy_campaign_winner', 'w');
    $query->fields('w', ['id']);
    $query->join('openy_campaign_member_campaign', 'mc', 'w.member_campaign = mc.id');

    // Delete only winners with defined activity.
    if (!$isAll) {
      $query->condition('w.activity', 0, '!=');
    }
    $query->condition('mc.campaign', $campaignId);

    $winnerIDs = $query->execute()->fetchCol();

    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
    $storage = \Drupal::service('entity_type.manager')->getStorage('openy_campaign_winner');
    $winners = $storage->loadMultiple($winnerIDs);
    $storage->delete($winners);
  }
public static function deleteWinners ( $ campaignId , $ isAll = TRUE ) { $ connection = \ Drupal :: service ( 'database' ) ; /** @var \Drupal\Core\Database\Query\Select $query */ $ query = $ connection -> select ( 'openy_campaign_winner' , 'w' ) ; $ query -> fields ( 'w' , [ 'id' ] ) ; $ query -> join ( 'openy_campaign_member_campaign' , 'mc' , 'w.member_campaign = mc.id' ) ; // Delete only winners with defined activity. if ( ! $ isAll ) { $ query -> condition ( 'w.activity' , 0 , '!=' ) ; } $ query -> condition ( 'mc.campaign' , $ campaignId ) ; $ winnerIDs = $ query -> execute ( ) -> fetchCol ( ) ; /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */ $ storage = \ Drupal :: service ( 'entity_type.manager' ) -> getStorage ( 'openy_campaign_winner' ) ; $ winners = $ storage -> loadMultiple ( $ winnerIDs ) ; $ storage -> delete ( $ winners ) ; }
Delete current Campaign winners.

@param int $campaignId
Campaign node ID.
@param bool $isAll
Should we delete all winners or only winners with defined activity.
Delete current Campaign winners .