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.

99 lines
3.0KB

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