get('net15.form.forge.reasons.manager')->getAll(); $locale = $container->get('request_stack')->getCurrentRequest()->getLocale(); return $this->render("@FormForge/FormForgeReason/default.html.twig",[ 'ticketReasonList'=>$ticketReasonList, 'lang'=>$locale ]); } /** * @param ContainerInterface $container * @return Response */ public function createAction(ContainerInterface $container){ $locale = $container->get('request_stack')->getCurrentRequest()->getLocale(); $formForgeFieldsTypeList = $container->get('net15.form.forge.type.manager')->getAll(); /** * @var User $user */ return $this->render('@FormForge/FormForgeReason/view.html.twig',[ 'reason'=>null, 'lang'=>$locale, 'fieldsType'=>$formForgeFieldsTypeList ]); } /** * @param Request $request * @param ContainerInterface $container * @return RedirectResponse */ public function validate_createReasonAction(Request $request, ContainerInterface $container){ $submittedToken = $request->request->get('_csrf_token'); if($this->isCsrfTokenValid('support_ticket_new_reason',$submittedToken)){ $languages = array(); $languages['fr'] = $request->get('name_fr'); $languages['en'] = $request->get('name_en'); $languages['es'] = $request->get('name_es'); $redirectURL = $request->get('redirectURL'); $reasonTag = $request->get('tag'); $reason = $container->get('net15.form.forge.reasons.manager')->create($languages, $redirectURL, $reasonTag); return $this->redirectToRoute('form_forge_update_reason',['publicKey'=>$reason->getPublicKey()]); } return $this->redirectToRoute('form_forge_new_reason',[]); } /** * @param string $publicKey * @param ContainerInterface $container * @return Response */ public function updateAction(string $publicKey, ContainerInterface $container){ $reason_list = $container->get('net15.form.forge.reasons.manager')->getAll(); $reason = $container->get('net15.form.forge.reasons.manager')->getByPublicKey($publicKey); $locale = $container->get('request_stack')->getCurrentRequest()->getLocale(); $formForgeFieldsTypeList = $container->get('net15.form.forge.type.manager')->getAll(); /** * @var User $user */ return $this->render('@FormForge/FormForgeReason/view.html.twig',[ 'reason' => $reason, 'lang' => $locale, 'fieldsType' => $formForgeFieldsTypeList, 'reason_list' => $reason_list ]); } /** * @param string $publicKey * @param ContainerInterface $container * @return Response */ public function editReasonAction(string $publicKey, ContainerInterface $container) { $reason = $container->get('net15.form.forge.reasons.manager')->getByPublicKey($publicKey); $locale = $container->get('request_stack')->getCurrentRequest()->getLocale(); return $this->render('@FormForge/FormForgeReason/edit.reason.html.twig',['reason'=>$reason, 'lang'=>$locale]); } /** * @param Request $request * @param ContainerInterface $container * @return Response */ public function updateReasonAction(Request $request, ContainerInterface $container) { $languages = array(); $languages['fr'] = trim($request->get('name_fr')); $languages['en'] = trim($request->get('name_en')); $languages['es'] = trim($request->get('name_es')); $redirectURL = trim($request->get('redirectURL')); $tag = trim($request->get('tag')); $reason = $container->get('net15.form.forge.reasons.manager')->updateReason($request->get('publicKey'), $languages, $redirectURL, $tag); $locale = $container->get('request_stack')->getCurrentRequest()->getLocale(); return $this->render('@FormForge/FormForgeReason/show.text.name.html.twig', [ 'reason' => $reason, 'lang' => $locale ]); } /** * @param string $publicKey * @param ContainerInterface $container * @return RedirectResponse */ public function deleteAction(string $publicKey, ContainerInterface $container){ $container->get('net15.form.forge.reasons.manager')->delete($publicKey); return $this->redirectToRoute('form_forge_reason_list'); } /** * @param FormForgeReason $reason * @param ContainerInterface $container * @return Response */ public function export(FormForgeReason $reason, ContainerInterface $container){ $return = $container->get('net15.restifier.process')->objectToArray( $reason, [ 'name', 'tag', 'formForgeFields', 'description', 'active', 'formForgeMappingEvents', 'redirectURL','xLarge','parameter'], [ 'FormForgeMappingEvent' => ['name'], 'LinguisticaTradItem' => ['strValues'], 'FormForgeField' => ['label','values','formForgeType','order','required','fieldTag','small','medium','large','xLarge', 'parameter'], 'FormForgeFieldValue' => ['strValues','order'], 'FormForgeType' => ['id','name'] ] ); $filename = "export-reason-".$reason->getId().".json"; $response = new Response(); $response->headers->set('Content-type', 'application/json'); $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename)); $response->setContent(json_encode($return)); return $response; } public function import(Request $request, ContainerInterface $container) { // $file = ->get('file'); $file = $request->files->get('import_file'); /** * @var $file UploadedFile */ $file->move($container->get('kernel')->getProjectDir(),'import.json'); $json_filename = $container->get('kernel')->getProjectDir().DIRECTORY_SEPARATOR.'import.json'; $json = file_get_contents($json_filename); @unlink($json_filename); $data = json_decode($json, true); $reason = $container->get('net15.form.forge.reasons.manager')->create( $data['name']['strValues'], $data['redirectURL'], $data['tag'] ); if ($reason !== null) { $reason->setDescription($data['description']); $reason->setActive($data['active']); foreach ($data['formForgeFields'] as $formForgeField) { $label = $formForgeField['label']; $type = $container->get('net15.form.forge.type.manager')->getByName( $formForgeField['formForgeType']['name'] ); $field = $container->get('net15.form.forge.fields.manager')->create( $reason, 'temp', 'fr', $type, $formForgeField['required'], $formForgeField['order'], $formForgeField['fieldTag'], $formForgeField['small'], $formForgeField['medium'], $formForgeField['large'], $formForgeField['xLarge'], $formForgeField['parameter'] ); if ($field !== null) { $field->getLabel()->setStrValues($formForgeField['label']['strValues']); foreach ($formForgeField['values'] as $value) { $fieldValue = new FormForgeFieldValue(); $fieldValue->setFormForgeField($field); foreach ($value['strValues'] as $locale => $content) { $fieldValue->addStrValues($content, $locale); } $fieldValue->setOrder($value['order']); $fieldValue->setDeleted(0); $container->get('net15.form.forge.field.value.manager')->quickUpdateValue($fieldValue); $field->addValue($fieldValue); } $container->get('net15.form.forge.fields.manager')->quickUpdate($field); $reason->addFormForgeField($field); } } foreach ($data['formForgeMappingEvents'] as $mappingEventData){ $mappingEvent = $container->get('net15.form.forge.mapping.events.manager')->getByName($mappingEventData['name']); if($mappingEvent !== null) $reason->addFormForgeMappingEvent($mappingEvent); } $container->get('net15.form.forge.reasons.manager')->quickUpdate($reason); return $this->redirectToRoute('form_forge_reason_list'); } return new Response("Failed"); } }