コード例 #1
0
 public function onUpload(PostPersistEvent $event)
 {
     $file = $event->getFile();
     /* @var $file \Symfony\Component\HttpFoundation\File\File */
     $request = $event->getRequest();
     $response = $event->getResponse();
     $r = array();
     $em = $this->doctrine->getEntityManager();
     if ($request->get('attachment')) {
         $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('attachment'));
         $documento = new Documento();
         $documento->setFile('upload/' . $contratto->getId() . '/documenti/' . $file->move('upload/' . $contratto->getId() . '/documenti/', $file->getFileName())->getFileName());
         $documento->setContratto($contratto);
         $r = array('name' => $file->getFilename(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/attachment/' . $file->getFilename());
         $documento->setJson($r);
         $em->persist($documento);
         $em->flush();
     } elseif ($request->get('contratto_id')) {
         $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('contratto_id'));
         /* @var $contratto \Casa\Front2Bundle\Entity\Contratto */
         $foto = new Foto();
         $foto->setContratto($contratto);
         $foto->setFile($file->getFilename());
         $foto->setPrincipale(count($contratto->getFoto()) == 0);
         $em->persist($foto);
         $em->flush();
         $r = array('name' => $file->getFilename(), 'size' => $file->getSize(), 'type' => $file->getMimeType(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/gallery/' . $foto->getFile());
         // Image sizes (x >= y):
         $size = array('bigImage' => array('x' => 1024, 'y' => 768), 'mediumImage' => array('x' => 600, 'y' => 400), 'thumbnail' => array('x' => 300, 'y' => 227), 'icon' => array('x' => 64, 'y' => 64));
         $this->gdResize($size, $file, $r);
         $foto->setJson($r);
         $em->persist($foto);
         $em->flush();
     } else {
         unlink($file->getRealPath());
         $response['error'] = "File format don't supported";
     }
     $response['files'] = array($r);
 }
コード例 #2
0
 /**
  * Finds and displays a Scheda entity.
  *
  * @Route("/{id}/fotografie", name="scheda_fotografie")
  * @Method("GET")
  * @Template()
  */
 public function fotografieAction($id)
 {
     $contratto = $this->find('CasaFront2Bundle:Contratto', $id);
     /* @var $contratto Contratto */
     $entity = null;
     /* @var $entity Scheda */
     if (!$contratto) {
         $entity = $this->find('CasaFront2Bundle:Scheda', $id);
         $contratto = $entity->getContratti()->first();
         if (!$contratto) {
             throw $this->createNotFoundException('Unable to find Contratto entity');
         }
     } else {
         $entity = $contratto->getScheda();
     }
     $foto = new Foto();
     $foto->setContratto($contratto->getId());
     $form = $this->createCreateFotoForm($foto);
     return array('entity' => $entity, 'contratto' => $contratto, 'form' => $form->createView());
 }