Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Grid.php
Go to the documentation of this file.
1 <?php
7 
13 class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
14 {
18  protected $_helper = null;
19 
23  protected $_agreementFactory;
24 
28  protected $_agreementModel;
29 
38  public function __construct(
39  \Magento\Backend\Block\Template\Context $context,
40  \Magento\Backend\Helper\Data $backendHelper,
41  \Magento\Paypal\Helper\Data $helper,
42  \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory,
43  \Magento\Paypal\Model\Billing\Agreement $agreementModel,
44  array $data = []
45  ) {
46  $this->_helper = $helper;
47  $this->_agreementFactory = $agreementFactory;
48  $this->_agreementModel = $agreementModel;
49  parent::__construct($context, $backendHelper, $data);
50  }
51 
57  protected function _construct()
58  {
59  parent::_construct();
60  $this->setId('billing_agreements');
61  $this->setUseAjax(true);
62  $this->setDefaultSort('agreement_id');
63  $this->setDefaultDir('DESC');
64  $this->setSaveParametersInSession(true);
65  }
66 
72  public function getGridUrl()
73  {
74  return $this->getUrl('paypal/billing_agreement/grid', ['_current' => true]);
75  }
76 
83  public function getRowUrl($item)
84  {
85  return $this->getUrl('paypal/billing_agreement/view', ['agreement' => $item->getAgreementId()]);
86  }
87 
93  protected function _prepareCollection()
94  {
96  $collection = $this->_agreementFactory->create()->addCustomerDetails();
97  $this->setCollection($collection);
98  return parent::_prepareCollection();
99  }
100 
107  protected function _prepareColumns()
108  {
109  $this->addColumn(
110  'agreement_id',
111  [
112  'header' => __('ID'),
113  'index' => 'agreement_id',
114  'type' => 'text',
115  'header_css_class' => 'col-id',
116  'column_css_class' => 'col-id'
117  ]
118  );
119 
120  $this->addColumn(
121  'customer_email',
122  [
123  'header' => __('Email'),
124  'index' => 'customer_email',
125  'type' => 'text',
126  'header_css_class' => 'col-mail',
127  'column_css_class' => 'col-mail'
128  ]
129  );
130 
131  $this->addColumn(
132  'customer_firstname',
133  [
134  'header' => __('First Name'),
135  'index' => 'customer_firstname',
136  'type' => 'text',
137  'escape' => true,
138  'header_css_class' => 'col-name',
139  'column_css_class' => 'col-name'
140  ]
141  );
142 
143  $this->addColumn(
144  'customer_lastname',
145  [
146  'header' => __('Last Name'),
147  'index' => 'customer_lastname',
148  'type' => 'text',
149  'escape' => true,
150  'header_css_class' => 'col-last-name',
151  'column_css_class' => 'col-last-name'
152  ]
153  );
154 
155  $this->addColumn(
156  'reference_id',
157  [
158  'header' => __('Reference ID'),
159  'index' => 'reference_id',
160  'type' => 'text',
161  'header_css_class' => 'col-reference',
162  'column_css_class' => 'col-reference'
163  ]
164  );
165 
166  $this->addColumn(
167  'status',
168  [
169  'header' => __('Status'),
170  'index' => 'status',
171  'type' => 'options',
172  'options' => $this->_agreementModel->getStatusesArray(),
173  'header_css_class' => 'col-status',
174  'column_css_class' => 'col-status'
175  ]
176  );
177 
178  $this->addColumn(
179  'created_at',
180  [
181  'header' => __('Created'),
182  'index' => 'created_at',
183  'type' => 'datetime',
184  'align' => 'center',
185  'default' => __('N/A'),
186  'html_decorators' => ['nobr'],
187  'header_css_class' => 'col-period',
188  'column_css_class' => 'col-period'
189  ]
190  );
191 
192  $this->addColumn(
193  'updated_at',
194  [
195  'header' => __('Updated'),
196  'index' => 'updated_at',
197  'type' => 'datetime',
198  'align' => 'center',
199  'default' => __('N/A'),
200  'html_decorators' => ['nobr'],
201  'header_css_class' => 'col-period',
202  'column_css_class' => 'col-period'
203  ]
204  );
205 
206  return parent::_prepareColumns();
207  }
208 }
$helper
Definition: iframe.phtml:13
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Paypal\Helper\Data $helper, \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory, \Magento\Paypal\Model\Billing\Agreement $agreementModel, array $data=[])
Definition: Grid.php:38