Jak na formulář psaný v doctrine?
- jAkErCZ
- Člen | 322
Zdravím,
mám po někom aplikace která je psaná v doctrine a potřeboval bych
poradit
mám formulář
/**
/**
* @param Form $form
* @throws AbortException
* @throws MpdfException
* @throws ORMException
*/
public function processForm(Form $form): void {
$isSave = false;
$values = $form->getValues();
$exhibitor = new Exhibitor();
/** @var Exposition $exposition */
foreach ($this->expositions as $exposition) {
if (!$values['exposition_' . $exposition->getId()]) {
continue;
}
$isSave = true;
$exhibitorExposition = new ExhibitorExposition();
$exhibitorExposition->setExhibitor($exhibitor);
$exhibitorExposition->setExposition($exposition);
bdump($exhibitorExposition);
//$this->em->persist($exhibitorExposition);
//$exhibitor->getExpositions()->add($exhibitorExposition);
foreach ($values['stands_' . $exposition->getId()] as $standId) {
/** @var Stand $stand */
$stand = $this->em->getStandRepository()->findById($standId);
$exhibitorExpositionStand = new ExhibitorExpositionStand();
$exhibitorExpositionStand->setPrice($stand->getPrice());
$exhibitorExpositionStand->setStand($stand);
$exhibitorExpositionStand->setExhibitorExposition($exhibitorExposition);
//$this->em->persist($exhibitorExpositionStand);
$exhibitorExposition->getStands()->add($exhibitorExpositionStand);
}
/** @var Equipment $equipment */
foreach ($exposition->getEquipments() as $equipment) {
if (!$values['equipment_' . $equipment->getId()] && !$equipment->isNecessary()) {
continue;
}
$exhibitorExpositionEquipment = new ExhibitorExpositionEquipment();
$exhibitorExpositionEquipment->setPrice($equipment->getPrice());
$exhibitorExpositionEquipment->setEquipment($equipment);
$exhibitorExpositionEquipment->setExhibitorExposition($exhibitorExposition);
//$this->em->persist($exhibitorExpositionEquipment);
$exhibitorExposition->getEquipments()->add($exhibitorExpositionEquipment);
}
}
if (!$isSave) {
$this->getPresenter()->flashMessage('Musíte vybrat alespoň jednu událost a termín.', 'danger');
return;
}
$this->em->flush();
}
a když si dupnu bdump($exhibitorExposition); tak mi to vátí
exposition private =>
exhibitor private =>
equipments private =>
elements private => array ()
stands private =>
elements private => array ()
id private => null
což je v pořádku ale v db mi to vytvoří řádek kde se dosadí exposition_id v pořádku ale na exhibitor_id mi do dosadí null jak tam ale dosadit to id co potřebuji?
id exposition_id exhibitor_id
361 3 NULL
362 3 NULL
363 3 NULL
Původní presenter:
/**
* @param Form $form
* @throws AbortException
* @throws MpdfException
* @throws ORMException
*/
public function processForm(Form $form): void {
$values = $form->getValues();
// Create exhibitor
$exhibitor = new Exhibitor();
$exhibitor->setCompany($values->company);
$exhibitor->setCompanyId($values->companyId);
$exhibitor->setStreet($values->street);
$exhibitor->setStreetNumber($values->streetNumber);
$exhibitor->setTown($values->town);
$exhibitor->setZip($values->zip);
$exhibitor->setSocial($values->social);
$exhibitor->setCompanyVat($values->companyVat);
$exhibitor->setContactName($values->contactName);
$exhibitor->setEmail($values->email);
$exhibitor->setContactEmail($values->email);
$exhibitor->setContactPhone($values->contactPhone);
$exhibitor->setTrader($values->trader ? $this->em->getExhibitorTraderRepository()->findById($values->trader) : null);
$exhibitor->setState($this->em->getExhibitorStateRepository()->findById(ExhibitorStateRepository::NEW_STATE));
$this->em->persist($exhibitor);
$isSave = false;
/** @var Exposition $exposition */
foreach ($this->expositions as $exposition) {
if (!$values['exposition_' . $exposition->getId()]) {
continue;
}
$isSave = true;
$exhibitorExposition = new ExhibitorExposition();
$exhibitorExposition->setExhibitor($exhibitor);
$exhibitorExposition->setExposition($exposition);
$this->em->persist($exhibitorExposition);
$exhibitor->getExpositions()->add($exhibitorExposition);
foreach ($values['stands_' . $exposition->getId()] as $standId) {
/** @var Stand $stand */
$stand = $this->em->getStandRepository()->findById($standId);
$exhibitorExpositionStand = new ExhibitorExpositionStand();
$exhibitorExpositionStand->setPrice($stand->getPrice());
$exhibitorExpositionStand->setStand($stand);
$exhibitorExpositionStand->setExhibitorExposition($exhibitorExposition);
$this->em->persist($exhibitorExpositionStand);
$exhibitorExposition->getStands()->add($exhibitorExpositionStand);
}
/** @var Equipment $equipment */
foreach ($exposition->getEquipments() as $equipment) {
if (!$values['equipment_' . $equipment->getId()] && !$equipment->isNecessary()) {
continue;
}
$exhibitorExpositionEquipment = new ExhibitorExpositionEquipment();
$exhibitorExpositionEquipment->setPrice($equipment->getPrice());
$exhibitorExpositionEquipment->setEquipment($equipment);
$exhibitorExpositionEquipment->setExhibitorExposition($exhibitorExposition);
$this->em->persist($exhibitorExpositionEquipment);
$exhibitorExposition->getEquipments()->add($exhibitorExpositionEquipment);
}
}
if (!$isSave) {
$this->getPresenter()->flashMessage('Musíte vybrat alespoň jednu událost a termín.', 'danger');
return;
}
$this->em->flush();
// Set VS
$this->em->getExhibitorRepository()->saveVS($exhibitor);
$this->em->persist($exhibitor);
$this->em->flush();
// Send email
$this->sendEmail($exhibitor);
$this->getPresenter()->redirect('Homepage:success', $exhibitor->getId());
}
Díky
Editoval jAkErCZ (21. 5. 2020 14:47)
- jAkErCZ
- Člen | 322
Mysteria napsal(a):
Zkusil bych jak tam máš
$exhibitor->getExpositions()->add($exhibitorExposition);
přidat i tu druhou vazbu, tzn. něco jako$exposition->getExhibitors()->add($exhibitorExposition);
.
Já právě potřebuji nějak dostat to ID do $exhibitorExposition->setExhibitor($exhibitor); dle původního
// Create exhibitor
$exhibitor = new Exhibitor();
$exhibitor->setCompany($values->company);
$exhibitor->setCompanyId($values->companyId);
$exhibitor->setStreet($values->street);
$exhibitor->setStreetNumber($values->streetNumber);
$exhibitor->setTown($values->town);
$exhibitor->setZip($values->zip);
$exhibitor->setSocial($values->social);
$exhibitor->setCompanyVat($values->companyVat);
$exhibitor->setContactName($values->contactName);
$exhibitor->setEmail($values->email);
$exhibitor->setContactEmail($values->email);
$exhibitor->setContactPhone($values->contactPhone);
$exhibitor->setTrader($values->trader ? $this->em->getExhibitorTraderRepository()->findById($values->trader) : null);
$exhibitor->setState($this->em->getExhibitorStateRepository()->findById(ExhibitorStateRepository::NEW_STATE));
to tady vytvářelo ale nevím jak sem dostat už vytvořený…