_collectionFactory = $collectionFactory; parent::__construct($context, $data); $this->currentCustomer = $currentCustomer; } /** * Truncate string * * @param string $value * @param int $length * @param string $etc * @param string &$remainder * @param bool $breakWords * @return string */ public function truncateString($value, $length = 80, $etc = '...', &$remainder = '', $breakWords = true) { return $this->filterManager->truncate( $value, ['length' => $length, 'etc' => $etc, 'remainder' => $remainder, 'breakWords' => $breakWords] ); } /** * Return collection of reviews * * @return array|\Magento\Review\Model\ResourceModel\Review\Product\Collection */ public function getReviews() { if (!($customerId = $this->currentCustomer->getCustomerId())) { return []; } if (!$this->_collection) { $this->_collection = $this->_collectionFactory->create(); $this->_collection ->addStoreFilter($this->_storeManager->getStore()->getId()) ->addCustomerFilter($customerId) ->setDateOrder() ->setPageSize(5) ->load() ->addReviewSummary(); } return $this->_collection; } /** * Return review customer view url * * @return string */ public function getReviewLink() { return $this->getUrl('review/customer/view/'); } /** * Return catalog product view url * * @return string */ public function getProductLink() { return $this->getUrl('catalog/product/view/'); } /** * Format review date * * @param string $date * @return string */ public function dateFormat($date) { return $this->formatDate($date, \IntlDateFormatter::SHORT); } /** * Return review customer url * * @return string */ public function getAllReviewsUrl() { return $this->getUrl('review/customer'); } /** * Return review customer view url for a specific customer/review * * @param int $id * @return string */ public function getReviewUrl($id) { return $this->getUrl('review/customer/view', ['id' => $id]); } }