Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ListCustomer.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
24  protected $_collection;
25 
32 
36  protected $currentCustomer;
37 
48  public function __construct(
49  \Magento\Framework\View\Element\Template\Context $context,
50  \Magento\Customer\Model\Session $customerSession,
51  \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
54  \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $collectionFactory,
55  \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
56  array $data = []
57  ) {
58  $this->_collectionFactory = $collectionFactory;
59  parent::__construct(
60  $context,
65  $data
66  );
67  $this->currentCustomer = $currentCustomer;
68  }
69 
75  public function getToolbarHtml()
76  {
77  return $this->getChildHtml('toolbar');
78  }
79 
85  protected function _prepareLayout()
86  {
87  if ($this->getReviews()) {
88  $toolbar = $this->getLayout()->createBlock(
89  \Magento\Theme\Block\Html\Pager::class,
90  'customer_review_list.toolbar'
91  )->setCollection(
92  $this->getReviews()
93  );
94 
95  $this->setChild('toolbar', $toolbar);
96  }
97  return parent::_prepareLayout();
98  }
99 
105  public function getReviews()
106  {
107  if (!($customerId = $this->currentCustomer->getCustomerId())) {
108  return false;
109  }
110  if (!$this->_collection) {
111  $this->_collection = $this->_collectionFactory->create();
112  $this->_collection
113  ->addStoreFilter($this->_storeManager->getStore()->getId())
114  ->addCustomerFilter($customerId)
115  ->setDateOrder();
116  }
117  return $this->_collection;
118  }
119 
126  public function getReviewLink()
127  {
128  return $this->getUrl('review/customer/view/');
129  }
130 
138  public function getReviewUrl($review)
139  {
140  return $this->getUrl('review/customer/view', ['id' => $review->getReviewId()]);
141  }
142 
149  public function getProductLink()
150  {
151  return $this->getUrl('catalog/product/view/');
152  }
153 
161  public function getProductUrl($product)
162  {
163  return $product->getProductUrl();
164  }
165 
172  public function dateFormat($date)
173  {
174  return $this->formatDate($date, \IntlDateFormatter::SHORT);
175  }
176 
182  protected function _beforeToHtml()
183  {
184  $reviews = $this->getReviews();
185  if ($reviews) {
186  $reviews->load()->addReviewSummary();
187  }
188  return parent::_beforeToHtml();
189  }
190 }
formatDate( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
__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 _collection
Definition: coupons.php:7