You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BusinessLogic.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace common\components;
  3. use domain\Producer\Producer\Producer;
  4. use yii\base\ErrorException;
  5. class BusinessLogic
  6. {
  7. protected ?Producer $producerContext = null;
  8. use BusinessLogicTrait;
  9. public function getModules()
  10. {
  11. return [
  12. $this->getSettingModule(),
  13. $this->getFeatureModule(),
  14. $this->getFeatureProducerModule(),
  15. $this->getUnitModule(),
  16. $this->getTaxRateModule(),
  17. $this->getUserUserGroupModule(),
  18. $this->getUserGroupModule(),
  19. $this->getPaymentModule(),
  20. $this->getProducerPriceRangeModule(),
  21. $this->getUserProducerModule(),
  22. $this->getUserPointSaleModule(),
  23. $this->getUserModule(),
  24. $this->getEmailModule(),
  25. $this->getAutomaticEmailModule(),
  26. $this->getUserMessageModule(),
  27. $this->getPointSaleDistributionModule(),
  28. $this->getProductAccessoryModule(),
  29. $this->getAccessoryModule(),
  30. $this->getProductDistributionModule(),
  31. $this->getProductCategoryModule(),
  32. $this->getProductPointSaleModule(),
  33. $this->getProductPriceModule(),
  34. $this->getProductSubscriptionModule(),
  35. $this->getTicketUserModule(),
  36. $this->getTicketMessageModule(),
  37. $this->getTicketModule(),
  38. $this->getPointSaleModule(),
  39. $this->getSharedPointSaleModule(),
  40. $this->getProductModule(),
  41. $this->getRotatingProductModule(),
  42. $this->getDistributionRotatingModule(),
  43. $this->getRotatingModule(),
  44. $this->getProductOrderModule(),
  45. $this->getOrderStatusModule(),
  46. $this->getOrderStatusHistoryModule(),
  47. $this->getQuotationModule(),
  48. $this->getInvoiceModule(),
  49. $this->getDeliveryNoteModule(),
  50. $this->getDocumentModule(),
  51. $this->getSubscriptionModule(),
  52. $this->getDistributionModule(),
  53. $this->getProducerModule(),
  54. $this->getOrderModule(),
  55. ];
  56. }
  57. public function getProducerContext(): ?Producer
  58. {
  59. return $this->producerContext;
  60. }
  61. public function setProducerContext(Producer $producer = null)
  62. {
  63. $this->producerContext = $producer;
  64. foreach($this->getModules() as $module) {
  65. foreach($module->getServices() as $serviceClass) {
  66. $instanceService = $serviceClass::getInstance();
  67. $instanceService->setProducerContext($producer);
  68. }
  69. }
  70. }
  71. /*
  72. * Hiérarchie des apps
  73. */
  74. public function getModuleLevelHierarchyByService($serviceClass): int
  75. {
  76. $modulesArray = $this->getModules();
  77. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  78. foreach($modulesArray as $key => $module) {
  79. if($module->getEntityFqcn() == $entityFqcnService) {
  80. return $key;
  81. }
  82. }
  83. }
  84. public function getEntityFqcnByService(string $serviceClass): string
  85. {
  86. $modulesArray = $this->getModules();
  87. foreach($modulesArray as $module) {
  88. if(in_array($serviceClass, $module->getServices())) {
  89. return $module->getEntityFqcn();
  90. }
  91. }
  92. throw new ErrorException('Service '.$serviceClass.' introuvable dans les modules.');
  93. }
  94. }