123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Review\Block\Customer;
- use Magento\Customer\Api\AccountManagementInterface;
- use Magento\Customer\Api\CustomerRepositoryInterface;
- /**
- * Customer Reviews list block
- *
- * @api
- * @since 100.0.2
- */
- class ListCustomer extends \Magento\Customer\Block\Account\Dashboard
- {
- /**
- * Product reviews collection
- *
- * @var \Magento\Review\Model\ResourceModel\Review\Product\Collection
- */
- protected $_collection;
- /**
- * Review resource model
- *
- * @var \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory
- */
- protected $_collectionFactory;
- /**
- * @var \Magento\Customer\Helper\Session\CurrentCustomer
- */
- protected $currentCustomer;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
- * @param CustomerRepositoryInterface $customerRepository
- * @param AccountManagementInterface $customerAccountManagement
- * @param \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $collectionFactory
- * @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Customer\Model\Session $customerSession,
- \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
- CustomerRepositoryInterface $customerRepository,
- AccountManagementInterface $customerAccountManagement,
- \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $collectionFactory,
- \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
- array $data = []
- ) {
- $this->_collectionFactory = $collectionFactory;
- parent::__construct(
- $context,
- $customerSession,
- $subscriberFactory,
- $customerRepository,
- $customerAccountManagement,
- $data
- );
- $this->currentCustomer = $currentCustomer;
- }
- /**
- * Get html code for toolbar
- *
- * @return string
- */
- public function getToolbarHtml()
- {
- return $this->getChildHtml('toolbar');
- }
- /**
- * Initializes toolbar
- *
- * @return \Magento\Framework\View\Element\AbstractBlock
- */
- protected function _prepareLayout()
- {
- if ($this->getReviews()) {
- $toolbar = $this->getLayout()->createBlock(
- \Magento\Theme\Block\Html\Pager::class,
- 'customer_review_list.toolbar'
- )->setCollection(
- $this->getReviews()
- );
- $this->setChild('toolbar', $toolbar);
- }
- return parent::_prepareLayout();
- }
- /**
- * Get reviews
- *
- * @return bool|\Magento\Review\Model\ResourceModel\Review\Product\Collection
- */
- public function getReviews()
- {
- if (!($customerId = $this->currentCustomer->getCustomerId())) {
- return false;
- }
- if (!$this->_collection) {
- $this->_collection = $this->_collectionFactory->create();
- $this->_collection
- ->addStoreFilter($this->_storeManager->getStore()->getId())
- ->addCustomerFilter($customerId)
- ->setDateOrder();
- }
- return $this->_collection;
- }
- /**
- * Get review link
- *
- * @return string
- * @deprecated 100.2.0
- */
- public function getReviewLink()
- {
- return $this->getUrl('review/customer/view/');
- }
- /**
- * Get review URL
- *
- * @param \Magento\Review\Model\Review $review
- * @return string
- * @since 100.2.0
- */
- public function getReviewUrl($review)
- {
- return $this->getUrl('review/customer/view', ['id' => $review->getReviewId()]);
- }
- /**
- * Get product link
- *
- * @return string
- * @deprecated 100.2.0
- */
- public function getProductLink()
- {
- return $this->getUrl('catalog/product/view/');
- }
- /**
- * Get product URL
- *
- * @param \Magento\Catalog\Model\Product $product
- * @return string
- * @since 100.2.0
- */
- public function getProductUrl($product)
- {
- return $product->getProductUrl();
- }
- /**
- * Format date in short format
- *
- * @param string $date
- * @return string
- */
- public function dateFormat($date)
- {
- return $this->formatDate($date, \IntlDateFormatter::SHORT);
- }
- /**
- * Add review summary
- *
- * @return \Magento\Framework\View\Element\AbstractBlock
- */
- protected function _beforeToHtml()
- {
- $reviews = $this->getReviews();
- if ($reviews) {
- $reviews->load()->addReviewSummary();
- }
- return parent::_beforeToHtml();
- }
- }
|