Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

108 lines
3.4KB

  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. }