Rss.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Adminhtml;
  7. use Magento\Framework\App\Rss\DataProviderInterface;
  8. /**
  9. * Class Rss
  10. * @package Magento\Catalog\Block\Adminhtml\Rss
  11. */
  12. class Rss extends \Magento\Backend\Block\AbstractBlock implements DataProviderInterface
  13. {
  14. /**
  15. * @var \Magento\Store\Model\StoreManagerInterface
  16. */
  17. protected $storeManager;
  18. /**
  19. * @var \Magento\Catalog\Model\Rss\Product\Review
  20. */
  21. protected $rssModel;
  22. /**
  23. * @param \Magento\Backend\Block\Context $context
  24. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  25. * @param \Magento\Review\Model\Rss $rssModel
  26. * @param array $data
  27. */
  28. public function __construct(
  29. \Magento\Backend\Block\Context $context,
  30. \Magento\Store\Model\StoreManagerInterface $storeManager,
  31. \Magento\Review\Model\Rss $rssModel,
  32. array $data = []
  33. ) {
  34. $this->storeManager = $storeManager;
  35. $this->rssModel = $rssModel;
  36. parent::__construct($context, $data);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getRssData()
  42. {
  43. $newUrl = $this->getUrl('rss/catalog/review', ['_secure' => true, '_nosecret' => true]);
  44. $title = __('Pending product review(s)');
  45. $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
  46. foreach ($this->rssModel->getProductCollection() as $item) {
  47. if ($item->getStoreId()) {
  48. $this->_urlBuilder->setScope($item->getStoreId());
  49. }
  50. $url = $this->getUrl('catalog/product/view', ['id' => $item->getId()]);
  51. $reviewUrl = $this->getUrl('review/product/edit/', [
  52. 'id' => $item->getReviewId(),
  53. '_secure' => true,
  54. '_nosecret' => true
  55. ]);
  56. $storeName = $this->storeManager->getStore($item->getStoreId())->getName();
  57. $description = '<p>' . __('Product: <a href="%1" target="_blank">%2</a> <br/>', $url, $item->getName())
  58. . __('Summary of review: %1 <br/>', $item->getTitle()) . __('Review: %1 <br/>', $item->getDetail())
  59. . __('Store: %1 <br/>', $storeName)
  60. . __('Click <a href="%1">here</a> to see the review.', $reviewUrl)
  61. . '</p>';
  62. $data['entries'][] = [
  63. 'title' => __('Product: "%1" reviewed by: %2', $item->getName(), $item->getNickname()),
  64. 'link' => $item->getProductUrl(),
  65. 'description' => $description,
  66. ];
  67. }
  68. return $data;
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function getCacheLifetime()
  74. {
  75. return 0;
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function isAllowed()
  81. {
  82. return true;
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function getFeeds()
  88. {
  89. return [];
  90. }
  91. /**
  92. * {@inheritdoc}
  93. */
  94. public function isAuthRequired()
  95. {
  96. return true;
  97. }
  98. }