Grid.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Newsletter templates grid block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Newsletter\Block\Adminhtml\Template;
  12. use Magento\Backend\Block\Widget\Grid as WidgetGrid;
  13. use Magento\Framework\App\TemplateTypesInterface;
  14. class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
  15. {
  16. /**
  17. * @var \Magento\Newsletter\Model\ResourceModel\Template\Collection
  18. */
  19. protected $_templateCollection;
  20. /**
  21. * @param \Magento\Backend\Block\Template\Context $context
  22. * @param \Magento\Backend\Helper\Data $backendHelper
  23. * @param \Magento\Newsletter\Model\ResourceModel\Template\Collection $templateCollection
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Template\Context $context,
  28. \Magento\Backend\Helper\Data $backendHelper,
  29. \Magento\Newsletter\Model\ResourceModel\Template\Collection $templateCollection,
  30. array $data = []
  31. ) {
  32. $this->_templateCollection = $templateCollection;
  33. parent::__construct($context, $backendHelper, $data);
  34. $this->setEmptyText(__('No Templates Found'));
  35. }
  36. /**
  37. * Apply sorting and filtering to collection
  38. *
  39. * @return WidgetGrid
  40. */
  41. protected function _prepareCollection()
  42. {
  43. $this->setCollection($this->_templateCollection->useOnlyActual());
  44. return parent::_prepareCollection();
  45. }
  46. /**
  47. * Prepare grid columns
  48. *
  49. * @return $this
  50. */
  51. protected function _prepareColumns()
  52. {
  53. $this->addColumn(
  54. 'template_code',
  55. [
  56. 'header' => __('ID'),
  57. 'index' => 'template_id',
  58. 'header_css_class' => 'col-id',
  59. 'column_css_class' => 'col-id'
  60. ]
  61. );
  62. $this->addColumn(
  63. 'code',
  64. [
  65. 'header' => __('Template'),
  66. 'index' => 'template_code',
  67. 'header_css_class' => 'col-template',
  68. 'column_css_class' => 'col-template'
  69. ]
  70. );
  71. $this->addColumn(
  72. 'added_at',
  73. [
  74. 'header' => __('Added'),
  75. 'index' => 'added_at',
  76. 'gmtoffset' => true,
  77. 'type' => 'datetime',
  78. 'header_css_class' => 'col-added col-date',
  79. 'column_css_class' => 'col-added col-date'
  80. ]
  81. );
  82. $this->addColumn(
  83. 'modified_at',
  84. [
  85. 'header' => __('Updated'),
  86. 'index' => 'modified_at',
  87. 'gmtoffset' => true,
  88. 'type' => 'datetime',
  89. 'header_css_class' => 'col-updated col-date',
  90. 'column_css_class' => 'col-updated col-date'
  91. ]
  92. );
  93. $this->addColumn(
  94. 'subject',
  95. [
  96. 'header' => __('Subject'),
  97. 'index' => 'template_subject',
  98. 'header_css_class' => 'col-subject',
  99. 'column_css_class' => 'col-subject'
  100. ]
  101. );
  102. $this->addColumn(
  103. 'sender',
  104. [
  105. 'header' => __('Sender'),
  106. 'index' => 'template_sender_email',
  107. 'renderer' => \Magento\Newsletter\Block\Adminhtml\Template\Grid\Renderer\Sender::class,
  108. 'header_css_class' => 'col-sender',
  109. 'column_css_class' => 'col-sender'
  110. ]
  111. );
  112. $this->addColumn(
  113. 'type',
  114. [
  115. 'header' => __('Template Type'),
  116. 'index' => 'template_type',
  117. 'type' => 'options',
  118. 'options' => [
  119. TemplateTypesInterface::TYPE_HTML => 'html',
  120. TemplateTypesInterface::TYPE_TEXT => 'text',
  121. ],
  122. 'header_css_class' => 'col-type',
  123. 'column_css_class' => 'col-type'
  124. ]
  125. );
  126. $this->addColumn(
  127. 'action',
  128. [
  129. 'header' => __('Action'),
  130. 'index' => 'template_id',
  131. 'sortable' => false,
  132. 'filter' => false,
  133. 'no_link' => true,
  134. 'renderer' => \Magento\Newsletter\Block\Adminhtml\Template\Grid\Renderer\Action::class,
  135. 'header_css_class' => 'col-actions',
  136. 'column_css_class' => 'col-actions'
  137. ]
  138. );
  139. return $this;
  140. }
  141. /**
  142. * Get row url
  143. *
  144. * @param \Magento\Framework\DataObject $row
  145. * @return string
  146. */
  147. public function getRowUrl($row)
  148. {
  149. return $this->getUrl('*/*/edit', ['id' => $row->getId()]);
  150. }
  151. }