src/Controller/HomeController.php line 21

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Playlist;
  4. use App\Repository\AdsRepository;
  5. use App\Repository\PlaylistRepository;
  6. use App\Repository\CategoryRepository;
  7. use App\Repository\InstructorRepository;
  8. use App\Repository\UserRepository;
  9. use App\Services\VimeoVideo;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class HomeController extends AbstractController
  16. {
  17.     #[Route('/', name: 'app_home')]
  18.     public function index(PlaylistRepository $playlistRepository, AdsRepository $adsRepository, InstructorRepository $instructorRepository, CategoryRepository $categoryRepository, SessionInterface $sessionInterface ,UserRepository $userRepository,UserPasswordHasherInterface $userPasswordHasher): Response
  19.     {
  20.         
  21.         $useri = $this->getUser();            
  22.         if ($useri && !($this->isGranted('ROLE_USER_ADMIN'))) {
  23.             $sess = $sessionInterface->getId();
  24.             $user = $userRepository->findOneBy(['phone' => $useri->getUserIdentifier()]);
  25.             // if ($sess != $user->getSess()) {
  26.             //     $pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6);
  27.             //     $user->setSess($sess);
  28.             //     $user->setPassword(
  29.             //         $userPasswordHasher->hashPassword(
  30.             //             $user,
  31.             //             $pass
  32.             //         )
  33.             //     );
  34.             //     $userRepository->save($user,true);
  35.             // }
  36.         }
  37.         return $this->render('home/index.html.twig', [
  38.             // 'controller_name' => 'HomeController',
  39.             'user' => $this->getUser(),
  40.             'playlist' => $playlistRepository->findBy(["publish" => true]),
  41.             'ads' => $adsRepository->findAll(),
  42.             'instructors' => $instructorRepository->findAll(),
  43.             'categories' => $categoryRepository->findAll()
  44.         ]);
  45.     }
  46.     //addPlaylist to card
  47.     #[Route('/addPlaylist/{id}', name: 'app_add_playlist')]
  48.     public function addPlaylist(Playlist $playlist, SessionInterface $sessionInterface): Response
  49.     {
  50.         $user = $this->getUser();
  51.         if ($user) {
  52.             $card = $sessionInterface->get('card', []);
  53.             if (!in_array($playlist->getId(), $card)) {
  54.                 $card[] = $playlist->getId();
  55.                 $sessionInterface->set('card', $card);
  56.             }
  57.         }
  58.         return $this->redirectToRoute('app_orders_index');
  59.     }
  60.     //removePlaylist from card
  61.     #[Route('/removePlaylist/{id}', name: 'app_remove_playlist')]
  62.     public function removePlaylist(Playlist $playlist, SessionInterface $sessionInterface): Response
  63.     {
  64.         $user = $this->getUser();
  65.         if ($user) {
  66.             $card = $sessionInterface->get('card', []);
  67.             if (in_array($playlist->getId(), $card)) {
  68.                 unset($card[array_search($playlist->getId(), $card)]);
  69.                 $sessionInterface->set('card', $card);
  70.             }
  71.         }
  72.         return $this->redirectToRoute('app_orders_index');
  73.     }
  74.     //notification
  75.     #[Route('/notification', name: 'app_notification')]
  76.     public function notification(SessionInterface $sessionInterface,PlaylistRepository $playlistRepository): Response
  77.     {
  78.         $user = $this->getUser();
  79.         if ($user) {
  80.             $card = $sessionInterface->get('card', []);
  81.             $playlists = $playlistRepository->findBy(['id' => $card]);
  82.             return $this->render('notification.html.twig', [
  83.                 'playlists' => $playlists,
  84.             ]);
  85.             
  86.         }
  87.         return $this->render('notification.html.twig', [
  88.             'playlists' => [],
  89.         ]);
  90.     }
  91. }