WebformIteratorAggregate.php in Webform Scheduled Tasks 8.2
File
src/Iterator/WebformIteratorAggregate.php
View source
<?php
namespace Drupal\webform_scheduled_tasks\Iterator;
use Drupal\Core\Entity\ContentEntityStorageInterface;
use Drupal\Core\Entity\Query\QueryInterface;
class WebformIteratorAggregate implements \IteratorAggregate, \Countable {
protected $submissionIds;
protected $chunkSize;
protected $submissionStorage;
public function __construct($submissionIds, $chunkSize, ContentEntityStorageInterface $submissionStorage) {
$this->submissionIds = $submissionIds;
$this->chunkSize = $chunkSize;
$this->submissionStorage = $submissionStorage;
}
public function count() {
return count($this->submissionIds);
}
public function getIterator() {
foreach (array_chunk($this->submissionIds, $this->chunkSize) as $ids_chunk) {
foreach ($this->submissionStorage
->loadMultiple($ids_chunk) as $entity) {
(yield $entity);
}
}
}
public static function createFromQuery(QueryInterface $query) {
return new static($query
->execute(), 50, \Drupal::service('entity_type.manager')
->getStorage('webform_submission'));
}
}