Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BusinessLogic.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. }