コード例 #1
0
 /**
  * @Route("/administration/presentation/membre/modifier/{member}", name="admin-member-edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Request $request, Member $member)
 {
     $form = $this->createForm(new MemberType(), $member, array('method' => 'POST', 'action' => $this->generateUrl('admin-member-edit', array('member' => $member->getId()))));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $ic = $this->getImageMemberConstraint();
         $errors = $this->get('validator')->validate($request->files->get('member')['photo'], $ic);
         if (count($errors) > 0) {
             foreach ($errors as $error) {
                 $form->get('photo')->addError(new FormError($error->getMessage()));
             }
             return $this->render('admin/presentation/add.html.twig', array('form' => $form->createView()));
         }
         $member = $form->getData();
         if (null !== $request->files->get('member')['photo']) {
             $file = new File();
             $file->setFile($request->files->get('member')['photo']);
             $file->upload();
             $member->setPhoto($file);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($member);
         $em->flush();
         $this->get('meli.flasher')->flashSuccess('Le membre a été modifié.');
         return $this->redirectToRoute('admin-presentation');
     }
     return $this->render('admin/presentation/add.html.twig', array('form' => $form->createView(), 'submit' => 'Modifier'));
 }
コード例 #2
0
 /**
  * Transforms a collection os files on session on entities
  *
  * @throws TransformationFailedException if object (issue) is not found.
  */
 public function reverseTransform($id)
 {
     // Pasar los ficheros almacenados en la sesión a la carpeta web y devolver el array de ficheros
     $manager = $this->orphanageManager->get('gallery');
     $images = $manager->uploadFiles();
     if (count($images) == 0) {
         return null;
     } else {
         if (count($images) == 1) {
             $file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $images[0]->getFilename());
             if ($file == null) {
                 $file = new File();
                 $file->setPath('uploads/gallery/' . $images[0]->getFilename());
                 $this->om->persist($file);
                 $this->om->flush();
             }
             $data = $file;
         } else {
             $data = array();
             foreach ($images as $image) {
                 $file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $image->getFilename());
                 if ($file == null) {
                     $file = new File();
                     $file->setPath('uploads/gallery/' . $image->getFilename());
                     $this->om->persist($file);
                     $this->om->flush();
                 }
                 $data[] = $file;
             }
             $this->om->flush();
         }
     }
     return $data;
 }
コード例 #3
0
 public function load(File $file)
 {
     #ToDO prueba de concepto sacar a un servicio
     $manager = $this->orphanManager->get('gallery');
     $fs = new Filesystem();
     $fs->copy($file->getAbsolutePath(), $this->config['directory'] . '/' . $this->session->getId() . '/gallery/' . $file->getName());
 }
コード例 #4
0
ファイル: FileController.php プロジェクト: j3k-b3h/paperhill
 /**
  * @Route("/doc/new/{docid}", name="file_new")
  */
 public function newAction(Request $request, $docid)
 {
     $storage = $this->get('app.storage_helper');
     $repo = $this->getDoctrine()->getManager()->getRepository('AppBundle:Document');
     $document = $repo->find($docid);
     if (!$document) {
         throw $this->createNotFoundException('No document found for id ' . $docid);
     }
     $file = new File();
     $file->setTitle(sprintf('Seite %d', count($document->getFiles()) + 1));
     $file->setDocument($document);
     $file->setPath($document->getPath());
     $form = $this->createForm(FileType::class, $file);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $file->setCreated(new \Datetime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($file);
         $em->flush();
         $storage->createThumbnail($file);
         $storage->extractContent($file);
         $em->persist($file);
         $em->flush();
         return $this->redirectToRoute('doc', ['id' => $file->getDocument()->getId()]);
     }
     return $this->render('file/new.html.twig', ['file' => $file, 'form' => $form->createView(), 'document' => $document]);
 }
コード例 #5
0
 protected function createFile(UploadedFile $uploadedFile, ObjectManager $em, $type)
 {
     $file = $this->getDoctrine()->getRepository(File::class)->findOneBy(['type' => $type]);
     if ($file) {
         $file->unlink();
     } else {
         $file = new File();
     }
     $fileName = $uploadedFile->getClientOriginalName();
     $file->setPath("files/uploads/{$fileName}");
     $file->setType($type);
     $file->setCreatedAt(new \DateTime());
     $uploadedFile->move($this->get('kernel')->getRootDir() . '/../web/files/uploads', $fileName);
     $em->persist($file);
 }
コード例 #6
0
 public function load(ObjectManager $manager)
 {
     /*
             $connection = $manager->getConnection();
             $dbPlatform = $connection->getDatabasePlatform();
     #        $connection->query('SET FOREIGN_KEY_CHECKS=0');
             $q = $dbPlatform->getTruncateTableSql('documents');
             $connection->executeUpdate($q);
             $q = $dbPlatform->getTruncateTableSql('files');
             $connection->executeUpdate($q);
      #       $connection->query('SET FOREIGN_KEY_CHECKS=1');
     */
     for ($i = 0; $i <= 10; $i++) {
         $document = new Document();
         $document->setTitle('Der Titel Nr. ' . $i);
         $document->setDocDate(new \Datetime());
         $document->setPath('/home/jacek/dir');
         $document->setCreated(new \Datetime());
         $document->setTags('tag1 tag2 tag3');
         $r = mt_rand(1, 2);
         for ($j = 0; $j <= $r; $j++) {
             $file = new File();
             $file->setTitle('Titel der Datei Nr. ' . $j);
             $file->setFilename('Dateiname.ext');
             $file->setPath('/home/jacek/dir');
             $file->setFiletype('ext');
             $file->setContent('blablabla');
             $file->setCreated(new \Datetime());
             $file->setDocument($document);
             $manager->persist($file);
             print "File angelegt: {$file->getTitle()} \n";
         }
         $manager->persist($document);
         print "Doc angelegt: {$document->getTitle()} \n";
     }
     $manager->flush();
 }
コード例 #7
0
ファイル: FileTransformer.php プロジェクト: cvele/fondacija
 /**
  * Include User
  *
  * @param File $organization
  * @return \League\Fractal\Resource\Item
  */
 public function includeUser(File $file)
 {
     return $this->item($file->getUser(), new UserTransformer());
 }
コード例 #8
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 0; $i <= 200; $i++) {
         $estate = new Estate();
         $estate->setTitle($faker->sentence);
         $estate->setDescription($faker->sentence);
         $estate->setPrice($faker->numberBetween(10000, 500000));
         $estate->setCreatedBy('user_manager' . rand(0, 2));
         $estate->setDistrict($this->getReference('district' . rand(1, 10)));
         $exclusive = rand(1, 10);
         if ($exclusive == 10) {
             $estate->setExclusive(true);
         }
         for ($k = 1; $k <= 5; $k++) {
             $file = new File();
             $file->setEstate($estate);
             $estate->addFile($file);
             $file->setMimeType('image/jpeg');
             $file->setName(md5(uniqid('sdfadf')) . '.jpg');
             $file->setSize('100000');
             $file->setPath("images/estates/foto" . rand(1, 9) . ".jpg");
             $manager->persist($file);
         }
         for ($j = 1; $j <= 5; $j++) {
             $comment = new Comment();
             $comment->setEstate($estate);
             $estate->addComment($comment);
             $comment->setContent($faker->sentence);
             $enable = rand(1, 2);
             if ($enable === 1) {
                 $comment->setEnabled(false);
             } else {
                 $comment->setEnabled(true);
             }
             $comment->setCreatedBy('user_user1');
             $manager->persist($comment);
         }
         // flats - 40%
         // set category
         // for rent - 20%
         $quart = rand(0, 9);
         if ($quart <= 3) {
             $cat = rand(1, 5);
             $estate->setCategory($this->getReference('category' . $cat));
             $countFloors = rand(4, 16);
             $estate->setFloor(array('floor' => rand(1, $countFloors), 'count_floor' => $countFloors));
             $floor = $estate->getFloor();
             if ($floor['floor'] == 1 || $floor['floor'] == $floor['count_floor']) {
                 $estate->setFirstLastFloor(true);
             } else {
                 $estate->setFirstLastFloor(false);
             }
         } elseif ($quart == 4 || $quart == 5) {
             $cat = rand(13, 14);
             $estate->setCategory($this->getReference('category' . $cat));
         } else {
             $cat = rand(6, 12);
             $estate->setCategory($this->getReference('category' . $cat));
         }
         $manager->persist($estate);
     }
     $manager->flush();
 }
コード例 #9
0
 /**
  * @Route("/myRepoFunctions/filesSubmit/{parent_dir}", name="filesSubmit", defaults={"parent_dir" = null})
  */
 public function filesSubmitAction($parent_dir, Request $request)
 {
     $files = new Files();
     $filesForm = $this->createForm(FilesType::class, $files, ['action' => $parent_dir]);
     $filesForm->add('submit', SubmitType::class, array('label' => 'Upload Files', 'attr' => array('class' => 'btn btn-default pull-right')));
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     $current_dir = $parent_dir ? $em->getRepository('AppBundle:Directory')->findOneBy(['encodedName' => $parent_dir]) : null;
     $filesForm->handleRequest($request);
     if ($filesForm->isValid()) {
         $filesArray = $files->getFiles();
         foreach ($filesArray as $item) {
             $file = new File();
             $file->setDirectory($current_dir);
             $file->setName($item->getClientOriginalName());
             $em->persist($file);
             $file->uploadFile($item, $user, $current_dir);
         }
         $em->flush();
         return $this->redirectToRoute('dir_show', ['dir_name' => $parent_dir]);
     }
     return false;
 }
コード例 #10
0
ファイル: StorageService.php プロジェクト: ravenhaus/cloud
 public function getDownloadUrl(File $file)
 {
     $cmd = $this->s3Client->getCommand('GetObject', ['Bucket' => $this->bucket, 'Key' => $file->getUri()]);
     $request = $this->s3Client->createPresignedRequest($cmd, '+12 hours');
     return (string) $request->getUri();
 }
コード例 #11
0
ファイル: FileManager.php プロジェクト: cvele/fondacija
 public function delete(File $entity, $eventName = 'app.entity.deleted')
 {
     $filePath = $entity->getPath() . DIRECTORY_SEPARATOR . $entity->getName();
     $this->simpleDelete($entity, $eventName);
     unlink($filePath);
 }
コード例 #12
0
ファイル: StorageHelper.php プロジェクト: j3k-b3h/paperhill
 /**
  * Erzeugt Thumbnail einer Datei
  * Bisher implementiert:
  * - PNG
  * - JPG
  * - GIF
  * - PDF
  * - OpenOffice Doc odt
  * @param  \AppBundle\Entity\File $file [description]
  * @return [type]                       [description]
  */
 public function createThumbnail(\AppBundle\Entity\File $file)
 {
     #print __METHOD__;
     #print $file->getMimeType();
     #die;
     switch ($file->getMimeType()) {
         case 'application/pdf':
             // sudo apt-get install imagemagick ghostscript
             $filename = sha1(uniqid(mt_rand(), true)) . '.png';
             $cmd = sprintf('convert -thumbnail 200x -background white -alpha remove "%s[0]" "%s"', $this->storage . $file->getPath() . '/' . $file->getFilename(), $this->thumbnailsPath . $filename);
             exec($cmd, $output, $return_var);
             if ($return_var != 0) {
                 print "FEHLER BEIM ERZEUGEN DES THUMBNAILS " . __METHOD__;
             } else {
                 $file->setThumbnail($filename);
             }
             break;
         case 'application/vnd.oasis.opendocument.text':
             // https://wiki.ubuntuusers.de/OpenDocument_Thumbnails/
             $filename = sha1(uniqid(mt_rand(), true)) . '.png';
             $cmd = sprintf('/usr/bin/gsf-office-thumbnailer -i "%s" -o "%s" -s 800', $this->storage . $file->getPath() . '/' . $file->getFilename(), $this->thumbnailsPath . $filename);
             exec($cmd, $output, $return_var);
             if ($return_var != 0) {
                 print "FEHLER BEIM ERZEUGEN DES THUMBNAILS " . __METHOD__;
             } else {
                 $source_image = imagecreatefrompng($this->thumbnailsPath . $filename);
                 $this->_makeThumbnail($file, $source_image, 200);
                 unlink($this->thumbnailsPath . $filename);
             }
             break;
         case 'image/png':
             $src = $this->storage . $file->getPath() . '/' . $file->getFilename();
             $source_image = imagecreatefrompng($src);
             $this->_makeThumbnail($file, $source_image, 200);
             break;
         case 'image/jpeg':
             $src = $this->storage . $file->getPath() . '/' . $file->getFilename();
             $source_image = imagecreatefromjpeg($src);
             $this->_makeThumbnail($file, $source_image, 200);
             break;
         case 'image/gif':
             $src = $this->storage . $file->getPath() . '/' . $file->getFilename();
             $source_image = imagecreatefromgif($src);
             $this->_makeThumbnail($file, $source_image, 200);
             break;
     }
 }