WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.62
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/Controller/HomeController.php
<?php

namespace App\Controller;

use App\Entity\Blog;
use App\Entity\ContactUsMessages;
use App\Entity\HomeFeaturedStock;
use App\Entity\Page;
use App\Entity\ReportedStock;
use App\Entity\Stock;
use App\Entity\StockCategory;
use App\Entity\StockType;
use App\Entity\WelcomeLanguages;
use App\Form\ContactUsMessagesType;
use App\Repository\AboutPageRepository;
use App\Repository\BlogRepository;
use App\Repository\FAQsCategoryRepository;
use App\Repository\FAQsRepository;
use App\Repository\HomeFeaturedStockRepository;
use App\Repository\HomePageRepository;
use App\Repository\ModelRepository;
use App\Repository\PageRepository;
use App\Repository\ReleaseRepository;
use App\Repository\StockCategoryRepository;
use App\Repository\StockRepository;
use App\Repository\StockTypeRepository;
use App\Repository\WelcomeLanguagesRepository;
use App\SearchRepository\StockSearchRepository;
use App\Service\Helper;
use App\Service\ImageHelper;
use App\Service\VideoHelper;
use FOS\ElasticaBundle\Manager\RepositoryManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
 * @Route("/home", name="home_")
 */
class HomeController extends AbstractController
{
    /**
     * @Route("/", name="index", methods={"GET"})
     * @param StockCategoryRepository $stockCategoryRepository
     * @param StockTypeRepository $stockTypeRepository
     * @return string
     */
    public function index(StockCategoryRepository $stockCategoryRepository,
                          StockTypeRepository $stockTypeRepository,
                          StockRepository $stockRepository,
                          PageRepository $pageRepository,
                          WelcomeLanguagesRepository $welcomeLanguagesRepository,
                          HomeFeaturedStockRepository $homeFeaturedStockRepository,
                          HomePageRepository $homePageRepository)
    {
        $stockTypes = $stockTypeRepository->findAll();
        $categories=$stockCategoryRepository->findAll();
        $stockCount = count($stockRepository->findAll());
        $home = $pageRepository->findOneBy(['slug'=>'home']);

        $welcomeMessages = $welcomeLanguagesRepository->getWelcomeMessage();
        $featuredStock=$homeFeaturedStockRepository->findBy(['type'=>4]);
        $featuredVideo=$homeFeaturedStockRepository->getFeaturedVideos(5);
        $welcome = null;
        if ($welcomeMessages){
            $welcome = $welcomeMessages[0];
        }

        $homePage = $homePageRepository->findOneBy([]);

        return $this->render('dashboard/index.html.twig', [
            'categories' => $categories,
            'stockTypes' => $stockTypes,
            'stockCount'=>$stockCount,
            'page' => $home,
            'welcome' => $welcome,
            'featuredStock' => $featuredStock,
            'featuredVideo' => $featuredVideo,
            'homePage' => $homePage,
            'greetings' => $welcomeMessages
        ]);
    }
    /**
     * @Route("/{name}/category", name="category", methods={"GET"})
     * @param Request $request
     * @return string
     */
    public function category(StockCategory $category,StockCategoryRepository $stockCategoryRepository,StockRepository $stockRepository)
    {
        $categories=$stockCategoryRepository->findAll();
        $images=$stockRepository->findOneBy(['category'=>$category]);
        return $this->render('dashboard/search.html.twig', [
            'categories' => $categories,
            'images' => $images,
        ]);
    }

    /**
     * @Route("/{title}/type", name="search_type", options={"expose"=true})
     * @param StockType $stockType
     * @param Request $request
     * @param StockRepository $stockRepository
     * @param PaginatorInterface $paginator
     * @param SearchController $searchController
     * @param int $page
     * @param StockTypeRepository $stockTypeRepository
     * @return Response
     */
    public function all_type_stock(StockType $stockType,
                                   Request $request,
                                   StockRepository $stockRepository,
                                   PaginatorInterface $paginator,
                                   SearchController $searchController,
                                   $page=1,
                                   StockTypeRepository $stockTypeRepository)
    {
        $pge = $request->get("page");
        $page=isset($pge) ? $pge : $page;
        $maxItemsPerPage = 300;
//        $stocks = $stockRepository->findBy(['type'=>$stockType, 'Published'=>1]);

        $stocksByType = $stockRepository->findStocksByType($stockType);
        $paginated = $paginator->paginate($stocksByType, $page, $maxItemsPerPage);

        $filteredStocks = [];
//        $sameShoots = [];
        if ($request->isXmlHttpRequest()){
            $sameShootsPrev=$request->get('sameShoot');
            $sameShoots = explode(",",$sameShootsPrev);
        }else{
            $sameShoots = [];
        }

        foreach ($paginated->getItems() as $stock){
            /**
             * @var Stock $stock
             */
            $shootCode = trim($stock->getSameShootCode());

            if ($shootCode=="" || !in_array($shootCode,$sameShoots, true)){
                if ($shootCode != ""){
                    array_push($sameShoots,$shootCode);
                }
//                array_push($filteredStocks,$stock);
                if (!in_array($stock,$filteredStocks)){
                    array_push($filteredStocks, $stock);
                }
            }
        }

        $paginated=$filteredStocks;
//        $count=count($paginated);

        $count = $stocksByType->getQuery()->getScalarResult();
        $count = count($count);

        $lastPage = $count-($page*$maxItemsPerPage) <= $maxItemsPerPage;
        $ajax = $request->get("ajax");

        if ($request->isXmlHttpRequest()){
            if($ajax){
                return new JsonResponse([
                    'html'=>$this->renderView('search/_type_filter_template.html.twig',[
                        'stocks'=>$searchController->removeDuplicates($stocksByType->getQuery()->getResult()),
                        'last_page'=>$lastPage
                    ]),
                    'last_page'=>$lastPage,
                    'sameShoots'=>implode(",", $sameShoots)
                ]);
            }
        }

        $response = new \Symfony\Component\HttpFoundation\Response();
        $response->headers->set("Vary","Accept");
        $type = $stockType->getTitle();
        return $this->render('search/type.html.twig',[
            'stocks' => $searchController->removeDuplicates($stocksByType->getQuery()->getResult()),
            '_type'=>$stockType,
            'search_type' => $stockType,
            'stockTypes'=>$stockTypeRepository->findAll(),
            'last_page'=>$lastPage,
            'sameShoots'=>implode(",", $sameShoots),
            'search_page' => 'type'
        ], $response);
    }

    /**
     * @Route("/{id}/model/stock", name="model_stocks")
     */
    public function model_stocks(Stock $stock,
                                 ModelRepository $modelRepository,
                                 ReleaseRepository $theReleaseRepo,
                                 StockRepository $stockRepository)
    {
        $stock_id = $stock->getId();
        $stock_type = $stock->getType()->getId();

        $sql = "
                SELECT * FROM stock WHERE stock.id in ( 
                SELECT stock_release.the_stock_id FROM stock_release WHERE stock_release.the_release_id IN ( 
                SELECT release_form.id FROM release_form WHERE release_form.model_id IN ( 
                SELECT release_form.model_id FROM release_form WHERE release_form.id IN ( 
                SELECT stock_release.the_release_id FROM stock_release WHERE stock_release.the_stock_id = $stock_id ) ) ) ) 
                AND stock.published=1 AND stock.type_id=$stock_type 
        ";

        $sql2 = "SELECT * FROM model WHERE model.id in ( 
                    SELECT release_form.model_id FROM release_form WHERE release_form.id in ( 
                        SELECT stock_release.the_release_id FROM stock_release WHERE stock_release.the_stock_id = $stock_id ) )";

        $conn = $this->getDoctrine()->getConnection();

        $stocks=[];
        $models=[];
        $stmt = $conn->prepare($sql);
        $stmt->execute();
        foreach ($stmt->fetchAll() as $item){
            $stocks[]=$stockRepository->find($item['id']);
        }

//        dd($stocks);

        $stmt = $conn->prepare($sql2);
        $stmt->execute();
        foreach ($stmt->fetchAll() as $item){
            $models[]=$modelRepository->find($item['id']);
        }



        return $this->render('search/type.html.twig',[
            "stock" => $stock,
            "stocks" => $stocks,
            "type" =>$stock->getType()->getTitle(),
            "_type" =>$stock->getType(),
            "models" =>$models,
            'search_type' => $stock->getType(),
            'count' => count($stockRepository->findAll()),
            'search_page' => 'same_model_search',
            'model_filter_url' => $this->generateUrl('home_model_stocks_filter',['id'=>$stock->getId()])
        ]);
    }

    /**
     * @Route("/{id}/model/stock/filter", name="model_stocks_filter", options={"expose":true}, methods={"GET", "POST"} )
     * @param Request $request
     * @param Stock $stock
     * @param ReleaseRepository $theReleaseRepo
     * @param StockRepository $stockRepository
     * @return JsonResponse
     */
    public function model_stocks_filter(Request $request,
                                        Stock $stock,
                                        ReleaseRepository $theReleaseRepo,
                                        StockRepository $stockRepository)
    {
        $license = $request->request->get("license") ;
        $imageType = $request->request->get("type");
        $orientation = $request->request->get("orientation");
        $people = $request->request->get("people");
        $category = $request->request->get("category");
        $contributor = $request->request->get("contributor");
        $is_exclusive = $request->request->get("is_exclusive");
        $search_video_r = $request->request->get("video_resolution");
        $search_video_resolution = isset($search_video_r) && $search_video_r != null ? $search_video_r : "";

        $stock_id = $stock->getId();
        $stock_type = $stock->getType()->getId();


        $sql = "
                SELECT * FROM stock WHERE stock.id in ( 
                SELECT stock_release.the_stock_id FROM stock_release WHERE stock_release.the_release_id IN ( 
                SELECT release_form.id FROM release_form WHERE release_form.model_id IN ( 
                SELECT release_form.model_id FROM release_form WHERE release_form.id IN ( 
                SELECT stock_release.the_release_id FROM stock_release WHERE stock_release.the_stock_id = $stock_id ) ) ) ) 
                AND stock.published=1 AND stock.type_id=$stock_type 
        ";

        if ($is_exclusive != "0"){
            $sql = "
                SELECT stock.id FROM stock INNER JOIN fos_user ON stock.contributor_id = fos_user.id WHERE stock.id in ( 
                SELECT stock_release.the_stock_id FROM stock_release WHERE stock_release.the_release_id IN ( 
                SELECT release_form.id FROM release_form WHERE release_form.model_id IN ( 
                SELECT release_form.model_id FROM release_form WHERE release_form.id IN ( 
                SELECT stock_release.the_release_id FROM stock_release WHERE stock_release.the_stock_id = $stock_id ) ) ) ) 
                AND stock.published=1 AND stock.type_id=$stock_type AND fos_user.is_exclusive=1
        ";
        }

        if ($license != "null" && $license != ""){
            $sql .= " AND stock.licence_type = '$license'";
        }
        if ($imageType != "null" && $imageType != ""){
            $sql .= "  AND stock.image_type = '".$imageType." Image'";
        }
        if ($orientation != "null" && $orientation != ""){
            $sql .= "  AND stock.orientation = '$orientation'";
        }
        if ($people != "null" && $people != ""){
            $sql .= "  AND stock.people_no = '$people'";
        }
        if ($category != "null" && $category != ""){
            $sql .= "  AND (stock.category_id = '$category' OR category2_id = '$category'";
            $sql .= " OR stock.id in (select stocks_cats.stock_id FROM stocks_cats where stocks_cats.category_stock_cat_id = '$category'))";
        }
        if ($contributor != "null" && $contributor != ""){
            $sql .= "  AND stock.contributor_id = '$contributor'";
        }
        if ($search_video_resolution != "null" && $search_video_resolution != ""){
            $sql .= "  AND stock.video_resolution = '$search_video_resolution'";
        }


        $conn = $this->getDoctrine()->getConnection();

        $stocks=[];
        $stmt = $conn->prepare($sql);
        $stmt->execute();
        foreach ($stmt->fetchAll() as $item){
            $stocks[]=$stockRepository->find($item['id']);
        }


        return new JsonResponse([
            "html" => $this->renderView('search/_type_filter_template.html.twig',[
                'stocks' => $stocks
            ]),
            "count" => count($stocks),
        ]);
    }

    /**
     * @Route("/{id}/similar", name="similar_stock", options={"expose"=true})
     * @param Stock $stock
     * @param Request $request
     * @param int $page
     * @param PaginatorInterface $paginator
     * @param SearchController $searchController
     * @param RepositoryManagerInterface $manager
     * @return Response
     */
    public function similar_stock(Stock $stock,
                                  Request $request,
                                  $page=1,
                                  PaginatorInterface $paginator,
                                  SearchController $searchController,
                                  RepositoryManagerInterface $manager)
    {
        $pge = $request->get("page");
        $page=isset($pge) ? $pge : $page;
        $maxItemsPerPage = 25;

        /**@var $stockSearchRepo StockSearchRepository**/
        $stockSearchRepo = $manager->getRepository(Stock::class);
        $similarStock = $stockSearchRepo->search_similar_stock($stock);
        $orginalStock = $stock;

        $paginated = $paginator->paginate($similarStock, $page, $maxItemsPerPage);

        $filteredStocks = [];
        $sameShoots = [];

        foreach ($paginated->getItems() as $stock){
            /**
             * @var Stock $stock
             */
            $shootCode = trim($stock->getSameShootCode());

            if ($shootCode=="" || $shootCode==null){
                array_push($filteredStocks, $stock);
            }
            else{
                if (!in_array($shootCode,$sameShoots, true)) {
                    if ($shootCode != "" || !empty($shootCode)) {
                        array_push($sameShoots, $shootCode);
                    }
//                    array_push($filteredStocks, $stock);
                    if (!in_array($stock,$filteredStocks)){
                        array_push($filteredStocks, $stock);
                    }
                }
            }
        }

        $paginated=$filteredStocks;

        $count = count($similarStock);
        $lastPage = $count-($page*$maxItemsPerPage) <= 0;



        $response = new \Symfony\Component\HttpFoundation\Response();
        $response->headers->set("Vary","Accept");
        return $this->render('search/type.html.twig',[
            "stocks" => $searchController->removeDuplicates($similarStock),
            "stock" => $orginalStock,
            'last_page'=>$lastPage,
            'id'=>$stock->getId(),
            '_type' => $stock->getType(),
            'sameShoots'=>implode(",", $sameShoots),
            'search_type'=>$stock->getType(),
            'search_page' => 'similar_stock_search'
        ], $response);
    }

    /**
     * @Route("/{id}/similar/lazy", name="similar_stock_lazy", options={"expose"=true})
     * @param Stock $stock
     * @param Request $request
     * @param int $page
     * @param SearchController $searchController
     * @param PaginatorInterface $paginator
     * @param RepositoryManagerInterface $manager
     * @return JsonResponse
     */
    public function similar_stock_lazy(Stock $stock,
                                  Request $request,
                                  $page=1,
                                  SearchController $searchController,
                                  PaginatorInterface $paginator,
                                  RepositoryManagerInterface $manager)
    {
        $pge = $request->get("page");
        $page=isset($pge) ? $pge : $page;
        $maxItemsPerPage = 25;

        /**@var $stockSearchRepo StockSearchRepository**/
        $stockSearchRepo = $manager->getRepository(Stock::class);
        $similarStock = $stockSearchRepo->search_similar_stock($stock);

        $paginated = $paginator->paginate($similarStock, $page, $maxItemsPerPage);

        $filteredStocks = [];
        $sameShootsPrev=$request->get('sameShoot');
        $sameShoots = explode(",",$sameShootsPrev);
        foreach ($paginated->getItems() as $stock){
            /**
             * @var Stock $stock
             */
            $shootCode = trim($stock->getSameShootCode());

            if ($shootCode=="" || $shootCode==null){
                array_push($filteredStocks, $stock);
            }
            else{
                if (!in_array($shootCode,$sameShoots, true)) {
                    if ($shootCode != "" || !empty($shootCode)) {
                        array_push($sameShoots, $shootCode);
                    }
                    array_push($filteredStocks, $stock);
                }
            }
        }
        $paginated=$filteredStocks;

//        $count = $similarStock->getTotalHits();
        $count = count($similarStock);
        $lastPage = $count-($page*$maxItemsPerPage) <= 0;

            return new JsonResponse([
                'html' => $this->renderView('search/_lazy_load_template.html.twig', [
                    'stocks'=>$searchController->removeDuplicates($similarStock),
                ]),
                'last_page'=>$lastPage,
                'id'=>$stock->getId(),
                'sameShoots'=>implode(",", $sameShoots)
            ]);
    }

    /**
     * @Route("/{id}/same-shoot", name="same_shoot", options={"expose"=true})
     */
    public function same_shoot_stock(Stock $stock,
                                  Request $request,
                                  $page=1,
                                  PaginatorInterface $paginator,
                                  RepositoryManagerInterface $manager)
    {
        $pge = $request->get("page");
        $page=isset($pge) ? $pge : $page;
        $maxItemsPerPage = 25;

        /**@var $stockSearchRepo StockSearchRepository**/
        $stockSearchRepo = $manager->getRepository(Stock::class);
        $similarStock = $stockSearchRepo->search_same_shoot_stock($stock);

        $paginated = $paginator->paginate($similarStock, $page, $maxItemsPerPage);

        $count = is_array($similarStock) ? count($similarStock) : $similarStock->getTotalHits();
//        $count = count($similarStock);
        $lastPage = $count-($page*$maxItemsPerPage) <= $maxItemsPerPage;

        $response = new \Symfony\Component\HttpFoundation\Response();
        $response->headers->set("Vary","Accept");
        return $this->render('search/type.html.twig',[
            "stocks" => $similarStock,
            "stock" => $stock,
            'last_page'=>$lastPage,
            'search_type'=>$stock->getType(),
            'id'=>$stock->getId(),
            '_type' => $stock->getType(),
            'search_page' => 'same_shoot_search'
        ], $response);
    }

    /**
     * @Route("/{id}/same_shoot/lazy", name="same_shoot_stock_lazy", options={"expose"=true})
     */
    public function same_shoot_stock_lazy(Stock $stock,
                                       Request $request,
                                       $page=1,
                                       PaginatorInterface $paginator,
                                       RepositoryManagerInterface $manager)
    {
        $pge = $request->get("page");
        $page=isset($pge) ? $pge : $page;
        $maxItemsPerPage = 25;

        /**@var $stockSearchRepo StockSearchRepository**/
        $stockSearchRepo = $manager->getRepository(Stock::class);
        $similarStock = $stockSearchRepo->search_same_shoot_stock($stock);

        $paginated = $paginator->paginate($similarStock, $page, $maxItemsPerPage);
        $count = $similarStock->getTotalHits();
        $lastPage = $count-($page*$maxItemsPerPage) <= $maxItemsPerPage;

        return new JsonResponse([
            'html' => $this->renderView('search/_lazy_load_template.html.twig', [
                'stocks'=>$similarStock,
            ]),
            'last_page'=>$lastPage,
            'id'=>$stock->getId()
        ]);
    }

    /**
     * @Route("/get-featured", name="get_featured")
     * @param Request $request
     * @param StockRepository $stockRepository
     * @param HomeFeaturedStockRepository $homeFeaturedStockRepository
     * @return mixed
     */
    public function getFeaturedStock(Request $request, StockRepository $stockRepository , HomeFeaturedStockRepository $homeFeaturedStockRepository)
    {
        /**
         * @var $stockType StockType
         */
        $stockType = $request->request->get("type");

        if (count($homeFeaturedStockRepository->getFeaturedStock($stockType)) == 0){
            return new JsonResponse(["error" => 1]);
        }
        $featuredStocks = $homeFeaturedStockRepository->getFeaturedStock($stockType);
        /**@var $featured HomeFeaturedStock**/
        $featured = $featuredStocks[0];

        $file = $featured ? $featured->getFile() :$featured;

        return new JsonResponse([
            "file"=>$file,
            "contributor"=>$featured ? $featured->getContributor()->getFullName(): $featured
        ]);
    }

    /**
     * @Route("/{slug}/about", name="home_about")
     */
    public function about(Page $page)
    {
        if ($page == null){
            return $this->redirectToRoute('home_index');
        }
        return $this->render('home/about.html.twig', [
            'page' => $page
        ]);
    }

    /**
     * @Route("/{slug}", name="page_show")
     */
    public function getPage(Page $page)
    {
        if ($page == null){
            return $this->redirectToRoute('home_index');
        }
        return $this->render('home/page_show.html.twig', [
            'page' => $page
        ]);
    }

    /**
     * @return Response
     * @Route("/about/us", name="to_about")
     */
    public function getAboutUs(AboutPageRepository $aboutPageRepository)
    {
        $aboutPage = $aboutPageRepository->find(1);
        return $this->render('static/about.html.twig',[
            'aboutPage' => $aboutPage
        ]);
    }

    /**
     * @return Response
     * @Route("/contact/us", name="to_contact_us")
     */
    public function getContactUs(AboutPageRepository $aboutPageRepository)
    {
        return $this->render('static/contact.html.twig');
    }

    /**
     * @return Response
     * @Route("/terms/of/service", name="to_terms")
     */
    public function getTerms(Request $request, PageRepository $pageRepository)
    {
        $referer = $request->headers->get('referer');
        $termsPage = $pageRepository->findOneBy(['slug'=>'terms-of-service']);
        return $this->render('static/terms_condition.html.twig',['page'=>$termsPage]);
    }

    /**
     * @return Response
     * @Route("/privacy/policy", name="to_privacy")
     */
    public function getPrivacyPolicyPage(AboutPageRepository $aboutPageRepository)
    {
        return $this->render('static/privacy_policy.html.twig');
    }


    /**
     * @return Response
     * @Route("/frequent/questions", name="to_faqs")
     */
    public function getFaqs(FAQsCategoryRepository $FAQsCategoryRepository)
    {
        $faqsCategories = $FAQsCategoryRepository->findAll();
        return $this->render('static/faq.html.twig',[
            'faqs_categories' => $faqsCategories
        ]);
    }

    /**
     * @param BlogRepository $blogRepository
     * @return Response
     * @Route("/blogs/all", name="blogs")
     */
    public function getBlogs(BlogRepository $blogRepository)
    {
        return $this->render("static/blogs.html.twig", [
            "blogs" => $blogRepository->getAllBlogs()
        ]);
    }

    /**
     * @Route("/blogs/{id}/read", name="blog_read")
     */
    public function getSingleBlog(Blog $blog, BlogRepository $blogRepository)
    {

        return $this->render('static/single-blog.html.twig',[
            'blog'=>$blog,
            'related' => $blogRepository->findRelated($blog)
        ]);
    }

    /**
     * @Route("/contact/send/message", name="send_contact_us_message")
     */
    public function sendContectUsMessage(Request $request)
    {
        $contactUsMessage = new ContactUsMessages();
        $form = $this->createForm(ContactUsMessagesType::class, $contactUsMessage);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $contactUsMessage->setCreatedAt(new \DateTime());
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($contactUsMessage);
            $entityManager->flush();

            $response = "Your message has been received. A response will sent to you via E-mail.";
            $this->addFlash("message", $response);
            return $this->redirectToRoute('home_send_contact_us_message');
        }

        return $this->render('static/contact.html.twig', [
            'contact_us_message' => $contactUsMessage,
            'form' => $form->createView(),
        ]);
    }

    /**
     * @Route("/greeting", name="get_greeting")
     * @param WelcomeLanguagesRepository $welcomeLanguagesRepository
     * @return JsonResponse
     */
    public function getGreeting(WelcomeLanguagesRepository $welcomeLanguagesRepository)
    {
        $welcomeMessages = $welcomeLanguagesRepository->getWelcomeMessage();
        /**@var WelcomeLanguages $welcome**/
        $welcome = null;
        if ($welcomeMessages){
            $welcome = $welcomeMessages[0];
        }
        if ($welcome){
            return new JsonResponse([
                'html' => $this->renderView('welcome_languages/_welcome_template.html.twig', [
                    'welcome' => $welcome
                ])
            ]);
        }

        return new JsonResponse(['error' => true]);
    }

    /**
     * @Route("/{id}/report", name="report_stock", methods={"GET","POST"})
     * @param Request $request
     * @param Stock $stock
     * @return Response
     * @throws \Exception
     */
    public function report(Request $request, Stock $stock): Response
    {


        if(!empty($request->request)){

            $currentUser=$this->getUser();



            $reported_stock = new ReportedStock();

            $reported_stock->setStock($stock);


            if ($currentUser){
                $reported_stock->setSource($currentUser);

                //TODO: Send email
            }

            $reported_stock->setReportDate(new \DateTime());

            $reported_stock->setReason($request->request->get('reported_stock')['Reason']);

            $reported_stock->setDetails($request->request->get('reported_stock')['Details']);

            $em = $this->getDoctrine()->getManager();

            $em->persist($reported_stock);

            $em->flush();

            $this->addFlash('report_success', 'The File has been reported successfully. The Site Admin will review the file shortly');

            return $this->redirectToRoute('image_details',['id'=>$stock->getId()]);

        }
        return new Response(0);
    }

    /**
     * @Route("/stock/generate", name="generate_video_sizes")
     */
    public function generateStockSizes(VideoHelper $videoHelper, ImageHelper $imageHelper, StockRepository $repository, Helper $helper)
    {
        $videoType = $helper->getVideosType();
        $stock = $repository->findOneBy(['status' => Stock::APPROVED_STOCK, 'Published'=>false, 'type'=>$videoType]);

        if($stock){
            if ($stock->getType() == $videoType){
                $videoHelper->generateVideoSizes($stock);
            }
        }

        return new Response(0);
    }

    /**
     * @Route("/stock/thumb/generate", name="generate_video_sizes_")
     */
    public function generateThumbs(VideoHelper $videoHelper, ImageHelper $imageHelper, StockRepository $repository, Helper $helper)
    {
        $videoType = $helper->getVideosType();
        $stock = $repository->findOneBy(['status' => Stock::APPROVED_STOCK, 'Published'=>true, 'type'=>$videoType,'processed'=>false]);

        if($stock){
            if ($stock->getType() == $videoType){
                $videoHelper->regenerateVideoSizes($stock);
            }
        }

        return new Response(0);

//        $videoType = $helper->getVideosType();
//        $stock = $repository->find(3729);
//
//        if($stock){
//            if ($stock->getType() == $videoType){
//                $videoHelper->regenerateVideoSizes($stock);
//            }
//        }
//
//        return new Response(0);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit