Collection.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * New Accounts Report collection
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Reports\Model\ResourceModel\Accounts;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Collection extends \Magento\Reports\Model\ResourceModel\Customer\Collection
  17. {
  18. /**
  19. * Join created_at and accounts fields
  20. *
  21. * @param string $fromDate
  22. * @param string $toDate
  23. * @return $this
  24. */
  25. protected function _joinFields($fromDate = '', $toDate = '')
  26. {
  27. $this->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS);
  28. $this->addAttributeToFilter(
  29. 'created_at',
  30. ['from' => $fromDate, 'to' => $toDate, 'datetime' => true]
  31. )->addExpressionAttributeToSelect(
  32. 'accounts',
  33. 'COUNT({{entity_id}})',
  34. ['entity_id']
  35. );
  36. $this->getSelect()->having("{$this->_joinFields['accounts']['field']} > ?", 0);
  37. return $this;
  38. }
  39. /**
  40. * Set date range
  41. *
  42. * @param string $fromDate
  43. * @param string $toDate
  44. * @return $this
  45. */
  46. public function setDateRange($fromDate, $toDate)
  47. {
  48. $this->_reset()->_joinFields($fromDate, $toDate);
  49. return $this;
  50. }
  51. /**
  52. * Set store ids to final result
  53. *
  54. * @param array $storeIds
  55. * @return $this
  56. */
  57. public function setStoreIds($storeIds)
  58. {
  59. if ($storeIds) {
  60. $this->addAttributeToFilter('store_id', ['in' => (array)$storeIds]);
  61. }
  62. return $this;
  63. }
  64. }