No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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