|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
-
- namespace common\components;
-
- use domain\Producer\Producer\Producer;
- use yii\base\ErrorException;
-
- class BusinessLogic
- {
- protected ?Producer $producerContext = null;
-
- use BusinessLogicTrait;
-
- public function getModules()
- {
- return [
- $this->getSettingModule(),
- $this->getFeatureModule(),
- $this->getFeatureProducerModule(),
- $this->getUnitModule(),
- $this->getTaxRateModule(),
- $this->getUserUserGroupModule(),
- $this->getUserGroupModule(),
- $this->getPaymentModule(),
- $this->getProducerPriceRangeModule(),
- $this->getUserProducerModule(),
- $this->getUserPointSaleModule(),
- $this->getUserModule(),
- $this->getPointSaleDistributionModule(),
- $this->getProductDistributionModule(),
- $this->getProductCategoryModule(),
- $this->getProductPointSaleModule(),
- $this->getProductPriceModule(),
- $this->getProductSubscriptionModule(),
- $this->getTicketUserModule(),
- $this->getTicketMessageModule(),
- $this->getTicketModule(),
- $this->getPointSaleModule(),
- $this->getProductModule(),
- $this->getProductOrderModule(),
- $this->getQuotationModule(),
- $this->getInvoiceModule(),
- $this->getDeliveryNoteModule(),
- $this->getDocumentModule(),
- $this->getSubscriptionModule(),
- $this->getDistributionModule(),
- $this->getProducerModule(),
- $this->getOrderModule(),
- ];
- }
-
- public function getProducerContext(): ?Producer
- {
- return $this->producerContext;
- }
-
- public function setProducerContext(Producer $producer = null)
- {
- $this->producerContext = $producer;
-
- foreach($this->getModules() as $module) {
- foreach($module->getServices() as $serviceClass) {
- $instanceService = $serviceClass::getInstance();
- $instanceService->setProducerContext($producer);
- }
- }
- }
-
- /*
- * Hiérarchie des apps
- */
-
- public function getModuleLevelHierarchyByService($serviceClass): int
- {
- $modulesArray = $this->getModules();
- $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
-
- foreach($modulesArray as $key => $module) {
- if($module->getEntityFqcn() == $entityFqcnService) {
- return $key;
- }
- }
- }
-
- public function getEntityFqcnByService(string $serviceClass): string
- {
- $modulesArray = $this->getModules();
-
- foreach($modulesArray as $module) {
- if(in_array($serviceClass, $module->getServices())) {
- return $module->getEntityFqcn();
- }
- }
-
- throw new ErrorException('Service '.$serviceClass.' introuvable dans les modules.');
- }
- }
|