コード例 #1
0
ファイル: AdminFileController.php プロジェクト: ojs/ojs
 /**
  * Creates a new AdminFileentity.
  *
  * @param  Request                                                                                       $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function createAction(Request $request)
 {
     $entity = new AdminFile();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $rootDir = $this->getParameter('kernel.root_dir');
         $path = $rootDir . '/../web/uploads/files/' . $entity->getPath();
         $entity->setSize(StringHelper::formatBytes(filesize($path)));
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         $this->successFlashBag('successful.create');
         return $this->redirectToRoute('ojs_admin_file_show', ['id' => $entity->getId()]);
     }
     return $this->render('OjsAdminBundle:AdminFile:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }
コード例 #2
0
 /**
  * Creates a new JournalFile entity.
  *
  * @param  Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function createAction(Request $request)
 {
     $journal = $this->get('ojs.journal_service')->getSelectedJournal();
     if (!$this->isGranted('CREATE', $journal, 'files')) {
         throw new AccessDeniedException("You are not authorized for this file!");
     }
     $entity = new JournalFile();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $rootDir = $this->getParameter('kernel.root_dir');
         $path = $rootDir . '/../web/uploads/files/' . $entity->getPath();
         $entity->setSize(StringHelper::formatBytes(filesize($path)));
         $entity->setJournal($journal);
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         $this->successFlashBag('successful.create');
         return $this->redirectToRoute('ojs_journal_filemanager_show', ['id' => $entity->getId(), 'journalId' => $journal->getId()]);
     }
     return $this->render('OjsJournalBundle:JournalFile:new.html.twig', ['entity' => $entity, 'form' => $form->createView()]);
 }