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.

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