Main.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Adminhtml review main block
  8. */
  9. namespace Magento\Review\Block\Adminhtml;
  10. class Main extends \Magento\Backend\Block\Widget\Grid\Container
  11. {
  12. /**
  13. * Core registry
  14. *
  15. * @var \Magento\Framework\Registry
  16. */
  17. protected $_coreRegistry = null;
  18. /**
  19. * @var \Magento\Customer\Api\CustomerRepositoryInterface
  20. */
  21. protected $customerRepository;
  22. /**
  23. * Catalog product model factory
  24. *
  25. * @var \Magento\Catalog\Model\ProductFactory
  26. */
  27. protected $_productFactory;
  28. /**
  29. * Customer View Helper
  30. *
  31. * @var \Magento\Customer\Helper\View
  32. */
  33. protected $_customerViewHelper;
  34. /**
  35. * @param \Magento\Backend\Block\Widget\Context $context
  36. * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  37. * @param \Magento\Catalog\Model\ProductFactory $productFactory
  38. * @param \Magento\Framework\Registry $registry
  39. * @param \Magento\Customer\Helper\View $customerViewHelper
  40. * @param array $data
  41. */
  42. public function __construct(
  43. \Magento\Backend\Block\Widget\Context $context,
  44. \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
  45. \Magento\Catalog\Model\ProductFactory $productFactory,
  46. \Magento\Framework\Registry $registry,
  47. \Magento\Customer\Helper\View $customerViewHelper,
  48. array $data = []
  49. ) {
  50. $this->_coreRegistry = $registry;
  51. $this->customerRepository = $customerRepository;
  52. $this->_productFactory = $productFactory;
  53. $this->_customerViewHelper = $customerViewHelper;
  54. parent::__construct($context, $data);
  55. }
  56. /**
  57. * Initialize add new review
  58. *
  59. * @return void
  60. */
  61. protected function _construct()
  62. {
  63. $this->_addButtonLabel = __('New Review');
  64. parent::_construct();
  65. $this->_blockGroup = 'Magento_Review';
  66. $this->_controller = 'adminhtml';
  67. // lookup customer, if id is specified
  68. $customerId = $this->getRequest()->getParam('customerId', false);
  69. $customerName = '';
  70. if ($customerId) {
  71. $customer = $this->customerRepository->getById($customerId);
  72. $customerName = $this->escapeHtml($this->_customerViewHelper->getCustomerName($customer));
  73. }
  74. $productId = $this->getRequest()->getParam('productId', false);
  75. $productName = null;
  76. if ($productId) {
  77. $product = $this->_productFactory->create()->load($productId);
  78. $productName = $this->escapeHtml($product->getName());
  79. }
  80. if ($this->_coreRegistry->registry('usePendingFilter') === true) {
  81. if ($customerName) {
  82. $this->_headerText = __('Pending Reviews of Customer `%1`', $customerName);
  83. } else {
  84. $this->_headerText = __('Pending Reviews');
  85. }
  86. $this->buttonList->remove('add');
  87. } else {
  88. if ($customerName) {
  89. $this->_headerText = __('All Reviews of Customer `%1`', $customerName);
  90. } elseif ($productName) {
  91. $this->_headerText = __('All Reviews of Product `%1`', $productName);
  92. } else {
  93. $this->_headerText = __('All Reviews');
  94. }
  95. }
  96. }
  97. }