public function getActiveCampaigns() {
    // All dates are stored in database in UTC timezone.
    // Get current datetime in UTC timezone.
    $dt = new \DateTime('now', new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
    $now = DrupalDateTime::createFromDateTime($dt);

    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    $campaignIds = $nodeStorage->getQuery()
      ->condition('type', 'campaign')
      ->condition('status', TRUE)
      ->condition('field_campaign_end_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=')
      ->sort('created', 'DESC')
      ->execute();
    $campaigns = $nodeStorage->loadMultiple($campaignIds);

    return !empty($campaigns) ? $campaigns : NULL;
  }
public function getActiveCampaigns() {
    // All dates are stored in database in UTC timezone.
    // Get current datetime in UTC timezone.
    $dt = new \DateTime('now', new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
    $now = DrupalDateTime::createFromDateTime($dt);

    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    $campaignIds = $nodeStorage->getQuery()
      ->condition('type', 'campaign')
      ->condition('status', TRUE)
      ->condition('field_campaign_end_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=')
      ->sort('created', 'DESC')
      ->execute();
    $campaigns = $nodeStorage->loadMultiple($campaignIds);

    return !empty($campaigns) ? $campaigns : NULL;
  }
public function getActiveCampaigns ( ) { // All dates are stored in database in UTC timezone. // Get current datetime in UTC timezone. $ dt = new \ DateTime ( 'now' , new \ DateTimezone ( DATETIME_STORAGE_TIMEZONE ) ) ; $ now = DrupalDateTime :: createFromDateTime ( $ dt ) ; /** @var \Drupal\node\NodeStorage $nodeStorage */ $ nodeStorage = $ this -> entityTypeManager -> getStorage ( 'node' ) ; $ campaignIds = $ nodeStorage -> getQuery ( ) -> condition ( 'type' , 'campaign' ) -> condition ( 'status' , TRUE ) -> condition ( 'field_campaign_end_date' , $ now -> format ( DATETIME_DATETIME_STORAGE_FORMAT ) , '>=' ) -> sort ( 'created' , 'DESC' ) -> execute ( ) ; $ campaigns = $ nodeStorage -> loadMultiple ( $ campaignIds ) ; return ! empty ( $ campaigns ) ? $ campaigns : NULL ; }
Get all active Campaign nodes.
Get all active Campaign nodes .