Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BusinessLogic.php 2.9KB

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