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ů.

95 lines
2.8KB

  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->getUnitModule(),
  14. $this->getTaxRateModule(),
  15. $this->getUserUserGroupModule(),
  16. $this->getUserGroupModule(),
  17. $this->getPaymentModule(),
  18. $this->getProducerPriceRangeModule(),
  19. $this->getUserProducerModule(),
  20. $this->getUserPointSaleModule(),
  21. $this->getUserModule(),
  22. $this->getPointSaleDistributionModule(),
  23. $this->getProductDistributionModule(),
  24. $this->getProductCategoryModule(),
  25. $this->getProductPointSaleModule(),
  26. $this->getProductPriceModule(),
  27. $this->getProductSubscriptionModule(),
  28. $this->getTicketUserModule(),
  29. $this->getTicketMessageModule(),
  30. $this->getTicketModule(),
  31. $this->getPointSaleModule(),
  32. $this->getProductModule(),
  33. $this->getProductOrderModule(),
  34. $this->getQuotationModule(),
  35. $this->getInvoiceModule(),
  36. $this->getDeliveryNoteModule(),
  37. $this->getDocumentModule(),
  38. $this->getSubscriptionModule(),
  39. $this->getDistributionModule(),
  40. $this->getProducerModule(),
  41. $this->getOrderModule(),
  42. ];
  43. }
  44. public function getProducerContext(): ?Producer
  45. {
  46. return $this->producerContext;
  47. }
  48. public function setProducerContext(Producer $producer)
  49. {
  50. $this->producerContext = $producer;
  51. foreach($this->getModules() as $module) {
  52. foreach($module->getServices() as $serviceClass) {
  53. $instanceService = $serviceClass::getInstance();
  54. $instanceService->setProducerContext($producer);
  55. }
  56. }
  57. }
  58. /*
  59. * Hiérarchie des apps
  60. */
  61. public function getModuleLevelHierarchyByService($serviceClass): int
  62. {
  63. $modulesArray = $this->getModules();
  64. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  65. foreach($modulesArray as $key => $module) {
  66. if($module->getEntityFqcn() == $entityFqcnService) {
  67. return $key;
  68. }
  69. }
  70. }
  71. public function getEntityFqcnByService(string $serviceClass): string
  72. {
  73. $modulesArray = $this->getModules();
  74. foreach($modulesArray as $module) {
  75. if(in_array($serviceClass, $module->getServices())) {
  76. return $module->getEntityFqcn();
  77. }
  78. }
  79. throw new ErrorException('Service '.$serviceClass.' introuvable dans les modules.');
  80. }
  81. }