/**
  * @Route(
  *      "/attachPost/ticket/{id}",
  *      name="diamante_ticket_create_attach_post",
  *      requirements={"id"="\d+"}
  * )
  *
  * @param int $id
  * @return Response
  */
 public function attachPostAction($id)
 {
     $ticket = $this->get('diamante.ticket.service')->loadTicket($id);
     $response = null;
     $session = $this->get('session');
     $commandFactory = new CommandFactory();
     $form = $this->createForm(new AttachmentType(), $commandFactory->createAddTicketAttachmentCommand($ticket));
     $formView = $form->createView();
     $formView->children['attachmentsInput']->vars = array_replace($formView->children['attachmentsInput']->vars, array('full_name' => 'diamante_attachment_form[attachmentsInput][]'));
     $beforeUploadAttachments = $ticket->getAttachments()->toArray();
     try {
         $this->handle($form);
         $command = $form->getData();
         /** @var TicketService $ticketService */
         $ticketService = $this->get('diamante.ticket.service');
         $ticketService->addAttachmentsForTicket($command);
         $this->addSuccessMessage('diamante.desk.attachment.messages.create.success');
         if ($this->getRequest()->request->get('diam-dropzone')) {
             $response = new Response();
             try {
                 $afterUploadAttachments = $ticket->getAttachments()->toArray();
                 $uploadedAttachments = $this->getAttachmentsDiff($afterUploadAttachments, $beforeUploadAttachments);
                 foreach ($uploadedAttachments as $att) {
                     $uploadedAttachmentsIds[] = $att->getId();
                 }
                 $session->set('recent_attachments_ids', $uploadedAttachmentsIds);
                 $response->setStatusCode(200);
             } catch (\Exception $e) {
                 $this->container->get('monolog.logger.diamante')->error(sprintf('Adding attachment failed: %s', $e->getMessage()));
                 $response->setStatusCode(500);
             }
         } else {
             $response = $this->get('oro_ui.router')->redirectAfterSave(['route' => 'diamante_attachment_attach', 'parameters' => []], ['route' => 'diamante_ticket_view', 'parameters' => ['key' => (string) $ticket->getKey()]]);
         }
     } catch (MethodNotAllowedException $e) {
         $response = array('form' => $formView);
     } catch (\Exception $e) {
         $this->container->get('monolog.logger.diamante')->error(sprintf('Adding attachment failed: %s', $e->getMessage()));
         $this->addErrorMessage('diamante.desk.attachment.messages.create.error');
         $response = array('form' => $formView);
     }
     return $response;
 }
 /**
  * @Route(
  *      "/attachPost/ticket/{id}",
  *      name="diamante_ticket_create_attach_post",
  *      requirements={"id"="\d+"}
  * )
  *
  * @param int $id
  * @return Response
  */
 public function attachPostAction($id)
 {
     $ticketService = $this->get('diamante.ticket.service');
     $ticket = $ticketService->loadTicket($id);
     $response = null;
     $commandFactory = new CommandFactory();
     $form = $this->createForm('diamante_attachment_form', $commandFactory->createAddTicketAttachmentCommand($ticket));
     $formView = $form->createView();
     $formView->children['attachmentsInput']->vars = array_replace($formView->children['attachmentsInput']->vars, array('full_name' => 'diamante_attachment_form[attachmentsInput][]'));
     try {
         $this->handle($form);
         $command = $form->getData();
         $uploadedAttachments = $ticketService->addAttachmentsForTicket($command);
         $this->addSuccessMessage('diamante.desk.attachment.messages.create.success');
         if ($this->container->get('request')->request->get('diam-dropzone')) {
             $response = $this->prepareDropzoneAttachmentsResponse($id, $uploadedAttachments);
         } else {
             $response = $this->get('oro_ui.router')->redirectAfterSave(['route' => 'diamante_attachment_attach', 'parameters' => []], ['route' => 'diamante_ticket_view', 'parameters' => ['key' => (string) $ticket->getKey()]]);
         }
     } catch (\Exception $e) {
         $this->handleException($e);
         $response = array('form' => $formView);
     }
     return $response;
 }