Grid.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Adminhtml\Billing\Agreement;
  7. /**
  8. * Adminhtml billing agreements grid
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
  13. {
  14. /**
  15. * @var \Magento\Paypal\Helper\Data
  16. */
  17. protected $_helper = null;
  18. /**
  19. * @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory
  20. */
  21. protected $_agreementFactory;
  22. /**
  23. * @var \Magento\Paypal\Model\Billing\Agreement
  24. */
  25. protected $_agreementModel;
  26. /**
  27. * @param \Magento\Backend\Block\Template\Context $context
  28. * @param \Magento\Backend\Helper\Data $backendHelper
  29. * @param \Magento\Paypal\Helper\Data $helper
  30. * @param \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory
  31. * @param \Magento\Paypal\Model\Billing\Agreement $agreementModel
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Backend\Block\Template\Context $context,
  36. \Magento\Backend\Helper\Data $backendHelper,
  37. \Magento\Paypal\Helper\Data $helper,
  38. \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory,
  39. \Magento\Paypal\Model\Billing\Agreement $agreementModel,
  40. array $data = []
  41. ) {
  42. $this->_helper = $helper;
  43. $this->_agreementFactory = $agreementFactory;
  44. $this->_agreementModel = $agreementModel;
  45. parent::__construct($context, $backendHelper, $data);
  46. }
  47. /**
  48. * Set grid params
  49. *
  50. * @return void
  51. */
  52. protected function _construct()
  53. {
  54. parent::_construct();
  55. $this->setId('billing_agreements');
  56. $this->setUseAjax(true);
  57. $this->setDefaultSort('agreement_id');
  58. $this->setDefaultDir('DESC');
  59. $this->setSaveParametersInSession(true);
  60. }
  61. /**
  62. * Retrieve grid url
  63. *
  64. * @return string
  65. */
  66. public function getGridUrl()
  67. {
  68. return $this->getUrl('paypal/billing_agreement/grid', ['_current' => true]);
  69. }
  70. /**
  71. * Retrieve row url
  72. *
  73. * @param object $item
  74. * @return string
  75. */
  76. public function getRowUrl($item)
  77. {
  78. return $this->getUrl('paypal/billing_agreement/view', ['agreement' => $item->getAgreementId()]);
  79. }
  80. /**
  81. * Prepare collection for grid
  82. *
  83. * @return $this
  84. */
  85. protected function _prepareCollection()
  86. {
  87. /** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $collection */
  88. $collection = $this->_agreementFactory->create()->addCustomerDetails();
  89. $this->setCollection($collection);
  90. return parent::_prepareCollection();
  91. }
  92. /**
  93. * Add columns to grid
  94. *
  95. * @return $this
  96. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  97. */
  98. protected function _prepareColumns()
  99. {
  100. $this->addColumn(
  101. 'agreement_id',
  102. [
  103. 'header' => __('ID'),
  104. 'index' => 'agreement_id',
  105. 'type' => 'text',
  106. 'header_css_class' => 'col-id',
  107. 'column_css_class' => 'col-id'
  108. ]
  109. );
  110. $this->addColumn(
  111. 'customer_email',
  112. [
  113. 'header' => __('Email'),
  114. 'index' => 'customer_email',
  115. 'type' => 'text',
  116. 'header_css_class' => 'col-mail',
  117. 'column_css_class' => 'col-mail'
  118. ]
  119. );
  120. $this->addColumn(
  121. 'customer_firstname',
  122. [
  123. 'header' => __('First Name'),
  124. 'index' => 'customer_firstname',
  125. 'type' => 'text',
  126. 'escape' => true,
  127. 'header_css_class' => 'col-name',
  128. 'column_css_class' => 'col-name'
  129. ]
  130. );
  131. $this->addColumn(
  132. 'customer_lastname',
  133. [
  134. 'header' => __('Last Name'),
  135. 'index' => 'customer_lastname',
  136. 'type' => 'text',
  137. 'escape' => true,
  138. 'header_css_class' => 'col-last-name',
  139. 'column_css_class' => 'col-last-name'
  140. ]
  141. );
  142. $this->addColumn(
  143. 'reference_id',
  144. [
  145. 'header' => __('Reference ID'),
  146. 'index' => 'reference_id',
  147. 'type' => 'text',
  148. 'header_css_class' => 'col-reference',
  149. 'column_css_class' => 'col-reference'
  150. ]
  151. );
  152. $this->addColumn(
  153. 'status',
  154. [
  155. 'header' => __('Status'),
  156. 'index' => 'status',
  157. 'type' => 'options',
  158. 'options' => $this->_agreementModel->getStatusesArray(),
  159. 'header_css_class' => 'col-status',
  160. 'column_css_class' => 'col-status'
  161. ]
  162. );
  163. $this->addColumn(
  164. 'created_at',
  165. [
  166. 'header' => __('Created'),
  167. 'index' => 'created_at',
  168. 'type' => 'datetime',
  169. 'align' => 'center',
  170. 'default' => __('N/A'),
  171. 'html_decorators' => ['nobr'],
  172. 'header_css_class' => 'col-period',
  173. 'column_css_class' => 'col-period'
  174. ]
  175. );
  176. $this->addColumn(
  177. 'updated_at',
  178. [
  179. 'header' => __('Updated'),
  180. 'index' => 'updated_at',
  181. 'type' => 'datetime',
  182. 'align' => 'center',
  183. 'default' => __('N/A'),
  184. 'html_decorators' => ['nobr'],
  185. 'header_css_class' => 'col-period',
  186. 'column_css_class' => 'col-period'
  187. ]
  188. );
  189. return parent::_prepareColumns();
  190. }
  191. }