src/Controller/HomeController.php line 52
<?phpnamespace App\Controller;use App\Entity\Playlist;use App\Repository\AdsRepository;use App\Repository\PlaylistRepository;use App\Repository\CategoryRepository;use App\Repository\InstructorRepository;use App\Repository\UserRepository;use App\Services\VimeoVideo;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpFoundation\Session\SessionInterface;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;use Symfony\Component\Routing\Annotation\Route;class HomeController extends AbstractController{#[Route('/', name: 'app_home')]public function index(PlaylistRepository $playlistRepository, AdsRepository $adsRepository, InstructorRepository $instructorRepository, CategoryRepository $categoryRepository, SessionInterface $sessionInterface ,UserRepository $userRepository,UserPasswordHasherInterface $userPasswordHasher): Response{$useri = $this->getUser();if ($useri && !($this->isGranted('ROLE_USER_ADMIN'))) {$sess = $sessionInterface->getId();$user = $userRepository->findOneBy(['phone' => $useri->getUserIdentifier()]);// if ($sess != $user->getSess()) {// $pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6);// $user->setSess($sess);// $user->setPassword(// $userPasswordHasher->hashPassword(// $user,// $pass// )// );// $userRepository->save($user,true);// }}return $this->render('home/index.html.twig', [// 'controller_name' => 'HomeController','user' => $this->getUser(),'playlist' => $playlistRepository->findBy(["publish" => true]),'ads' => $adsRepository->findAll(),'instructors' => $instructorRepository->findAll(),'categories' => $categoryRepository->findAll()]);}//addPlaylist to card#[Route('/addPlaylist/{id}', name: 'app_add_playlist')]public function addPlaylist(Playlist $playlist, SessionInterface $sessionInterface): Response{$user = $this->getUser();if ($user) {$card = $sessionInterface->get('card', []);if (!in_array($playlist->getId(), $card)) {$card[] = $playlist->getId();$sessionInterface->set('card', $card);}}return $this->redirectToRoute('app_orders_index');}//removePlaylist from card#[Route('/removePlaylist/{id}', name: 'app_remove_playlist')]public function removePlaylist(Playlist $playlist, SessionInterface $sessionInterface): Response{$user = $this->getUser();if ($user) {$card = $sessionInterface->get('card', []);if (in_array($playlist->getId(), $card)) {unset($card[array_search($playlist->getId(), $card)]);$sessionInterface->set('card', $card);}}return $this->redirectToRoute('app_orders_index');}//notification#[Route('/notification', name: 'app_notification')]public function notification(SessionInterface $sessionInterface,PlaylistRepository $playlistRepository): Response{$user = $this->getUser();if ($user) {$card = $sessionInterface->get('card', []);$playlists = $playlistRepository->findBy(['id' => $card]);return $this->render('notification.html.twig', ['playlists' => $playlists,]);}return $this->render('notification.html.twig', ['playlists' => [],]);}}