Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Source.php
Go to the documentation of this file.
1 <?php
7 
10 use Traversable;
11 
15 class Source implements \IteratorAggregate, \Countable, SourceProviderInterface
16 {
20  private $customerCollection;
21 
25  private $batchSize;
26 
31  public function __construct(
32  \Magento\Customer\Model\ResourceModel\Customer\Indexer\CollectionFactory $collectionFactory,
33  $batchSize = 10000
34  ) {
35  $this->customerCollection = $collectionFactory->create();
36  $this->batchSize = $batchSize;
37  }
38 
42  public function getMainTable()
43  {
44  return $this->customerCollection->getMainTable();
45  }
46 
50  public function getIdFieldName()
51  {
52  return $this->customerCollection->getIdFieldName();
53  }
54 
58  public function addFieldToSelect($fieldName, $alias = null)
59  {
60  $this->customerCollection->addFieldToSelect($fieldName, $alias);
61  return $this;
62  }
63 
67  public function getSelect()
68  {
69  return $this->customerCollection->getSelect();
70  }
71 
75  public function addFieldToFilter($attribute, $condition = null)
76  {
77  $this->customerCollection->addFieldToFilter($attribute, $condition);
78  return $this;
79  }
80 
84  public function count()
85  {
86  return $this->customerCollection->getSize();
87  }
88 
94  public function getIterator()
95  {
96  $this->customerCollection->setPageSize($this->batchSize);
97  $lastPage = $this->customerCollection->getLastPageNumber();
98  $pageNumber = 0;
99  do {
100  $this->customerCollection->clear();
101  $this->customerCollection->setCurPage($pageNumber);
102  foreach ($this->customerCollection->getItems() as $key => $value) {
103  yield $key => $value;
104  }
105  $pageNumber++;
106  } while ($pageNumber <= $lastPage);
107  }
108 }
addFieldToSelect($fieldName, $alias=null)
Definition: Source.php:58
__construct(\Magento\Customer\Model\ResourceModel\Customer\Indexer\CollectionFactory $collectionFactory, $batchSize=10000)
Definition: Source.php:31
addFieldToFilter($attribute, $condition=null)
Definition: Source.php:75
$value
Definition: gender.phtml:16
if(!trim($html)) $alias
Definition: details.phtml:20