/** * @Acl( * id="pmanager_default_index", * type="entity", * class="IbnabPmanagerBundle:PDFTemplate", * permission="EDIT" * ) * @Route("/pmanager/default/index", name="pmanager_default_index") * @Template("IbnabPmanagerBundle:Default:index.html.twig") */ public function indexAction() { $responseData = ['saved' => false]; $info = $this->get('request')->get('ibnab_pmanager_exportpdf'); $importForm = $this->createForm('ibnab_pmanager_exportpdf'); $attachmentManager = $this->get('oro_attachment.manager'); $responseData['form'] = $importForm->createView(); //$importForm = $this->createForm('ibnab_pmanager_exportpdf'); $responseData['entityClass'] = $info['entityClass']; $responseData['entityId'] = $info['entityId']; $responseData['process'] = $info['process'] ? $info['process'] : "download"; $pdftemplateEntity = new PDFTemplate(); if ($templateResult = $this->get('ibnab_pmanager.form.handler.exportpdf')->process()) { $entity = $this->getDoctrine()->getRepository($info['entityClass'])->findOneBy(array('id' => $info['entityId'])); $templateParams = ['entity' => $entity]; $pdfObj = $this->instancePDF($templateResult); $pdfObj->AddPage(); $outputFormat = 'pdf'; $resultForPDF = $this->get('oro_email.email_renderer')->renderWithDefaultFilters($templateResult->getContent(), $templateParams); $resultForPDF = $templateResult->getCss() . $resultForPDF; $responseData['resultForPDF'] = $resultForPDF; $pdfObj->writeHTML($responseData['resultForPDF'], true, 0, true, 0); $pdfObj->lastPage(); //substr($info['entityClass'], strrpos($str, '\\') + 1) $fileName = $this->getExportHandler()->generateTemporaryFileName($info['entityId'], $outputFormat); $pdfObj->Output($fileName, 'F'); $url = $this->get('router')->generate('oro_importexport_export_download', ['fileName' => basename($fileName)]); if ($info['process'] == 'attach') { $attachment = new Attachment(); $file = $this->getAttachmentManager()->prepareRemoteFile($fileName); $this->getAttachmentManager()->upload($file); //$attachment->save() $em = $this->getDoctrine()->getManager(); $em->persist($file); $em->flush(); $attachment->setFile($file); $em->persist($attachment); $em->flush(); //var_dump($attachment);die(); $responseData['attachment_id'] = $attachment->getId(); } $responseData['url'] = $url; $responseData['saved'] = true; } //return $this->update($pdftemplateEntity); return $responseData; }
/** * @param string $dataClass Parent entity class name * @param File|Attachment $entity File entity * @param string $fieldName Field name where new file/image field was added * * @return \Symfony\Component\Validator\ConstraintViolationListInterface */ public function validate($dataClass, $entity, $fieldName = '') { /** @var Config $entityAttachmentConfig */ if ($fieldName === '') { $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass); $mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes')); if (!$mimeTypes) { $mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types'))); } } else { $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName); /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $entityAttachmentConfig->getId(); if ($fieldConfigId->getFieldType() === 'file') { $configValue = 'upload_file_mime_types'; } else { $configValue = 'upload_image_mime_types'; } $mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue)); } $fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024; foreach ($mimeTypes as $id => $value) { $mimeTypes[$id] = trim($value); } return $this->validator->validate($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes])]); }
/** * @Route("attachment/create/{entityClass}/{entityId}", name="oro_attachment_create") * * @Template("OroAttachmentBundle:Attachment:update.html.twig") * @Acl( * id="oro_attachment_create", * type="entity", * class="OroAttachmentBundle:Attachment", * permission="CREATE" * ) */ public function createAction($entityClass, $entityId) { $entityRoutingHelper = $this->getEntityRoutingHelper(); $entity = $entityRoutingHelper->getEntity($entityClass, $entityId); $entityClass = get_class($entity); $attachmentEntity = new Attachment(); $attachmentEntity->setTarget($entity); $form = $this->createForm(new AttachmentType(), $attachmentEntity, ['parentEntityClass' => $entityClass, 'checkEmptyFile' => true]); $formAction = $entityRoutingHelper->generateUrlByRequest('oro_attachment_create', $this->getRequest(), $entityRoutingHelper->getRouteParameters($entityClass, $entityId)); return $this->update($form, $formAction); }
public function testLinkEmailAttachmentToTargetEntity() { $emailAttachment = $this->getEmailAttachment(); $this->emailAttachmentManager->method('buildAttachmentInstance')->withAnyParameters()->will($this->returnValue($this->attachment)); $emailAttachment->expects($this->once())->method('setFile')->withAnyParameters(); $this->attachment->expects($this->never())->method('setFile')->withAnyParameters(); $this->configFileValidator->expects($this->any())->method('validate')->willReturn($this->getMock('Countable')); $this->emailAttachmentManager->linkEmailAttachmentToTargetEntity($emailAttachment, new SomeEntity()); }
/** * @param AttachmentOro $attachmentOro * * @return AttachmentEntity */ public function oroToEntity(AttachmentOro $attachmentOro) { $emailAttachmentEntity = new AttachmentEntity(); $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getFilename()); $emailAttachmentContent = new EmailAttachmentContent(); $emailAttachmentContent->setContent(base64_encode($this->filesystem->get($attachmentOro->getFile()->getFilename())->getContent())); $emailAttachmentContent->setContentTransferEncoding('base64'); $emailAttachmentContent->setEmailAttachment($emailAttachmentEntity); $emailAttachmentEntity->setContent($emailAttachmentContent); $emailAttachmentEntity->setContentType($attachmentOro->getFile()->getMimeType()); $emailAttachmentEntity->setFile($attachmentOro->getFile()); $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getOriginalFilename()); return $emailAttachmentEntity; }