Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller\Pages;
- use App\Entity\Db_Products;
- use App\Entity\Db_Timestamps;
- use App\Entity\Db_Transcripts;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Routing\Annotation\Route;
- use Doctrine\ORM\PersistentCollection;
- use Symfony\Component\HttpFoundation\Request;
- class VideosController extends AbstractController {
- /**
- * @Route("/products/{id}", name="a_products")
- */
- public function index(int $id, UserInterface $userInterface = null, Request $request) {
- header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
- header("Cache-Control: post-check=0, pre-check=0", false);
- header("Pragma: no-cache");
- header("Connection: close");
- if ($product = $this->getDoctrine()->getRepository(Db_Products::class)->find($id)) {
- if ($product->getPublic()) {
- $file = $this->getParameter("kernel.project_dir") . "/products/" . $product->getPath() . "/" . $product->getFile();
- session_write_close();
- header('Content-Type: '.mime_content_type($file));
- header('Content-Length:' . filesize($file));
- return (new VideoStream($file))->start();
- }
- if ($userInterface) {
- if ($userInterface->getRoles()[0] == "ROLE_USER") {
- if (!$request->get("video")) {
- $file = $this->getParameter("kernel.project_dir") . "/products/" . $product->getPath() . "/" . $product->getFile();
- session_write_close();
- header('Content-Type: '.mime_content_type($file));
- header('Content-Length:' . filesize($file));
- return (new VideoStream($file))->start();
- }
- /**
- * @var PersistentCollection
- */
- $users = $product->getUsers();
- foreach ($users as $user) {
- if ($user == $userInterface) {
- $file = $this->getParameter("kernel.project_dir") . "/products/" . $product->getPath() . "/" . $product->getFile();
- if ($videoId = $request->get("video")) {
- /**
- * @var Db_Timestamps
- */
- $video = $this->getDoctrine()->getRepository(Db_Timestamps::class)->find($videoId);
- $file = $this->getParameter("kernel.project_dir") . "/products/" . $product
- ->getPath() . "/" . $video->getVideoName();
- }
- session_write_close();
- header('Content-Type: '.mime_content_type($file));
- header('Content-Length:' . filesize($file));
- return (new VideoStream($file))->start();
- }
- }
- }
- }
- }
- return new Response('Private video', 500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement