Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
7 
9 
19 {
25  protected $_queueLinkTable;
26 
32  protected $_storeTable;
33 
39  protected $_queueJoinedFlag = false;
40 
46  protected $_showCustomersInfo = false;
47 
53  protected $_countFilterPart = [];
54 
61 
71  public function __construct(
72  \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
73  \Psr\Log\LoggerInterface $logger,
74  \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
75  \Magento\Framework\Event\ManagerInterface $eventManager,
76  \Magento\Eav\Helper\Data $customerHelperData,
77  \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
78  \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
79  ) {
80  $this->_customerHelperData = $customerHelperData;
81  parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
82  }
83 
90  protected function _construct()
91  {
92  parent::_construct();
93  $this->_init(
94  \Magento\Newsletter\Model\Subscriber::class,
95  \Magento\Newsletter\Model\ResourceModel\Subscriber::class
96  );
97  $this->_queueLinkTable = $this->getTable('newsletter_queue_link');
98  $this->_storeTable = $this->getTable('store');
99 
100  $this->_map['fields']['type'] = $this->getResource()->getConnection()->getCheckSql(
101  'main_table.customer_id = 0',
102  1,
103  2
104  );
105  $this->_map['fields']['website_id'] = 'store.website_id';
106  $this->_map['fields']['group_id'] = 'store.group_id';
107  $this->_map['fields']['store_id'] = 'main_table.store_id';
108  }
109 
116  public function useQueue(ModelQueue $queue)
117  {
118  $this->getSelect()->join(
119  ['link' => $this->_queueLinkTable],
120  "link.subscriber_id = main_table.subscriber_id",
121  []
122  )->where(
123  "link.queue_id = ? ",
124  $queue->getId()
125  );
126  $this->_queueJoinedFlag = true;
127  return $this;
128  }
129 
135  public function useOnlyUnsent()
136  {
137  if ($this->_queueJoinedFlag) {
138  $this->addFieldToFilter('link.letter_sent_at', ['null' => 1]);
139  }
140 
141  return $this;
142  }
143 
149  public function showCustomerInfo()
150  {
151  $this->getSelect()->joinLeft(
152  [
153  'customer' => $this->getTable('customer_entity')
154  ],
155  'main_table.customer_id = customer.entity_id',
156  ['firstname', 'lastname']
157  );
158  return $this;
159  }
160 
166  public function addSubscriberTypeField()
167  {
168  $this->getSelect()->columns(['type' => new \Zend_Db_Expr($this->_getMappedField('type'))]);
169  return $this;
170  }
171 
177  public function showStoreInfo()
178  {
179  $this->getSelect()->join(
180  ['store' => $this->_storeTable],
181  'store.store_id = main_table.store_id',
182  ['group_id', 'website_id']
183  );
184 
185  return $this;
186  }
187 
193  public function getSelectCountSql()
194  {
195  $select = parent::getSelectCountSql();
196  $countSelect = clone $this->getSelect();
197 
198  $countSelect->reset(\Magento\Framework\DB\Select::HAVING);
199 
200  return $select;
201  }
202 
208  public function useOnlyCustomers()
209  {
210  $this->addFieldToFilter('main_table.customer_id', ['gt' => 0]);
211 
212  return $this;
213  }
214 
220  public function useOnlySubscribed()
221  {
222  $this->addFieldToFilter(
223  'main_table.subscriber_status',
224  \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED
225  );
226 
227  return $this;
228  }
229 
236  public function addStoreFilter($storeIds)
237  {
238  $this->addFieldToFilter('main_table.store_id', ['in' => $storeIds]);
239  return $this;
240  }
241 
248  public function getQueueJoinedFlag()
249  {
251  }
252 }
$queue
Definition: queue.php:21
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Helper\Data $customerHelperData, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null)
Definition: Collection.php:71
$resource
Definition: bulk.php:12
$logger