Rss.php 3.06 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Review\Block\Adminhtml;

use Magento\Framework\App\Rss\DataProviderInterface;

/**
 * Class Rss
 * @package Magento\Catalog\Block\Adminhtml\Rss
 */
class Rss extends \Magento\Backend\Block\AbstractBlock implements DataProviderInterface
{
    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @var \Magento\Catalog\Model\Rss\Product\Review
     */
    protected $rssModel;

    /**
     * @param \Magento\Backend\Block\Context $context
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Review\Model\Rss $rssModel
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Review\Model\Rss $rssModel,
        array $data = []
    ) {
        $this->storeManager = $storeManager;
        $this->rssModel = $rssModel;
        parent::__construct($context, $data);
    }

    /**
     * {@inheritdoc}
     */
    public function getRssData()
    {
        $newUrl = $this->getUrl('rss/catalog/review', ['_secure' => true, '_nosecret' => true]);
        $title = __('Pending product review(s)');

        $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];

        foreach ($this->rssModel->getProductCollection() as $item) {
            if ($item->getStoreId()) {
                $this->_urlBuilder->setScope($item->getStoreId());
            }

            $url = $this->getUrl('catalog/product/view', ['id' => $item->getId()]);
            $reviewUrl = $this->getUrl('review/product/edit/', [
                'id' => $item->getReviewId(),
                '_secure' => true,
                '_nosecret' => true
            ]);

            $storeName = $this->storeManager->getStore($item->getStoreId())->getName();
            $description = '<p>' . __('Product: <a href="%1" target="_blank">%2</a> <br/>', $url, $item->getName())
                . __('Summary of review: %1 <br/>', $item->getTitle()) . __('Review: %1 <br/>', $item->getDetail())
                . __('Store: %1 <br/>', $storeName)
                . __('Click <a href="%1">here</a> to see the review.', $reviewUrl)
                . '</p>';

            $data['entries'][] = [
                'title' => __('Product: "%1" reviewed by: %2', $item->getName(), $item->getNickname()),
                'link' => $item->getProductUrl(),
                'description' => $description,
            ];
        }

        return $data;
    }

    /**
     * {@inheritdoc}
     */
    public function getCacheLifetime()
    {
        return 0;
    }

    /**
     * {@inheritdoc}
     */
    public function isAllowed()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function getFeeds()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public function isAuthRequired()
    {
        return true;
    }
}