You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7KB

  1. <?php
  2. namespace common\components;
  3. use common\logic\Producer\Producer\Model\Producer;
  4. use yii\base\ErrorException;
  5. class BusinessLogic
  6. {
  7. use BusinessLogicTrait;
  8. public function getContainers()
  9. {
  10. return [
  11. $this->getTaxRateContainer(),
  12. $this->getUserUserGroupContainer(),
  13. $this->getUserGroupContainer(),
  14. $this->getCreditHistoryContainer(),
  15. $this->getProducerPriceRangeContainer(),
  16. $this->getUserProducerContainer(),
  17. $this->getUserPointSaleContainer(),
  18. $this->getUserContainer(),
  19. $this->getPointSaleDistributionContainer(),
  20. $this->getProductDistributionContainer(),
  21. $this->getProductCategoryContainer(),
  22. $this->getProductPointSaleContainer(),
  23. $this->getProductOrderContainer(),
  24. $this->getProductPriceContainer(),
  25. $this->getProductSubscriptionContainer(),
  26. $this->getTicketUserContainer(),
  27. $this->getTicketMessageContainer(),
  28. $this->getTicketContainer(),
  29. $this->getQuotationContainer(),
  30. $this->getInvoiceContainer(),
  31. $this->getDeliveryNoteContainer(),
  32. $this->getDocumentContainer(),
  33. $this->getPointSaleContainer(),
  34. $this->getSubscriptionContainer(),
  35. $this->getProductContainer(),
  36. $this->getDistributionContainer(),
  37. $this->getProducerContainer(),
  38. $this->getOrderContainer(),
  39. ];
  40. }
  41. public function setProducerContext(Producer $producer)
  42. {
  43. foreach($this->getContainers() as $container) {
  44. foreach($container->getServices() as $serviceClass) {
  45. $instanceService = $serviceClass::getInstance();
  46. $instanceService->setProducerContext($producer);
  47. }
  48. }
  49. }
  50. /*
  51. * Hiérarchie des apps
  52. */
  53. public function getContainerLevelHierarchyByService($serviceClass): int
  54. {
  55. $containersArray = $this->getContainers();
  56. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  57. foreach($containersArray as $key => $container) {
  58. if($container->getEntityFqcn() == $entityFqcnService) {
  59. return $key;
  60. }
  61. }
  62. }
  63. public function getEntityFqcnByService(string $serviceClass): string
  64. {
  65. $containersArray = $this->getContainers();
  66. foreach($containersArray as $container) {
  67. if(in_array($serviceClass, $container->getServices())) {
  68. return $container->getEntityFqcn();
  69. }
  70. }
  71. throw new ErrorException('Service '.$serviceClass.' introuvable dans les containers.');
  72. }
  73. }