src/Controller/Frontend/ShareController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use App\Entity\Media\ShareCart;
  6. use App\Form\Media\ShareCartType;
  7. use App\Entity\Media\Document;
  8. use App\Form\Media\DownloadMultipleType;
  9. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  10. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  11. use App\Entity\History\History;
  12. use App\Entity\Media\Share;
  13. use App\Entity\Media\Quality;
  14. use App\Service\Site\SiteManager;
  15. use App\Service\Media\DownloadManager;
  16. class ShareController extends AbstractController
  17. {
  18.     public function listAction(Request $requestSiteManager $site)
  19.     {
  20.         $user $this->get('security.token_storage')->getToken()->getUser();
  21.         
  22.         $accessSite $site->userAccessSite($user);
  23.         $shares $this->getDoctrine()->getManager()->getRepository(ShareCart::class)->findByAccessSite($accessSite);
  24.         
  25.         return $this->render('Frontend/Views/Share/list.html.twig', array(
  26.             'shares' => $shares
  27.         ));
  28.     }
  29.     
  30.     public function editAction(Request $requestShareCart $shareCart)
  31.     {
  32.         $form $this->createForm(ShareCartType::class, $shareCart, ['qualities' => $shareCart->getAccessSite()->getQualities()]);
  33.         $form->handleRequest($request);
  34.         
  35.         if ($form->isSubmitted() && $form->isValid())
  36.         {
  37.             $em $this->getDoctrine()->getManager();
  38.             $em->persist($shareCart);
  39.             $em->flush();
  40.             
  41.             return $this->redirectToRoute('frontend_share_list');
  42.         }
  43.         
  44.         return $this->render('Frontend/Views/Share/edit.html.twig', array(
  45.             'form' => $form->createView(),
  46.             'deleteForm' => $this->createDeleteForm($shareCart)->createView(),
  47.             'shareCart' => $shareCart
  48.         ));
  49.     }
  50.     
  51.     public function viewAction(Request $request$token nullDownloadManager $downloadManager)
  52.     {
  53.         $documents = array();
  54.         $form $this->createForm(DownloadMultipleType::class, null, array());
  55.         $em $this->getDoctrine()->getManager();
  56.                 
  57.         $share $this->getDoctrine()->getManager()->getRepository(ShareCart::class)->findOneByToken($token);
  58.         
  59.         $form->handleRequest($request);
  60.         
  61.         if ($form->isSubmitted() && $form->isValid()) {
  62.             $documentsIds $form['documents']->getData();
  63.             
  64.             foreach($documentsIds as $downloadId)
  65.                 array_push($documents$em->getRepository(Document::class)->find($downloadId));
  66.             
  67.             if(!empty($documents))
  68.             {
  69.                 $response $downloadManager->downloadPictures($documents$share->getQuality());
  70.             
  71.                 return $response;
  72.             }
  73.         }
  74.         
  75.         return $this->render('Frontend/Views/Share/view.html.twig', array(
  76.             'share' => $share,
  77.             'form' => $form->createView()
  78.         ));
  79.     }
  80.     
  81.     public function deleteAction(Request $requestShareCart $shareCart)
  82.     {
  83.         $em $this->getDoctrine()->getManager();
  84.         
  85.         $form $this->createDeleteForm($shareCart);
  86.         $form->handleRequest($request);
  87.         
  88.         if($request->isMethod('DELETE'))
  89.         {
  90.             if ($form->isValid())
  91.             {
  92.                 $em->remove($shareCart);
  93.                 $em->flush();
  94.                 
  95.                 return $this->redirectToRoute('frontend_share_list');
  96.             }
  97.         }
  98.     }    
  99.     
  100.     private function createDeleteForm(ShareCart $shareCart)
  101.     {
  102.         return $this->createFormBuilder()
  103.         ->setAction($this->generateUrl('frontend_share_delete', array('id' => $shareCart->getId())))
  104.         ->setMethod('DELETE')
  105.         ->getForm();
  106.     }
  107.     
  108.     public function documentViewAction(Request $requestDocument $document)
  109.     {
  110.         $proofValidation false;
  111.                
  112.         if(sizeof($document->getSkippers()) > || sizeof($document->getBoats()) > 0){
  113.             $referents $this->getDoctrine()->getManager()->getRepository(\App\Entity\Federation\Participation::class)->getReferents($document->getRace(), $document->getBoats(), $document->getSkippers());
  114.             
  115.             if(!empty($referents))
  116.             {
  117.                 foreach ($referents as $key => $referent)
  118.                     if(!empty($referent['id']))
  119.                         $referents[$key] = $this->getDoctrine()->getManager()->getRepository(\App\Entity\User\User::class)->find($referent['id']);
  120.             }
  121.         }
  122.                 
  123.         return $this->render('Frontend/Views/Document/view-'.$document->getDocumentType()->getDirectoryName().'.html.twig', array(
  124.             'document' => $document,
  125.             'proofValidation' => $proofValidation
  126.         ));
  127.     }
  128.     
  129.     public function downloadAction(ShareCart $shareCartQuality $qualityDownloadManager $downloadManager)
  130.     {
  131.         $response $downloadManager->downloadPictures($shareCart->getDocuments(), $quality);
  132.         
  133.         return $response;
  134.     }
  135.     
  136.     public function shareToFlickerAction(ShareCart $shareCartDocument $parentDocument)
  137.     {
  138.         $flickerPhotoId $document null;
  139.         $fm $this->get('flickr.sdkmanager');
  140.         
  141.         foreach($parentDocument->getDocumentsChild() as $child)
  142.             if($child->getQuality()->getCode() == 'BD')
  143.                 $document $child;
  144.             
  145.         if(!empty($document))
  146.         {
  147.             $copyright '';
  148.             if(!empty($document->getCopyright()))
  149.                 $copyright "©".str_replace("©"""$document->getCopyright())."<br>";
  150.                 
  151.             $description $copyright."\n".$document->getLegend()."\n".$document->getDescription();
  152.             
  153.             //1 - Upload Photo
  154.             $path $this->get('media.fileManager')->getRootFileManager().$document->getRace()->getDirectoryName()."/".$document->getFile()['Key'];
  155.             $result $fm->upload($path$document->getTitle(), $description);
  156.             if(isset($result['photoid']))
  157.                 $flickerPhotoId $result['photoid'];
  158.                 
  159.             if($flickerPhotoId 0)
  160.             {
  161.                 if(empty($shareCart->getFlickerShare()))
  162.                 {
  163.                     //1 - Upload first image and Create Album
  164.                     $album $fm->createAlbum($shareCart->getName(), $shareCart->getComment(), [ $flickerPhotoId ]);
  165.                     $shareCart->setFlickerAlbum($album);
  166.                     $shareCart->setFlickerShare(1);
  167.                     
  168.                     $this->getDoctrine()->getManager()->flush();
  169.                     
  170.                 } else {
  171.                     //2 - Upload photo and assign album
  172.                     $album $shareCart->getFlickerAlbum();
  173.                     $fm->addPhotoToAlbum($album['id'], $flickerPhotoId);
  174.                 }
  175.             }
  176.         }
  177.         
  178.         return $this->json(['size' => $document->getFile()['Size']]);
  179.     }
  180. }