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.

101 line
3.1KB

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