You are here

class WebformIteratorAggregate in Webform Scheduled Tasks 8.2

The WebformIteratorAggregate class.

Hierarchy

  • class \Drupal\webform_scheduled_tasks\Iterator\WebformIteratorAggregate implements \Drupal\webform_scheduled_tasks\Iterator\IteratorAggregate, \Drupal\webform_scheduled_tasks\Iterator\Countable

Expanded class hierarchy of WebformIteratorAggregate

3 files declare their use of WebformIteratorAggregate
AllSubmissions.php in src/Plugin/WebformScheduledTasks/ResultSet/AllSubmissions.php
SubmissionsCompletedSinceLastSuccess.php in src/Plugin/WebformScheduledTasks/ResultSet/SubmissionsCompletedSinceLastSuccess.php
WebformIteratorAggregateTest.php in tests/src/Unit/WebformIteratorAggregateTest.php

File

src/Iterator/WebformIteratorAggregate.php, line 11

Namespace

Drupal\webform_scheduled_tasks\Iterator
View source
class WebformIteratorAggregate implements \IteratorAggregate, \Countable {

  /**
   * An array of webform submission IDs.
   *
   * @var array
   */
  protected $submissionIds;

  /**
   * The chunk size.
   *
   * @var int
   */
  protected $chunkSize;

  /**
   * The webform submission storage.
   *
   * @var \Drupal\Core\Entity\ContentEntityStorageInterface
   */
  protected $submissionStorage;

  /**
   * WebformIteratorAggregate constructor.
   */
  public function __construct($submissionIds, $chunkSize, ContentEntityStorageInterface $submissionStorage) {
    $this->submissionIds = $submissionIds;
    $this->chunkSize = $chunkSize;
    $this->submissionStorage = $submissionStorage;
  }

  /**
   * {@inheritdoc}
   */
  public function count() {
    return count($this->submissionIds);
  }

  /**
   * {@inheritdoc}
   */
  public function getIterator() {
    foreach (array_chunk($this->submissionIds, $this->chunkSize) as $ids_chunk) {
      foreach ($this->submissionStorage
        ->loadMultiple($ids_chunk) as $entity) {
        (yield $entity);
      }
    }
  }

  /**
   * Create an iterator aggregate from an entity query.
   *
   * @param \Drupal\Core\Entity\Query\QueryInterface $query
   *   An un-executed entity query for webform submissions.
   *
   * @return static
   */
  public static function createFromQuery(QueryInterface $query) {
    return new static($query
      ->execute(), 50, \Drupal::service('entity_type.manager')
      ->getStorage('webform_submission'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformIteratorAggregate::$chunkSize protected property The chunk size.
WebformIteratorAggregate::$submissionIds protected property An array of webform submission IDs.
WebformIteratorAggregate::$submissionStorage protected property The webform submission storage.
WebformIteratorAggregate::count public function
WebformIteratorAggregate::createFromQuery public static function Create an iterator aggregate from an entity query.
WebformIteratorAggregate::getIterator public function
WebformIteratorAggregate::__construct public function WebformIteratorAggregate constructor.