src/Controller/PlaylistController.php line 380

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Playlist;
  4. use App\Repository\ConceptRepository;
  5. use App\Repository\GroupeRepository;
  6. use App\Repository\GroupItemRepository;
  7. use App\Repository\PlaylistRepository;
  8. use App\Repository\VideoRepository;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Yectep\PhpSpreadsheetBundle\Factory;
  15. class PlaylistController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/api/get-last-video-time", name="playlist_get_last_video_time")
  19.      */
  20.     public function playlist_get_last_video_time(PlaylistRepository $playlistRepository): Response
  21.     {
  22.         $video $playlistRepository->getLastPlay();
  23.         if($video) {
  24.             if(time() < (int)($video->getStartPlay() + $video->getDuration()))
  25.                 return new Response((int)($video->getStartPlay() + $video->getDuration()));
  26.         }
  27.         return new Response(time() + 60*5);
  28.     }
  29.     /**
  30.      * @Route("/api/test-video-time", name="playlist_test_video_time")
  31.      */
  32.     public function playlist_test_video_time(PlaylistRepository $playlistRepositoryRequest $request): Response
  33.     {
  34.         $time $request->get('time'null);
  35.         $duration $request->get('duration'null);
  36.         $videosOverlay = [];
  37.         if($time && $duration) {
  38.             $videos $playlistRepository->getVideoOverlay($time$time $duration);
  39.             if ($videos) {
  40.                 foreach ($videos as $video) {
  41.                     $videosOverlay[] = [
  42.                         'id' => $video->getId(),
  43.                         'name' => $video->getName(),
  44.                         'startPlay' => $video->getStartPlay(),
  45.                         'duration' => $video->getDuration(),
  46.                         'start' => $video->getStart(),
  47.                         'end' => $video->getEnd(),
  48.                     ];
  49.                 }
  50.             }
  51.         }
  52.         return new JsonResponse($videosOverlay);
  53.     }
  54.     /**
  55.      * @Route("/api/get-current-playlist", name="playlist_get_current")
  56.      */
  57.     public function playlist_get_current(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  58.     {
  59.         $day $request->get('day'date('d.m.Y'));
  60.         $videos $playlistRepository->getVideoByDay($day);
  61.         $response = [];
  62.         $concepts_ $conceptRepository->findAll();
  63.         $reportConcept = [];
  64.         foreach ($concepts_ as $concept) {
  65.             $reportConcept[$concept->getId()] = [
  66.                 'name' => $concept->getName(),
  67.                 'coor' => 0,
  68.                 'need' => $concept->getNeead(),
  69.             ];
  70.         }
  71.         $reportLang = [];
  72.         foreach ($videos as $video) {
  73.             $response[] = [
  74.                 'id' => $video->getId(),
  75.                 'file' => $video->getFile(),
  76.                 'concept' => $video->getConcept(),
  77.                 'startPlay' => $video->getStartPlay(),
  78.                 'duration' => $video->getDuration(),
  79.                 'name' => $video->getName(),
  80.                 'theme' => $video->getTheme(),
  81.                 'autor' => $video->getAutor(),
  82.                 'lang' => $video->getLang(),
  83.                 'production' => $video->getProduction(),
  84.                 'licension' => $video->getLicension(),
  85.                 'prev' => $video->getPrev(),
  86.             ];
  87.             if(isset($reportConcept[$video->getConcept()])) {
  88.                 $reportConcept[$video->getConcept()]['coor'] += $video->getDuration();
  89.             }
  90.             if(isset($reportLang[$video->getLang()])) {
  91.                 $reportLang[$video->getLang()]['coor'] += $video->getDuration();
  92.             } else {
  93.                 $reportLang[$video->getLang()] = [
  94.                     'name' => $video->getLang(),
  95.                     'coor' => $video->getDuration(),
  96.                 ];
  97.             }
  98.         }
  99.         $clearReportConcept = [];
  100.         foreach ($reportConcept as $item) {
  101.             $clearReportConcept[] = $item;
  102.         }
  103.         return new JsonResponse([
  104.             'videos' => $response,
  105.             'reportConcept' => $clearReportConcept,
  106.             'reportLang' => $reportLang,
  107.         ]);
  108.     }
  109.     /**
  110.      * @Route("/api/get-current-playlist-exel", name="playlist_get_current_exel")
  111.      */
  112.     public function playlist_get_current_exel(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  113.     {
  114.         $day $request->get('day'date('d.m.Y'));
  115.         $videos $playlistRepository->getVideoByDay($day);
  116.         $response = [];
  117.         $concepts_ $conceptRepository->findAll();
  118.         $reportConcept = [];
  119.         foreach ($concepts_ as $concept) {
  120.             $reportConcept[$concept->getId()] = [
  121.                 'name' => $concept->getName(),
  122.                 'coor' => 0,
  123.                 'need' => $concept->getNeead(),
  124.             ];
  125.         }
  126.         $reportLang = [];
  127.         foreach ($videos as $video) {
  128.             $response[] = [
  129.                 'id' => $video->getId(),
  130.                 'file' => $video->getFile(),
  131.                 'concept' => $video->getConcept(),
  132.                 'startPlay' => $video->getStartPlay(),
  133.                 'duration' => $video->getDuration(),
  134.                 'name' => $video->getName(),
  135.                 'theme' => $video->getTheme(),
  136.                 'autor' => $video->getAutor(),
  137.                 'lang' => $video->getLang(),
  138.                 'production' => $video->getProduction(),
  139.                 'licension' => $video->getLicension(),
  140.             ];
  141.             if(isset($reportConcept[$video->getConcept()])) {
  142.                 $reportConcept[$video->getConcept()]['coor'] += $video->getDuration();
  143.             }
  144.             if(isset($reportLang[$video->getLang()])) {
  145.                 $reportLang[$video->getLang()]['coor'] += $video->getDuration();
  146.             } else {
  147.                 $reportLang[$video->getLang()] = [
  148.                     'name' => $video->getLang(),
  149.                     'coor' => $video->getDuration(),
  150.                 ];
  151.             }
  152.         }
  153.         $clearReportConcept = [];
  154.         foreach ($reportConcept as $item) {
  155.             $clearReportConcept[] = $item;
  156.         }
  157.         $factory = new Factory();
  158.         $spreadsheet $factory->createSpreadsheet();
  159.         $spreadsheet->getProperties()->setCreator('Playout')
  160.             ->setLastModifiedBy('Playout')
  161.             ->setTitle('Video: '.$day)
  162.             ->setSubject('Video: '.$day)
  163.             ->setDescription('Export of scan results with orders.');
  164.         $sheet $spreadsheet->getActiveSheet();
  165.         $sheet->setTitle('Export');
  166.         $sheet->setCellValue('A1''Початок');
  167.         $sheet->setCellValue('B1''Завершення');
  168.         $sheet->setCellValue('C1''Назва');
  169.         $sheet->setCellValue('D1''Тема');
  170.         $sheet->setCellValue('E1''Автор/ведучий');
  171.         $sheet->setCellValue('F1''Мова');
  172.         $sheet->setCellValue('G1''Хронометраж');
  173.         $sheet->setCellValue('H1''Виробництво');
  174.         $sheet->setCellValue('I1''Лізензіар');
  175.         $sheet->setCellValue('J1''Жанр');
  176.         $row 2;
  177.         foreach ($response as $respons) {
  178.             $sheet->setCellValue('A' $rowdate('H:i:s'$respons['startPlay']));
  179.             $sheet->setCellValue('B' $rowdate('H:i:s'$respons['startPlay'] + $respons['duration']));
  180.             $sheet->setCellValue('C' $row$respons['name']);
  181.             $sheet->setCellValue('D' $row$respons['theme']);
  182.             $sheet->setCellValue('E' $row$respons['autor']);
  183.             $sheet->setCellValue('F' $row$respons['lang']);
  184.             $sheet->setCellValue('G' $rowgmdate("H:i:s"$respons['duration']));
  185.             $sheet->setCellValue('H' $row$respons['production']);
  186.             $sheet->setCellValue('I' $row$respons['licension']);
  187.             $concept $conceptRepository->find($respons['concept']);
  188.             $sheet->setCellValue('J' $row$concept->getName());
  189.             $row++;
  190.         }
  191.         $row++;
  192.         foreach ($reportConcept as $item) {
  193.             if($item['coor']) {
  194.                 $sheet->setCellValue('A' $row$item['name']);
  195.                 $sheet->setCellValue('B' $rowgmdate("H:i:s"$item['coor']));
  196.                 $row++;
  197.             }
  198.         }
  199.         $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet"Xlsx");
  200.         $writer->save("/home/admin/web/apipl.mhu.news/public_html/public/report_".time().".xlsx");
  201.         return $this->redirect('https://apipl.mhu.news/report_'.time().'.xlsx');
  202.     }
  203.     /**
  204.      * @Route("/api/set-current-playlist-up", name="playlist_set_current_up")
  205.      */
  206.     public function playlist_set_current_up(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  207.     {
  208.         $em $this->getDoctrine()->getManager();
  209.         $day $request->get('day'date('d.m.Y'));
  210.         $videoId $request->get('id');
  211.         $videos $playlistRepository->getVideoByDay($day);
  212.         $startPlay 0;
  213.         foreach ($videos as $key => $video) {
  214.             if($video->getId() == $videoId && isset($videos[$key 1])) {
  215.                 $video->setStartPlay($videos[$key 1]->getStartPlay());
  216.                 $startPlay $videos[$key 1]->getStartPlay() + $video->getDuration();
  217.                 $em->persist($video);
  218.                 $em->flush();
  219.                 $videos[$key 1]->setStartPlay($startPlay);
  220.                 $startPlay $startPlay $videos[$key 1]->getDuration();
  221.                 $em->persist($videos[$key 1]);
  222.                 $em->flush();
  223.             } elseif($startPlay) {
  224.                 $video->setStartPlay($startPlay);
  225.                 $startPlay $startPlay $videos[$key]->getDuration();
  226.                 $em->persist($videos[$key]);
  227.                 $em->flush();
  228.             }
  229.         }
  230.         return new JsonResponse([]);
  231.     }
  232.     /**
  233.      * @Route("/api/set-current-playlist-down", name="playlist_set_current_down")
  234.      */
  235.     public function playlist_set_current_down(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  236.     {
  237.         $em $this->getDoctrine()->getManager();
  238.         $day $request->get('day'date('d.m.Y'));
  239.         $videoId $request->get('id');
  240.         $videos $playlistRepository->getVideoByDay($day);
  241.         $startPlay 0;
  242.         $nex null;
  243.         foreach ($videos as $key => $video) {
  244.             if($video->getId() == $videoId && isset($videos[$key 1])) {
  245.                 $videos[$key 1]->setStartPlay($video->getStartPlay());
  246.                 $startPlay $video->getStartPlay() + $videos[$key 1]->getDuration();
  247.                 $em->persist($videos[$key 1]);
  248.                 $em->flush();
  249.                 $video->setStartPlay($startPlay);
  250.                 $startPlay $startPlay $video->getDuration();
  251.                 $em->persist($video);
  252.                 $em->flush();
  253.                 $nex $videos[$key 1]->getId();
  254.             } elseif($startPlay && $nex != $video->getId()) {
  255.                 $video->setStartPlay($startPlay);
  256.                 $startPlay $startPlay $videos[$key]->getDuration();
  257.                 $em->persist($videos[$key]);
  258.                 $em->flush();
  259.             }
  260.         }
  261.         return new JsonResponse([]);
  262.     }
  263.     /**
  264.      * @Route("/api/set-current-temp", name="playlist_set_current_temp")
  265.      */
  266.     public function playlist_set_current_temp(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  267.     {
  268.         $em $this->getDoctrine()->getManager();
  269.         $lastVideo $playlistRepository->find(1661);
  270.         $startPlay $lastVideo->getStartPlay() + $lastVideo->getDuration();
  271.         $timestart strtotime("2024-07-29 00:00:00");
  272.         $timeend strtotime("2024-07-30 00:00:01");
  273.         $videos $playlistRepository->getVideoDayPlay($timestart$timeend);
  274.         /*if(!$videos) {
  275.             $videos = $this->checkVideoDay(1);
  276.         }*/
  277.         $i 1;
  278.         //for($i = 1; $i <=23; $i++) {
  279.            // if($i < 10) $i = '0'.$i;
  280.         $startPlay strtotime("2024-09-24 15:45:03");
  281.             foreach ($videos as $video) {
  282.                 echo 'add new: '.$video->getName()." Time: ".date("H:i:s"$startPlay)."\n";
  283.                 $newVideo = new Playlist();
  284.                 $newVideo->setName($video->getName());
  285.                 $newVideo->setFile($video->getFile());
  286.                 $newVideo->setDuration($video->getDuration());
  287.                 $newVideo->setAutor($video->getAutor());
  288.                 $newVideo->setConcept($video->getConcept());
  289.                 $newVideo->setEnd($video->getEnd());
  290.                 $newVideo->setLang($video->getLang());
  291.                 $newVideo->setLicension($video->getLicension());
  292.                 $newVideo->setProduction($video->getProduction());
  293.                 $newVideo->setTheme($video->getTheme());
  294.                 $newVideo->setStart($video->getStart());
  295.                 $newVideo->setPrev($video->getPrev());
  296.                 $newVideo->setStartPlay($startPlay);
  297.                 $em->persist($newVideo);
  298.                 $em->flush();
  299.                 $startPlay += $newVideo->getDuration();
  300.             }
  301. //}
  302.         /*$videos = $playlistRepository->getVideoDayPlayTemp();
  303.         foreach ($videos as $video) {
  304.             $newVideo = new Playlist();
  305.             $newVideo->setName($video->getName());
  306.             $newVideo->setFile($video->getFile());
  307.             $newVideo->setDuration($video->getDuration());
  308.             $newVideo->setAutor($video->getAutor());
  309.             $newVideo->setConcept($video->getConcept());
  310.             $newVideo->setEnd($video->getEnd());
  311.             $newVideo->setLang($video->getLang());
  312.             $newVideo->setLicension($video->getLicension());
  313.             $newVideo->setProduction($video->getProduction());
  314.             $newVideo->setTheme($video->getTheme());
  315.             $newVideo->setStart($video->getStart());
  316.             $newVideo->setStartPlay($startPlay);
  317.             echo $newVideo->getName().' : '.date('d..m.Y H:i:s', $newVideo->getStartPlay()).' : '.date('d..m.Y H:i:s', $newVideo->getStartPlay()+ $newVideo->getDuration())."\n";
  318.             $startPlay += $newVideo->getDuration();
  319.             $em->persist($newVideo);
  320.             $em->flush();
  321.         }*/
  322.         return new JsonResponse([]);
  323.     }
  324.     /**
  325.      * @Route("/api/set-current-playlist-remove", name="playlist_set_current_remove")
  326.      */
  327.     public function playlist_set_current_remove(PlaylistRepository $playlistRepositoryRequest $requestConceptRepository $conceptRepository): Response
  328.     {
  329.         $em $this->getDoctrine()->getManager();
  330.         $day $request->get('day'date('d.m.Y'));
  331.         $videoId $request->get('id');
  332.         $videos $playlistRepository->getVideoByDay($day);
  333.         $startPlay 0;
  334.         $nex null;
  335.         foreach ($videos as $key => $video) {
  336.             if($video->getId() == $videoId) {
  337.                 if(isset($videos[$key 1])) {
  338.                     $videos[$key 1]->setStartPlay($video->getStartPlay());
  339.                     $startPlay $video->getStartPlay() + $videos[$key 1]->getDuration();
  340.                     $em->persist($videos[$key 1]);
  341.                     $em->flush();
  342.                     $nex $videos[$key 1]->getId();
  343.                 }
  344.                 $em->remove($video);
  345.                 $em->flush();
  346.             } elseif($startPlay && $nex != $video->getId()) {
  347.                 $video->setStartPlay($startPlay);
  348.                 $startPlay $startPlay $videos[$key]->getDuration();
  349.                 $em->persist($videos[$key]);
  350.                 $em->flush();
  351.             }
  352.         }
  353.         return new JsonResponse([]);
  354.     }
  355.     /**
  356.      * @Route("/api/replace-video", name="replace_video")
  357.      */
  358.     public function replace_video(Request $requestPlaylistRepository $playlistRepositoryVideoRepository $videoRepository): Response
  359.     {
  360.         $data json_decode($request->getContent());
  361.         $base $playlistRepository->find($data->base);
  362.         $replace $videoRepository->find($data->replace);
  363.         $duration $data->duration;
  364.         $video $data->video;
  365.         if($data->replace == '1-1') {
  366.             $base->setName($video->name);
  367.             $base->setFile('_efir:1');
  368.             $base->setDuration($duration);
  369.             $base->setAutor($video->autor);
  370.             $base->setConcept($video->concept);
  371.             $base->setEnd($duration);
  372.             $base->setLang($video->lang);
  373.             $base->setLicension($video->licension);
  374.             $base->setProduction($video->production);
  375.             $base->setTheme($video->theme);
  376.             $base->setStart(0);
  377.             $base->setStartPlay($base->getStartPlay());
  378.             $base->setPrev('');
  379.         } else {
  380.             $base->setName($replace->getName());
  381.             $base->setFile($replace->getFile());
  382.             $base->setDuration($replace->getDuration());
  383.             $base->setAutor($replace->getAutor());
  384.             $base->setConcept($replace->getConcept());
  385.             $base->setEnd($base->getEnd());
  386.             $base->setLang($replace->getLang());
  387.             $base->setLicension($replace->getLicension());
  388.             $base->setProduction($replace->getProduction());
  389.             $base->setTheme($replace->getTheme());
  390.             $base->setStart($base->getStart());
  391.             $base->setStartPlay($base->getStartPlay());
  392.             $base->setPrev($base->getPrev());
  393.         }
  394.         $em $this->getDoctrine()->getManager();
  395.         $em->persist($base);
  396.         $em->flush();
  397.         return new JsonResponse([]);
  398.     }
  399.     /**
  400.      * @Route("/api/replace-video-group", name="replace_video_group")
  401.      */
  402.     public function replace_video_group(Request $requestGroupItemRepository $groupItemRepositoryVideoRepository $videoRepository): Response
  403.     {
  404.         $data json_decode($request->getContent());
  405.         $base $groupItemRepository->find($data->base);
  406.         $replace $videoRepository->find($data->replace);
  407.         $base->setName($replace->getName());
  408.         $base->setFile($replace->getFile());
  409.         $base->setDuration($replace->getDuration());
  410.         $base->setAutor($replace->getAutor());
  411.         $base->setConcept($replace->getConcept());
  412.         $base->setLang($replace->getLang());
  413.         $base->setLicension($replace->getLicension());
  414.         $base->setProduction($replace->getProduction());
  415.         $base->setTheme($replace->getTheme());
  416.         $em $this->getDoctrine()->getManager();
  417.         $em->persist($base);
  418.         $em->flush();
  419.         return new JsonResponse([]);
  420.     }
  421.     /**
  422.      * @Route("/api/recalc-group", name="recalc_video_group")
  423.      */
  424.     public function recalc_video_group(Request $requestGroupItemRepository $groupItemRepositoryGroupeRepository $groupeRepository): Response
  425.     {
  426.         $data json_decode($request->getContent());
  427.         $groupe $groupeRepository->find($data->group);
  428.         $duration 0;
  429.         $items $groupItemRepository->findBy(['groupe' => $data->group]);
  430.         foreach ($items as $item) {
  431.             $duration += $item->getDuration();
  432.         }
  433.         $groupe->setDuration($duration);
  434.         $em $this->getDoctrine()->getManager();
  435.         $em->persist($groupe);
  436.         $em->flush();
  437.         return new JsonResponse([]);
  438.     }
  439. }