Problem.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Newsletter\Block\Adminhtml;
  7. use Magento\Newsletter\Model\ResourceModel\Problem\Collection;
  8. /**
  9. * Newsletter problem block template.
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Problem extends \Magento\Backend\Block\Template
  16. {
  17. /**
  18. * @var string
  19. */
  20. protected $_template = 'Magento_Newsletter::problem/list.phtml';
  21. /**
  22. * @var \Magento\Newsletter\Model\ResourceModel\Problem\Collection
  23. */
  24. protected $_problemCollection;
  25. /**
  26. * @param \Magento\Backend\Block\Template\Context $context
  27. * @param Collection $problemCollection
  28. * @param array $data
  29. */
  30. public function __construct(
  31. \Magento\Backend\Block\Template\Context $context,
  32. Collection $problemCollection,
  33. array $data = []
  34. ) {
  35. $this->_problemCollection = $problemCollection;
  36. parent::__construct($context, $data);
  37. }
  38. /**
  39. * @return void
  40. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  41. */
  42. protected function _construct()
  43. {
  44. parent::_construct();
  45. $collection = $this->_problemCollection->addSubscriberInfo()->addQueueInfo();
  46. }
  47. /**
  48. * Prepare for the newsletter block layout
  49. *
  50. * @return $this
  51. */
  52. protected function _prepareLayout()
  53. {
  54. $this->setChild(
  55. 'deleteButton',
  56. $this->getLayout()->createBlock(
  57. \Magento\Backend\Block\Widget\Button::class,
  58. 'del.button'
  59. )->setData(
  60. ['label' => __('Delete Selected Problems'), 'onclick' => 'problemController.deleteSelected();']
  61. )
  62. );
  63. $this->setChild(
  64. 'unsubscribeButton',
  65. $this->getLayout()->createBlock(
  66. \Magento\Backend\Block\Widget\Button::class,
  67. 'unsubscribe.button'
  68. )->setData(
  69. ['label' => __('Unsubscribe Selected'), 'onclick' => 'problemController.unsubscribe();']
  70. )
  71. );
  72. return parent::_prepareLayout();
  73. }
  74. /**
  75. * Get the html element for unsubscribe button
  76. *
  77. * @return $string
  78. */
  79. public function getUnsubscribeButtonHtml()
  80. {
  81. return $this->getChildHtml('unsubscribeButton');
  82. }
  83. /**
  84. * Get the html element for delete button
  85. *
  86. * @return $string
  87. */
  88. public function getDeleteButtonHtml()
  89. {
  90. return $this->getChildHtml('deleteButton');
  91. }
  92. /**
  93. * Return true if the size is greater than 0
  94. *
  95. * @return bool
  96. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  97. */
  98. public function getShowButtons()
  99. {
  100. return $this->_problemCollection->getSize() > 0;
  101. }
  102. }