em = $em; $this->rdp = $rdp; $this->reasonResponseManager = $reasonResponseManager; $this->class = $class; $this->storage = $storage; } public function createFieldResponse(FormForgeReasonInterface $reason, Collection $formForgeField, array $dataResponse, string $locale, ?CustomUserInterface $creator = null){ if(is_null($creator)) { $creator = $this->storage->getToken()->getUser(); if(!$creator instanceof CustomUserInterface) return false; } // Create reason response $reasonResponse = $this->reasonResponseManager->createReasonResponse($reason, $locale, $creator); $index = 0; // Add response data foreach ($dataResponse as $data){ // $label = array($locale => $reason->getFormForgeFields()->getValues()[$index]->getLabel()->show($locale)); $formForgeFieldResponse = new FormForgeFieldResponse($reasonResponse); $formForgeFieldResponse->setOrder(count($reasonResponse->getFieldResponse())); $formForgeFieldResponse->setValue($data); $formForgeFieldResponse->setFormForgeField($formForgeField[$index]); $this->quickUpdateFieldResponse($formForgeFieldResponse); $index++; // Adding the answer to the "FieldsResponse()" collection $reasonResponse->addFieldResponse($formForgeFieldResponse); $this->quickUpdateReasonResponse($reasonResponse); // Adding the answer to the "FieldsResponse()" collection // $reasonResponse->addFieldResponse($formForgeFieldResponse); // $this->quickUpdateReasonResponse($reasonResponse); } return $reasonResponse; } public function quickUpdateFieldResponse(FormForgeFieldResponseInterface $element){ if(empty($element)) return false; try { $this->em->persist($element); $this->em->flush(); } catch (ORMException $e) { return false; } return true; } public function quickUpdateReasonResponse(FormForgeReasonResponseInterface $element){ if(empty($element)) return false; try { $this->em->persist($element); $this->em->flush(); } catch (ORMException $e) { return false; } return true; } }