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.

82 line
2.6KB

  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->getOrderSatusHistoryContainer(),
  20. $this->getPointSaleDistributionContainer(),
  21. $this->getProductDistributionContainer(),
  22. $this->getProductCategoryContainer(),
  23. $this->getProductPointSaleContainer(),
  24. $this->getProductOrderContainer(),
  25. $this->getProductPriceContainer(),
  26. $this->getProductSubscriptionContainer(),
  27. $this->getQuotationContainer(),
  28. $this->getInvoiceContainer(),
  29. $this->getDeliveryNoteContainer(),
  30. $this->getDocumentContainer(),
  31. $this->getPointSaleContainer(),
  32. $this->getSubscriptionContainer(),
  33. $this->getProductContainer(),
  34. $this->getDistributionContainer(),
  35. $this->getProducerContainer(),
  36. $this->getOrderContainer(),
  37. ];
  38. }
  39. public function setProducerContext(Producer $producer)
  40. {
  41. foreach($this->getContainers() as $container) {
  42. foreach($container->getServices() as $serviceClass) {
  43. $instanceService = $serviceClass::getInstance();
  44. $instanceService->setProducerContext($producer);
  45. }
  46. }
  47. }
  48. /*
  49. * Hiérarchie des apps
  50. */
  51. public function getContainerLevelHierarchyByService($serviceClass): int
  52. {
  53. $containersArray = $this->getContainers();
  54. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  55. foreach($containersArray as $key => $container) {
  56. if($container->getEntityFqcn() == $entityFqcnService) {
  57. return $key;
  58. }
  59. }
  60. }
  61. public function getEntityFqcnByService(string $serviceClass): string
  62. {
  63. $containersArray = $this->getContainers();
  64. foreach($containersArray as $container) {
  65. if(in_array($serviceClass, $container->getServices())) {
  66. return $container->getEntityFqcn();
  67. }
  68. }
  69. throw new ErrorException('Service '.$serviceClass.' introuvable dans les containers.');
  70. }
  71. }