ReportStatus.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Reports\Model;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\Exception\InputException;
  10. /**
  11. * Is report for specified event type is enabled in system configuration
  12. */
  13. class ReportStatus
  14. {
  15. /**
  16. * @var ScopeConfigInterface
  17. */
  18. private $scopeConfig;
  19. /**
  20. * ReportStatus constructor.
  21. *
  22. * @param ScopeConfigInterface $scopeConfig
  23. */
  24. public function __construct(ScopeConfigInterface $scopeConfig)
  25. {
  26. $this->scopeConfig = $scopeConfig;
  27. }
  28. /**
  29. * Is report for specified event type is enabled in system configuration
  30. *
  31. * @param string $reportEventType
  32. * @return bool
  33. * @throws InputException
  34. */
  35. public function isReportEnabled(string $reportEventType): bool
  36. {
  37. return $this->scopeConfig->isSetFlag('reports/options/enabled')
  38. && $this->scopeConfig->isSetFlag($this->getConfigPathByEventType($reportEventType));
  39. }
  40. /**
  41. * Get Config Path By Event Type
  42. *
  43. * @param string $reportEventType
  44. * @return string
  45. * @throws InputException
  46. */
  47. private function getConfigPathByEventType(string $reportEventType): string
  48. {
  49. $typeToPathMap = [
  50. Event::EVENT_PRODUCT_VIEW => 'reports/options/product_view_enabled',
  51. Event::EVENT_PRODUCT_SEND => 'reports/options/product_send_enabled',
  52. Event::EVENT_PRODUCT_COMPARE => 'reports/options/product_compare_enabled',
  53. Event::EVENT_PRODUCT_TO_CART => 'reports/options/product_to_cart_enabled',
  54. Event::EVENT_PRODUCT_TO_WISHLIST => 'reports/options/product_to_wishlist_enabled',
  55. Event::EVENT_WISHLIST_SHARE => 'reports/options/wishlist_share_enabled',
  56. ];
  57. if (!isset($typeToPathMap[$reportEventType])) {
  58. throw new InputException(
  59. __('System configuration is not found for report event type "%1"', $reportEventType)
  60. );
  61. }
  62. return $typeToPathMap[$reportEventType];
  63. }
  64. }