Collection.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\ResourceModel\Billing\Agreement;
  7. /**
  8. * Billing agreements resource collection
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  14. {
  15. /**
  16. * Mapping for fields
  17. *
  18. * @var array
  19. */
  20. protected $_map = [
  21. 'fields' => [
  22. 'customer_email' => 'ce.email',
  23. 'customer_firstname' => 'ce.firstname',
  24. 'customer_lastname' => 'ce.lastname',
  25. 'agreement_created_at' => 'main_table.created_at',
  26. 'agreement_updated_at' => 'main_table.updated_at',
  27. ],
  28. ];
  29. /**
  30. * @var \Magento\Customer\Model\ResourceModel\Customer
  31. */
  32. protected $_customerResource;
  33. /**
  34. * @var \Magento\Eav\Helper\Data
  35. */
  36. protected $_eavHelper;
  37. /**
  38. * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  39. * @param \Psr\Log\LoggerInterface $logger
  40. * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  41. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  42. * @param \Magento\Customer\Model\ResourceModel\Customer $customerResource
  43. * @param \Magento\Eav\Helper\Data $eavHelper
  44. * @param mixed $connection
  45. * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
  46. */
  47. public function __construct(
  48. \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
  49. \Psr\Log\LoggerInterface $logger,
  50. \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
  51. \Magento\Framework\Event\ManagerInterface $eventManager,
  52. \Magento\Customer\Model\ResourceModel\Customer $customerResource,
  53. \Magento\Eav\Helper\Data $eavHelper,
  54. \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
  55. \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
  56. ) {
  57. parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
  58. $this->_eavHelper = $eavHelper;
  59. $this->_customerResource = $customerResource;
  60. }
  61. /**
  62. * Collection initialization
  63. *
  64. * @return void
  65. */
  66. protected function _construct()
  67. {
  68. $this->_init(
  69. \Magento\Paypal\Model\Billing\Agreement::class,
  70. \Magento\Paypal\Model\ResourceModel\Billing\Agreement::class
  71. );
  72. }
  73. /**
  74. * Add customer details(email, firstname, lastname) to select
  75. *
  76. * @return $this
  77. */
  78. public function addCustomerDetails()
  79. {
  80. $this->getSelect()->joinInner(
  81. ['ce' => $this->getTable('customer_entity')],
  82. 'ce.entity_id = main_table.customer_id',
  83. [
  84. 'customer_email' => 'email',
  85. 'customer_firstname' => 'firstname',
  86. 'customer_lastname' => 'lastname',
  87. ]
  88. );
  89. return $this;
  90. }
  91. /**
  92. * @inheritdoc
  93. */
  94. public function addFieldToFilter($field, $condition = null)
  95. {
  96. if (in_array($field, ['created_at', 'updated_at'], true)) {
  97. $field = 'main_table.' . $field;
  98. }
  99. return parent::addFieldToFilter($field, $condition);
  100. }
  101. }