Data.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Helper;
  7. /**
  8. * Default review helper
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  14. {
  15. const XML_REVIEW_GUETS_ALLOW = 'catalog/review/allow_guest';
  16. /**
  17. * Filter manager
  18. *
  19. * @var \Magento\Framework\Filter\FilterManager
  20. */
  21. protected $filter;
  22. /**
  23. * Escaper
  24. *
  25. * @var \Magento\Framework\Escaper
  26. */
  27. protected $_escaper;
  28. /**
  29. * @param \Magento\Framework\App\Helper\Context $context
  30. * @param \Magento\Framework\Escaper $escaper
  31. * @param \Magento\Framework\Filter\FilterManager $filter
  32. */
  33. public function __construct(
  34. \Magento\Framework\App\Helper\Context $context,
  35. \Magento\Framework\Escaper $escaper,
  36. \Magento\Framework\Filter\FilterManager $filter
  37. ) {
  38. $this->_escaper = $escaper;
  39. $this->filter = $filter;
  40. parent::__construct($context);
  41. }
  42. /**
  43. * Get review detail
  44. *
  45. * @param string $origDetail
  46. * @return string
  47. */
  48. public function getDetail($origDetail)
  49. {
  50. return nl2br($this->filter->truncate($origDetail, ['length' => 50]));
  51. }
  52. /**
  53. * Return short detail info in HTML
  54. *
  55. * @param string $origDetail Full detail info
  56. * @return string
  57. */
  58. public function getDetailHtml($origDetail)
  59. {
  60. return nl2br($this->filter->truncate($this->_escaper->escapeHtml($origDetail), ['length' => 50]));
  61. }
  62. /**
  63. * Return an indicator of whether or not guest is allowed to write
  64. *
  65. * @return bool
  66. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  67. */
  68. public function getIsGuestAllowToWrite()
  69. {
  70. return $this->scopeConfig->isSetFlag(
  71. self::XML_REVIEW_GUETS_ALLOW,
  72. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  73. );
  74. }
  75. /**
  76. * Get review statuses with their codes
  77. *
  78. * @return array
  79. */
  80. public function getReviewStatuses()
  81. {
  82. return [
  83. \Magento\Review\Model\Review::STATUS_APPROVED => __('Approved'),
  84. \Magento\Review\Model\Review::STATUS_PENDING => __('Pending'),
  85. \Magento\Review\Model\Review::STATUS_NOT_APPROVED => __('Not Approved')
  86. ];
  87. }
  88. /**
  89. * Get review statuses as option array
  90. *
  91. * @return array
  92. */
  93. public function getReviewStatusesOptionArray()
  94. {
  95. $result = [];
  96. foreach ($this->getReviewStatuses() as $value => $label) {
  97. $result[] = ['value' => $value, 'label' => $label];
  98. }
  99. return $result;
  100. }
  101. }