Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

98 lines
3.0KB

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