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.

103 lines
3.2KB

  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->getUserMessageModule(),
  25. $this->getPointSaleDistributionModule(),
  26. $this->getProductAccessoryModule(),
  27. $this->getAccessoryModule(),
  28. $this->getProductDistributionModule(),
  29. $this->getProductCategoryModule(),
  30. $this->getProductPointSaleModule(),
  31. $this->getProductPriceModule(),
  32. $this->getProductSubscriptionModule(),
  33. $this->getTicketUserModule(),
  34. $this->getTicketMessageModule(),
  35. $this->getTicketModule(),
  36. $this->getPointSaleModule(),
  37. $this->getSharedPointSaleModule(),
  38. $this->getProductModule(),
  39. $this->getProductOrderModule(),
  40. $this->getOrderStatusModule(),
  41. $this->getOrderStatusHistoryModule(),
  42. $this->getQuotationModule(),
  43. $this->getInvoiceModule(),
  44. $this->getDeliveryNoteModule(),
  45. $this->getDocumentModule(),
  46. $this->getSubscriptionModule(),
  47. $this->getDistributionModule(),
  48. $this->getProducerModule(),
  49. $this->getOrderModule(),
  50. ];
  51. }
  52. public function getProducerContext(): ?Producer
  53. {
  54. return $this->producerContext;
  55. }
  56. public function setProducerContext(Producer $producer = null)
  57. {
  58. $this->producerContext = $producer;
  59. foreach($this->getModules() as $module) {
  60. foreach($module->getServices() as $serviceClass) {
  61. $instanceService = $serviceClass::getInstance();
  62. $instanceService->setProducerContext($producer);
  63. }
  64. }
  65. }
  66. /*
  67. * Hiérarchie des apps
  68. */
  69. public function getModuleLevelHierarchyByService($serviceClass): int
  70. {
  71. $modulesArray = $this->getModules();
  72. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  73. foreach($modulesArray as $key => $module) {
  74. if($module->getEntityFqcn() == $entityFqcnService) {
  75. return $key;
  76. }
  77. }
  78. }
  79. public function getEntityFqcnByService(string $serviceClass): string
  80. {
  81. $modulesArray = $this->getModules();
  82. foreach($modulesArray as $module) {
  83. if(in_array($serviceClass, $module->getServices())) {
  84. return $module->getEntityFqcn();
  85. }
  86. }
  87. throw new ErrorException('Service '.$serviceClass.' introuvable dans les modules.');
  88. }
  89. }