Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $io->title('Ajouter un fichier');
     $em = $this->getcontainer()->get('doctrine.orm.default_entity_manager');
     $SCrepo = $em->getRepository('evegAppBundle:SyntaxonCore');
     $UserRepo = $em->getRepository('evegUserBundle:User');
     $s = $SCrepo->findById($input->getArgument('SCid'));
     $SCdiag = $SCrepo->findById($input->getArgument('diagnosisOf'));
     $user = $UserRepo->findByUsername($input->getArgument('userName'))[0];
     $io->writeln('Updating (id: ' . $input->getArgument('SCid') . ') ' . $s->getSyntaxon());
     $io->writeln('    adding file ' . $input->getArgument('fileName'));
     $sFile = new SyntaxonFile();
     $sFile->setHit($input->getArgument('hit'))->setDiagnosisOf($SCdiag);
     $sFile->setSyntaxonCore($s);
     $sFile->setUser($user)->setType($input->getArgument('type'))->setVisibility($input->getArgument('visibility'))->setTitle($input->getArgument('title'))->setFileName($input->getArgument('fileName'))->setOriginalName($input->getArgument('originalName'))->setOriginalSyntaxonName($input->getArgument('originalSyntaxonName'))->setLicense('CC-BY-SA')->setUpdatedAt(new \DateTime('now'))->setUploadedAt(new \DateTime('now'));
     $s->addSyntaxonFile($sFile);
     $em->flush();
     $io->success('file added');
 }
Esempio n. 2
0
 /**
  * @ParamConverter("syntaxon", class="evegAppBundle:syntaxonCore")
  * 
  */
 public function addFileLinkAction(SyntaxonCore $syntaxon, $id, Request $request)
 {
     $request = $this->getRequest();
     // Get all files
     $em = $this->getDoctrine()->getManager();
     $filesRepo = $em->getRepository('evegAppBundle:SyntaxonFile');
     $files = $filesRepo->findAll();
     // Creates the form...
     $form = $this->createForm(new SyntaxonCoreFileLinkType());
     // ... and then hydrates it
     $form->handleRequest($request);
     // Get the file id to retrieve
     $fileIdToRetrieve = (int) $request->request->get('syntaxonCoreFileLink')['syntaxonFiles'][0]['fileLink'];
     $newTitle = (string) $request->request->get('syntaxonCoreFileLink')['syntaxonFiles'][0]['title'];
     $newVisibility = (string) $request->request->get('syntaxonCoreFileLink')['syntaxonFiles'][0]['visibility'];
     $newDiagnosisOf = $request->request->get('syntaxonCoreFileLink')['syntaxonFiles'][0]['diagnosisOf'];
     //dump($newDiagnosisOf);
     // Job routine
     if ($form->isValid()) {
         $data = $form->getData();
         $files = $data->getSyntaxonFiles();
         $nbFiles = count($files);
         $currentUser = $this->getUser();
         // get the file
         $fileToLink = $filesRepo->findById($fileIdToRetrieve)[0];
         // new file object
         $file = new SyntaxonFile($fileToLink);
         // link both files
         //$file = $fileToLink;
         $file->setLinked(true);
         $file->setSyntaxonCore($syntaxon);
         $file->setUser($currentUser);
         $file->setTitle($newTitle);
         $file->setType($fileToLink->getType());
         $file->setFileName($fileToLink->getFileName());
         $file->setOriginalName($fileToLink->getOriginalName());
         $file->setVisibility($newVisibility);
         $file->setDiagnosisOf($form->getData()->getSyntaxonFiles()[0]->getDiagnosisOf());
         $file->setLicense($fileToLink->getLicense());
         $file->setUploadedAt(new \DateTime('now'));
         $file->setUpdatedAt(new \DateTime('now'));
         $file->setOriginalSyntaxonName('(id:' . $syntaxon->getId() . ') ' . $syntaxon->getSyntaxon());
         $syntaxon->addSyntaxonFile($file);
         $em->persist($syntaxon);
         $em->flush();
         if ($nbFiles == 1) {
             $request->getSession()->getFlashBag()->add('success', 'Un nouveau fichier lié.');
         } elseif ($nbFiles > 1) {
             $request->getSession()->getFlashBag()->add('success', $nbFiles . ' nouveaux fichiers liés.');
         } else {
             $request->getSession()->getFlashBag()->add('warning', 'Aucun nouveau fichier lié.');
         }
         // If SaveAndAdd
         if ($form->get('saveAndAdd')->isClicked()) {
             return $this->redirect($this->generateUrl('eveg_add_file_link', array('id' => $id)));
         } else {
             return $this->redirect($this->generateUrl('eveg_show_one', array('id' => $id)));
         }
     }
     return $this->render('evegAppBundle:Default:addFileLink.html.twig', array('syntaxon' => $syntaxon, 'files' => $files, 'form' => $form->createView()));
 }