Grid.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Newsletter\Controller\Adminhtml\Problem;
  8. class Grid extends \Magento\Newsletter\Controller\Adminhtml\Problem
  9. {
  10. /**
  11. * Newsletter problems grid
  12. *
  13. * @return void
  14. */
  15. public function execute()
  16. {
  17. if ($this->getRequest()->getParam('_unsubscribe')) {
  18. $problems = (array)$this->getRequest()->getParam('problem', []);
  19. if (count($problems) > 0) {
  20. $collection =
  21. $this->_objectManager->create(\Magento\Newsletter\Model\ResourceModel\Problem\Collection::class);
  22. $collection->addSubscriberInfo()->addFieldToFilter(
  23. $collection->getResource()->getIdFieldName(),
  24. ['in' => $problems]
  25. )->load();
  26. $collection->walk('unsubscribe');
  27. }
  28. $this->messageManager->addSuccess(__('We unsubscribed the people you identified.'));
  29. }
  30. if ($this->getRequest()->getParam('_delete')) {
  31. $problems = (array)$this->getRequest()->getParam('problem', []);
  32. if (count($problems) > 0) {
  33. $collection =
  34. $this->_objectManager->create(\Magento\Newsletter\Model\ResourceModel\Problem\Collection::class);
  35. $collection->addFieldToFilter(
  36. $collection->getResource()->getIdFieldName(),
  37. ['in' => $problems]
  38. )->load();
  39. $collection->walk('delete');
  40. }
  41. $this->messageManager->addSuccess(__('The problems you identified have been deleted.'));
  42. }
  43. $this->_view->loadLayout(false);
  44. $this->_view->getLayout()->getMessagesBlock()->setMessages($this->messageManager->getMessages(true));
  45. $this->_view->renderLayout();
  46. }
  47. }