function load(ObjectManager $manager) { foreach ($this->models as $index => $item) { /** @var CeModel $strategy */ $strategy = $this->getReference('strategy-' . $item['parent_index']); $model = new CeModel(); $model->setName($item['name']); $model->setParent($strategy); $model->setRiskRating($item['risk_rating']); $model->setType($strategy->getType()); $manager->persist($model); $this->addReference('model-' . ($index + 1), $model); foreach ($item['entities'] as $entityItem) { /** @var SecurityAssignment $securityAssignment */ $securityAssignment = $this->getReference('model-security-assignment-' . $entityItem['security_assignment_index']); $entity = new CeModelEntity(); $entity->setModel($model); $entity->setSubclass($securityAssignment->getSubclass()); $entity->setAssetClass($securityAssignment->getSubclass()->getAssetClass()); $entity->setSecurityAssignment($securityAssignment); $entity->setPercent($entityItem['percent']); $model->addModelEntity($entity); } } $manager->flush(); }
private function createModel(ObjectManager $manager, User $riaUser) { $categories = $this->createCategories($riaUser); $modelManager = new CeModelManager($manager, '\\Wealthbot\\AdminBundle\\Entity\\CeModel'); $model = $modelManager->createCustomModel($riaUser); $model->setCommissionMin($this->strategy['commission_min']); $model->setCommissionMax($this->strategy['commission_max']); $model->setForecast($this->strategy['forecast_min']); $model->setGenerousMarketReturn($this->strategy['generous_market_return']); $model->setLowMarketReturn($this->strategy['low_market_return']); $model->setIsAssumptionLocked($this->strategy['is_assumption_locked']); $securityAssignments = array(); $isExistSecurityAssignment = function ($arr, $securityIndex) { return isset($arr[$securityIndex]); }; foreach ($this->strategy['models'] as $modelItem) { $child = $modelManager->createChild($model); $child->setName($modelItem['name']); $child->setRiskRating($modelItem['risk_rating']); $child->setIsAssumptionLocked($modelItem['is_assumption_locked']); $model->addChildren($child); foreach ($modelItem['entities'] as $entityItem) { /** @var AssetClass $assetClass */ $assetClass = $categories[$entityItem['asset_class_index']]; $assetClass->setModel($model); $subclass = $assetClass->getSubclasses()->get($entityItem['subclass_index']); /** @var Security $security */ $security = $this->getReference('security-' . $entityItem['security']); if ($isExistSecurityAssignment($securityAssignments, $entityItem['security'])) { $securityAssignment = $securityAssignments[$entityItem['security']]; } else { $securityAssignment = new SecurityAssignment(); $securityAssignment->setSecurity($security); $securityAssignment->setSubclass($subclass); $securityAssignment->setModel($model); $securityAssignments[$entityItem['security']] = $securityAssignment; $this->addReference('model-security-assignment-asset-index-' . $entityItem['asset_class_index'] . '-subclass-index-' . $entityItem['subclass_index'] . '-security-' . $entityItem['security'], $securityAssignment); } $entity = new CeModelEntity(); $entity->setModel($child); $entity->setAssetClass($assetClass); $entity->setSubclass($subclass); $entity->setSecurityAssignment($securityAssignment); $entity->setPercent($entityItem['percent']); if ($entityItem['muni_substitution_security']) { /** @var Security $muniSubstitutionSecurity */ $muniSubstitutionSecurity = $this->getReference('security-' . $entityItem['muni_substitution_security']); if ($isExistSecurityAssignment($securityAssignments, $entityItem['muni_substitution_security'])) { /** @var securityAssignment $muniSubstitutionAssignment */ $muniSubstitutionAssignment = $securityAssignments[$entityItem['muni_substitution_security']]; $muniSubstitutionAssignment->setMuniSubstitution(true); } else { $muniSubstitutionAssignment = new SecurityAssignment(); $muniSubstitutionAssignment->setSecurity($muniSubstitutionSecurity); $muniSubstitutionAssignment->setSubclass($subclass); $muniSubstitutionAssignment->setModel($model); $securityAssignments[$entityItem['muni_substitution_security']] = $muniSubstitutionAssignment; } $entity->setMuniSubstitution($muniSubstitutionAssignment); } if ($entityItem['tax_loss_harvesting_security']) { /** @var Security $taxLossHarvestingSecurity */ $taxLossHarvestingSecurity = $this->getReference('security-' . $entityItem['tax_loss_harvesting_security']); if ($isExistSecurityAssignment($securityAssignments, $entityItem['tax_loss_harvesting_security'])) { /** @var securityAssignment $taxLossHarvestingAssignment */ $taxLossHarvestingAssignment = $securityAssignments[$entityItem['tax_loss_harvesting_security']]; $taxLossHarvestingAssignment->setMuniSubstitution(true); } else { $taxLossHarvestingAssignment = new SecurityAssignment(); $taxLossHarvestingAssignment->setSecurity($taxLossHarvestingSecurity); $taxLossHarvestingAssignment->setSubclass($subclass); $taxLossHarvestingAssignment->setModel($model); $securityAssignments[$entityItem['tax_loss_harvesting_security']] = $taxLossHarvestingAssignment; } $entity->setTaxLossHarvesting($taxLossHarvestingAssignment); } $child->addModelEntity($entity); } $this->addReference('cec-ria-model-' . $modelItem['index'], $child); } return $model; }