您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BusinessLogic.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace common\components;
  3. use common\logic\Producer\Producer\Model\Producer;
  4. use common\logic\ProducerContextTrait;
  5. use yii\base\ErrorException;
  6. class BusinessLogic
  7. {
  8. protected ?Producer $producerContext = null;
  9. use BusinessLogicTrait;
  10. public function getModules()
  11. {
  12. return [
  13. $this->getSettingModule(),
  14. $this->getFeatureModule(),
  15. $this->getFeatureProducerModule(),
  16. $this->getUnitModule(),
  17. $this->getTaxRateModule(),
  18. $this->getUserUserGroupModule(),
  19. $this->getUserGroupModule(),
  20. $this->getPaymentModule(),
  21. $this->getProducerPriceRangeModule(),
  22. $this->getUserProducerModule(),
  23. $this->getUserPointSaleModule(),
  24. $this->getUserModule(),
  25. $this->getPointSaleDistributionModule(),
  26. $this->getProductDistributionModule(),
  27. $this->getProductCategoryModule(),
  28. $this->getProductPointSaleModule(),
  29. $this->getProductPriceModule(),
  30. $this->getProductSubscriptionModule(),
  31. $this->getTicketUserModule(),
  32. $this->getTicketMessageModule(),
  33. $this->getTicketModule(),
  34. $this->getPointSaleModule(),
  35. $this->getProductModule(),
  36. $this->getProductOrderModule(),
  37. $this->getQuotationModule(),
  38. $this->getInvoiceModule(),
  39. $this->getDeliveryNoteModule(),
  40. $this->getDocumentModule(),
  41. $this->getSubscriptionModule(),
  42. $this->getDistributionModule(),
  43. $this->getProducerModule(),
  44. $this->getOrderModule(),
  45. ];
  46. }
  47. public function getProducerContext(): ?Producer
  48. {
  49. return $this->producerContext;
  50. }
  51. public function setProducerContext(Producer $producer = null)
  52. {
  53. $this->producerContext = $producer;
  54. foreach($this->getModules() as $module) {
  55. foreach($module->getServices() as $serviceClass) {
  56. $instanceService = $serviceClass::getInstance();
  57. $instanceService->setProducerContext($producer);
  58. }
  59. }
  60. }
  61. /*
  62. * Hiérarchie des apps
  63. */
  64. public function getModuleLevelHierarchyByService($serviceClass): int
  65. {
  66. $modulesArray = $this->getModules();
  67. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  68. foreach($modulesArray as $key => $module) {
  69. if($module->getEntityFqcn() == $entityFqcnService) {
  70. return $key;
  71. }
  72. }
  73. }
  74. public function getEntityFqcnByService(string $serviceClass): string
  75. {
  76. $modulesArray = $this->getModules();
  77. foreach($modulesArray as $module) {
  78. if(in_array($serviceClass, $module->getServices())) {
  79. return $module->getEntityFqcn();
  80. }
  81. }
  82. throw new ErrorException('Service '.$serviceClass.' introuvable dans les modules.');
  83. }
  84. }