Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

105 lines
3.3KB

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