Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Recent.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
23  protected $_template = 'Magento_Review::customer/list.phtml';
24 
30  protected $_collection;
31 
38 
42  protected $currentCustomer;
43 
50  public function __construct(
51  \Magento\Framework\View\Element\Template\Context $context,
52  \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $collectionFactory,
53  \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
54  array $data = []
55  ) {
56  $this->_collectionFactory = $collectionFactory;
57  parent::__construct($context, $data);
58  $this->currentCustomer = $currentCustomer;
59  }
60 
71  public function truncateString($value, $length = 80, $etc = '...', &$remainder = '', $breakWords = true)
72  {
73  return $this->filterManager->truncate(
74  $value,
75  ['length' => $length, 'etc' => $etc, 'remainder' => $remainder, 'breakWords' => $breakWords]
76  );
77  }
78 
84  public function getReviews()
85  {
86  if (!($customerId = $this->currentCustomer->getCustomerId())) {
87  return [];
88  }
89  if (!$this->_collection) {
90  $this->_collection = $this->_collectionFactory->create();
91  $this->_collection
92  ->addStoreFilter($this->_storeManager->getStore()->getId())
93  ->addCustomerFilter($customerId)
94  ->setDateOrder()
95  ->setPageSize(5)
96  ->load()
97  ->addReviewSummary();
98  }
99  return $this->_collection;
100  }
101 
107  public function getReviewLink()
108  {
109  return $this->getUrl('review/customer/view/');
110  }
111 
117  public function getProductLink()
118  {
119  return $this->getUrl('catalog/product/view/');
120  }
121 
128  public function dateFormat($date)
129  {
130  return $this->formatDate($date, \IntlDateFormatter::SHORT);
131  }
132 
138  public function getAllReviewsUrl()
139  {
140  return $this->getUrl('review/customer');
141  }
142 
149  public function getReviewUrl($id)
150  {
151  return $this->getUrl('review/customer/view', ['id' => $id]);
152  }
153 }
$id
Definition: fieldset.phtml:14
formatDate( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
$value
Definition: gender.phtml:16
$this _collection
Definition: coupons.php:7
truncateString($value, $length=80, $etc='...', &$remainder='', $breakWords=true)
Definition: Recent.php:71
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $collectionFactory, \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer, array $data=[])
Definition: Recent.php:50