src/Controller/HomeController.php line 125

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ArchitectDetails;
  4. use App\Entity\ShowroomDetails;
  5. use App\Form\ChangePasswordFormType;
  6. use App\Form\CKEditorMessageType;
  7. use App\Form\ProfileType;
  8. use App\Repository\ContactPreferencesRepository;
  9. use App\Repository\ContactUsRepository;
  10. use App\Repository\DirectoryProfileCategoriesRepository;
  11. use App\Repository\DirectoryProfileRepository;
  12. use App\Repository\EducationCategoryRepository;
  13. use App\Repository\EducationSponsorDetailsRepository;
  14. use App\Repository\EducationsRepository;
  15. use App\Repository\EducationTypeRepository;
  16. use App\Repository\MemosRepository;
  17. use App\Repository\PodcastRepository;
  18. use App\Repository\PrivateCommunityRepository;
  19. use App\Repository\ResourcesRepository;
  20. use App\Repository\SubscriptionTransactionsRepository;
  21. use App\Repository\UserRepository;
  22. use App\Services\EmailTemplatesService;
  23. use App\Services\ImageService;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  31. use Symfony\Component\Routing\Annotation\Route;
  32. use Symfony\Component\Security\Core\Security;
  33. use Symfony\Contracts\Translation\TranslatorInterface;
  34. use Twig\Environment;
  35. use App\Services\S3Service;
  36. use Symfony\Component\HttpFoundation\File\UploadedFile;
  37. use Aws\S3\S3Client;
  38. class HomeController extends AbstractController
  39. {
  40.     private $params;
  41.     private $translator;
  42.     private $userRepository;
  43.     private $helper;
  44.     private $contactUsRepository;
  45.     private $contactPreferenceRepository;
  46.     private $directoryProfileRepository;
  47.     private $directoryProfileCategoriesRepository;
  48.     private $educationRepository;
  49.     private $educationCategoryRepository;
  50.     private $educationTypeRepository;
  51.     private $educationSponsorDetailsRepository;
  52.     private $subscriptionTransactionsRepository;
  53.     private $resourcesRepository;
  54.     protected $entityManager;
  55.     protected $memosRepository;
  56.     protected $podcastRepository;
  57.     protected $privateCommunityRepository;
  58.     protected $imageService;
  59.     protected $emailTemplates;
  60.     private $s3Service;
  61.     private $s3Client;
  62.     public function __construct(
  63.         Environment $twig,
  64.         ParameterBagInterface $params,
  65.         TranslatorInterface $translator,
  66.         UserRepository $userRepository,
  67.         \App\Helper\helpers $helper,
  68.         ContactUsRepository $contactUsRepository,
  69.         ContactPreferencesRepository $contactPreferenceRepository,
  70.         DirectoryProfileRepository $directoryProfileRepository,
  71.         DirectoryProfileCategoriesRepository $directoryProfileCategoriesRepository,
  72.         EducationsRepository $educationRepository,
  73.         EducationTypeRepository $educationTypeRepository,
  74.         EducationCategoryRepository $educationCategoryRepository,
  75.         EducationSponsorDetailsRepository $educationSponsorDetailsRepository,
  76.         SubscriptionTransactionsRepository $subscriptionTransactionsRepository,
  77.         ResourcesRepository $resourcesRepository,
  78.         EntityManagerInterface $entityManager,
  79.         MemosRepository $memosRepository,
  80.         PodcastRepository $podcastRepository,
  81.         PrivateCommunityRepository $privateCommunityRepository,
  82.         EmailTemplatesService $emailTemplates,
  83.         ImageService $imageService,
  84.         S3Service $s3Service,
  85.         S3Client $s3Client
  86.     ) {
  87.         // $this->loader = $twig->getLoader();
  88.         $this->translator $translator;
  89.         $this->userRepository $userRepository;
  90.         $this->helper $helper;
  91.         $this->contactUsRepository $contactUsRepository;
  92.         $this->contactPreferenceRepository $contactPreferenceRepository;
  93.         $this->directoryProfileRepository $directoryProfileRepository;
  94.         $this->directoryProfileCategoriesRepository $directoryProfileCategoriesRepository;
  95.         $this->params $params;
  96.         $this->educationRepository $educationRepository;
  97.         $this->educationCategoryRepository $educationCategoryRepository;
  98.         $this->educationTypeRepository $educationTypeRepository;
  99.         $this->educationSponsorDetailsRepository $educationSponsorDetailsRepository;
  100.         $this->subscriptionTransactionsRepository $subscriptionTransactionsRepository;
  101.         $this->resourcesRepository $resourcesRepository;
  102.         $this->entityManager $entityManager;
  103.         $this->memosRepository $memosRepository;
  104.         $this->podcastRepository $podcastRepository;
  105.         $this->privateCommunityRepository $privateCommunityRepository;
  106.         $this->emailTemplates $emailTemplates;
  107.         $this->imageService $imageService;
  108.         $this->s3Service $s3Service;
  109.         $this->s3Client $s3Client;
  110.     }
  111.     //     #[Route('/', name: 'root')]
  112.     // public function  home()
  113.     // {
  114.     //     // Logic for the root path
  115.     //     return $this->render('home.html.twig');
  116.     // }
  117.     #[Route('/dashboard'name'home')]
  118.     public function index(Request $request): Response
  119.     {
  120.         // Counter for Interior Designers
  121.         $interiorDesigners $this->userRepository->createQueryBuilder('id')
  122.             ->select('count(id.id) as total')
  123.             ->andwhere('id.deleted_at IS NULL')
  124.             ->andwhere('id.user_role_type = :user_role_type')
  125.             ->setParameter('user_role_type''interior_designer')
  126.             ->andwhere('id.status = :status')
  127.             ->setParameter('status''1')
  128.             ->getQuery()
  129.             ->getOneOrNullResult();
  130.         $interiorDesignersCount $interiorDesigners['total'];
  131.         // Counter for Home Owners
  132.         $homeOwners $this->userRepository->createQueryBuilder('ho')
  133.             ->select('count(ho.id) as total')
  134.             ->andwhere('ho.user_role_type = :user_role_type')
  135.             ->andwhere('ho.deleted_at IS NULL')
  136.             ->setParameter('user_role_type''home_owner')
  137.             ->andwhere('ho.status = :status')
  138.             ->setParameter('status''1')
  139.             ->getQuery()
  140.             ->getOneOrNullResult();
  141.         $homeOwnerCount $homeOwners['total'];
  142.         // Counter for Architects / Builders
  143.         $architects $this->userRepository->createQueryBuilder('ar')
  144.             ->select('count(ar.id) as total')
  145.             ->Join(ArchitectDetails::class, 'ad''WITH''ar.id = ad.user_id')
  146.             ->andwhere('ad.deleted_at IS NULL')
  147.             ->andwhere('ar.deleted_at IS NULL')
  148.             ->andwhere('ar.user_role_type = :user_role_type')
  149.             ->setParameter('user_role_type''architect')
  150.             ->andwhere('ar.status = :status')
  151.             ->setParameter('status''1')
  152.             ->getQuery()
  153.             ->getOneOrNullResult();
  154.         $architectCount $architects['total'];
  155.         // Counter for Showrooms
  156.         $showrooms $this->userRepository->createQueryBuilder('sr')
  157.             ->select('count(sr.id) as total')
  158.             ->Join(ShowroomDetails::class, 'sd''WITH''sr.id = sd.user')
  159.             ->andWhere('sd.deleted_at IS NULL')
  160.             ->andWhere('sr.user_role_type = :user_role_type')
  161.             ->andWhere('sr.deleted_at IS NULL')
  162.             ->setParameter('user_role_type''showroom')
  163.             ->andwhere('sr.status = :status')
  164.             ->setParameter('status''1')
  165.             ->getQuery()
  166.             ->getOneOrNullResult();
  167.         $showroomCount $showrooms['total'];
  168.         // counter for memos
  169.         $memos $this->memosRepository->createQueryBuilder('mr')
  170.             ->select('count(mr.id) as total')
  171.             ->where('mr.deleted_at IS NULL')
  172.             ->andwhere('mr.is_active = :status')
  173.             ->setParameter('status''1')
  174.             ->getQuery()
  175.             ->getOneOrNullResult();
  176.         $memoCount $memos['total'];
  177.         // counter for Podcasts
  178.         $Podcasts $this->podcastRepository->createQueryBuilder('pr')
  179.             ->select('count(pr.id) as total')
  180.             ->where('pr.deleted_at IS NULL')
  181.             ->andwhere('pr.is_active = :status')
  182.             ->setParameter('status''1')
  183.             ->getQuery()
  184.             ->getOneOrNullResult();
  185.         $podcastCount $Podcasts['total'];
  186.         // counter for directoryProfiles
  187.         $directoryProfiles $this->directoryProfileRepository->createQueryBuilder('dpr')
  188.             ->select('count(dpr.id) as total')
  189.             ->where('dpr.deleted_at IS NULL')
  190.             ->andWhere('dpr.is_approved = :is_approved')
  191.             ->setParameter('is_approved''approved')
  192.             ->andWhere('dpr.is_active = :is_active')
  193.             ->setParameter('is_active''1')
  194.             ->getQuery()
  195.             ->getOneOrNullResult();
  196.         $directoryProfilesCount $directoryProfiles['total'];
  197.         // counter for privateCommunityUsers
  198.         $privateCommunityUsers $this->privateCommunityRepository->createQueryBuilder('pcr')
  199.             ->select('count(pcr.id) as total')
  200.             ->where('pcr.deleted_at IS NULL')
  201.             ->andWhere('pcr.is_approved = :is_approved')
  202.             ->setParameter('is_approved''approved')
  203.             ->andWhere('pcr.is_active = :is_active')
  204.             ->setParameter('is_active''1')
  205.             ->getQuery()
  206.             ->getOneOrNullResult();
  207.         $privateCommunityUsersCount $privateCommunityUsers['total'];
  208.         $baseUrl $request->getSchemeAndHttpHost();
  209.         return $this->render(
  210.             'index.html.twig',
  211.             [
  212.                 'interiorDesignersCount' => $interiorDesignersCount,
  213.                 'homeOwnerCount' => $homeOwnerCount,
  214.                 'architectCount' => $architectCount,
  215.                 'showroomCount' => $showroomCount,
  216.                 'memoCount' => $memoCount,
  217.                 'podcastCount' => $podcastCount,
  218.                 'directoryProfilesCount' => $directoryProfilesCount,
  219.                 'privateCommunityUsersCount' => $privateCommunityUsersCount,
  220.                 'baseUrl' => $baseUrl,
  221.             ]
  222.         );
  223.     }
  224.     #[Route('/myProfile'name'myProfile')]
  225.     public function myfrofile(Request $requestSecurity $securityUserRepository $userRepositoryEntityManagerInterface $em): Response
  226.     {
  227.         $email $security->getUser()->getId();
  228.         $user $userRepository->find($email);
  229.         $user->setEmail($user->getEmail());
  230.         $form $this->createForm(ProfileType::class, $user);
  231.         $form->handleRequest($request);
  232.         if ($form->isSubmitted() && $form->isValid()) {
  233.             $user->setFirstName($this->helper->formatFullName($user->getFirstName()));
  234.             $user->setLastName($this->helper->formatFullName($user->getLastName()));
  235.             $user->setPhone($user->getPhone());
  236.             $user->setEmail($user->getEmail());
  237.             $this->addFlash('success''User Updated Successfully');
  238.             $em->persist($user);
  239.             $em->flush();
  240.             return $this->redirectToRoute('myProfile');
  241.         }
  242.         return $this->render(
  243.             'user/profile.html.twig',
  244.             [
  245.                 'form' => $form->createView(),
  246.             ]
  247.         );
  248.     }
  249.     #[Route('/changePassword'name'changePassword')]
  250.     public function changePassword(Request $requestUserPasswordHasherInterface $passwordHasherTranslatorInterface $translatorsEntityManagerInterface $entityManagerSecurity $securityUserRepository $userRepository): Response
  251.     {
  252.         // The token is valid; allow the user to change their password.
  253.         $form $this->createForm(ChangePasswordFormType::class);
  254.         $form->handleRequest($request);
  255.         if ($form->isSubmitted() && $form->isValid()) {
  256.             $email $security->getUser()->getUserIdentifier();
  257.             $user $userRepository->findOneBy(['email' => $email]);
  258.             $encodedPassword $passwordHasher->hashPassword(
  259.                 $user,
  260.                 $form->get('plainPassword')->getData()
  261.             );
  262.             $user->setPassword($encodedPassword);
  263.             $entityManager->flush();
  264.             $this->addFlash('success'$this->translator->trans('message.modules.success.pwd_reset'));
  265.             return $this->redirectToRoute('changePassword');
  266.         }
  267.         return $this->render('user/changePass.html.twig', [
  268.             'resetForm' => $form->createView(),
  269.         ]);
  270.     }
  271.     #[Route('/dashboard-contact-us'name'dashboard_contact_us_list')]
  272.     public function getContactUsData(Request $request)
  273.     {
  274.         $arrWhoCanCheck $this->params->get('arrWhoCanCheck');
  275.         $isRepliable $this->helper->whoCanCheck($arrWhoCanCheck'admin_contact_us_reply');
  276.         $isDeletable $this->helper->whoCanCheck($arrWhoCanCheck'admin_contact_us_delete');
  277.         $length 5;
  278.         $queryBuilder $this->contactUsRepository->createQueryBuilder('c')
  279.             ->select('c.id''c.first_name ''c.last_name ''c.email''c.subject''c.message''c.phone''c.created_at''c.is_replied''c.preferences')
  280.             ->where('c.deleted_at IS NULL')
  281.             ->orderBy('c.updated_at''DESC')->setFirstResult(0)->setMaxResults($length);
  282.         $contactUsData $queryBuilder->getQuery()->getResult();
  283.         $data = [];
  284.         $form $this->createForm(CKEditorMessageType::class);
  285.         $form->handleRequest($request);
  286.         $renderedTemplate $this->renderView('contact_us/ckeditor.html.twig', [
  287.             'form' => $form->createView(),
  288.         ]);
  289.         foreach ($contactUsData as $value) {
  290.             $action '';
  291.             $availableActions = [];
  292.             if ($value['is_replied'] == 1) {
  293.                 if ($isRepliable) {
  294.                     $availableActions['replyView'] = [
  295.                         'id' => $value['id'],
  296.                     ];
  297.                 }
  298.             } else {
  299.                 if ($isRepliable) {
  300.                     $availableActions['reply'] = [
  301.                         'id' => $value['id'],
  302.                     ];
  303.                 }
  304.             }
  305.             if ($isDeletable) {
  306.                 $availableActions['delete'] = [
  307.                     'id' => $value['id'],
  308.                 ];
  309.             }
  310.             $action $this->renderView('components/actions.html.twig', [
  311.                 'availableActions' => $availableActions,
  312.             ]);
  313.             $preferenceName null;
  314.             $preferenceValue $this->contactPreferenceRepository->find($value['preferences']);
  315.             if ($preferenceValue !== null) {
  316.                 $preferenceName $preferenceValue->getName();
  317.             }
  318.             $data[] = [
  319.                 $value['id'],
  320.                 $action,
  321.                 $this->helper->formatFullName($value['first_name']),
  322.                 $this->helper->formatFullName($value['last_name']),
  323.                 $preferenceName,
  324.                 $value['email'],
  325.                 $value['phone'],
  326.                 $value['created_at']->format('M d, Y'),
  327.             ];
  328.         }
  329.         $json_data = array(
  330.             "draw" => intval($request->query->get('draw')),
  331.             "data" => $data,
  332.             "renderTemplate" => $renderedTemplate,
  333.         );
  334.         return new JsonResponse($json_data);
  335.     }
  336.     #[Route('/dashboard-directory-profiles'name'dashboard_directory_profile_list')]
  337.     public function getDirectoryProfileList(Request $request)
  338.     {
  339.         $arrWhoCanCheck $this->params->get('arrWhoCanCheck');
  340.         $isDirectoryProfileEditable $this->helper->whoCanCheck($arrWhoCanCheck'admin_directory_profile_edit');
  341.         $isDirectoryProfileDeletable $this->helper->whoCanCheck($arrWhoCanCheck'admin_directory_profile_delete');
  342.         $isDirectoryProfileApproved $this->helper->whoCanCheck($arrWhoCanCheck'admin_directory_profile_permission');
  343.         $isApprovable $this->helper->whoCanCheck($arrWhoCanCheck'admin_education_approve_reject');
  344.         // Get filter parameters
  345.         $req $request->query->all();
  346.         $search = isset($req['search']['value']) ? $req['search']['value'] : '';
  347.         $order = isset($req['order'][0]['dir']) ? $req['order'][0]['dir'] : 'asc';
  348.         $column = isset($req['order'][0]['column']) ? $req['order'][0]['column'] : 0;
  349.         $orderby = ['id''type''business_name''address''email''phone''photo''created_on'];
  350.         $directoryProfileQueryBuilder $this->directoryProfileRepository->createQueryBuilder('rc');
  351.         $subqueryBuilder = clone $directoryProfileQueryBuilder;
  352.         $subquery $subqueryBuilder
  353.             ->select('rc.id')
  354.             ->where('rc.deleted_at IS NULL')
  355.             ->andWhere('rc.is_approved = :isApproved')
  356.             ->setParameter('isApproved''pending')
  357.             ->setFirstResult(0)
  358.             ->setMaxResults(5)
  359.             ->getQuery()
  360.             ->getResult();
  361.         // dd($subquery);
  362.         // ->where('rc.deleted_at IS NULL')
  363.         // ->andWhere('rc.is_approved = :isApproved')
  364.         // ->setParameter('isApproved', 'pending')
  365.         // ->orderBy('rc.created_on', 'DESC')
  366.         // ->setFirstResult(0)
  367.         // ->setMaxResults(5)
  368.         // ->getQuery()
  369.         // ->getResult();
  370.         $recordIds array_column($subquery'id');
  371.         $query $directoryProfileQueryBuilder
  372.             ->where('rc.id IN (:recordIds)')
  373.             ->setParameter('recordIds'$recordIds)
  374.             ->orderBy('rc.' $orderby[$column], $order)
  375.             ->getQuery()
  376.             ->getResult();
  377.         $data = [];
  378.         foreach ($query as $key => $value) {
  379.             $isPublished '';
  380.             $isApprovable '';
  381.             $directoryProfileAction '';
  382.             $routePrefix $this->params->get('routePrefix');
  383.             $PublishData = [
  384.                 'editable' => $isDirectoryProfileEditable true false,
  385.                 'id' => $value->getId(),
  386.                 'published' => $value->getIsPublished() ? 'published' '',
  387.             ];
  388.             $availableActions = [];
  389.             $isPublished $this->renderView('components/toggleButton.html.twig', [
  390.                 'PublishData' => $PublishData,
  391.                 'id' => $value->getId(),
  392.                 'published' => $value->getIsPublished() ? 'true' '',
  393.             ]);
  394.             $isApprovable = [
  395.                 'editable' => $isDirectoryProfileApproved true false,
  396.                 'id' => $value->getId(),
  397.                 'active' => $value->getIsActive() ? '1' '',
  398.             ];
  399.             $isDirectoryProfileApproved $this->renderView('components/toggleButton.html.twig', [
  400.                 'isApprove' => $isApprovable,
  401.                 'id' => $value->getId(),
  402.                 'active' => $value->getIsActive() ? 'true' '',
  403.             ]);
  404.             if ($isDirectoryProfileEditable) {
  405.                 $availableActions['edit'] = [
  406.                     'route' => $this->generateUrl($this->params->get('routePrefix') . '_directory_profile_edit', ['id' => $value->getId()]),
  407.                 ];
  408.             }
  409.             if ($isDirectoryProfileDeletable) {
  410.                 $availableActions['delete'] = [
  411.                     'id' => $value->getId(),
  412.                     'published' => $value->getIsPublished(),
  413.                 ];
  414.             }
  415.             //if active inactive set data for popup
  416.             if ($isApprovable) {
  417.                 $availableActions['approve'] = [
  418.                     'id' => $value->getId(),
  419.                     'status' => $value->getIsApproved(),
  420.                 ];
  421.             }
  422.             $directoryProfileAction $this->renderView('components/actions.html.twig', [
  423.                 'availableActions' => $availableActions,
  424.             ]);
  425.             $classRow $value->getIsActive() ? "" "row_inactive";
  426.             $createdDate $value->getCreatedOn()->format('M d, Y');
  427.             $title $value->gettype();
  428.             if (!empty($value->getCoverPicture())) {
  429.                 $image '<div class="admin-banner"><img src="/directory_profile_photos/cover_photos/' $value->getCoverPicture() . '" height="50px" width="50px" alt=""/></div>';
  430.             } else {
  431.                 $image $value->getCoverPicture();
  432.             }
  433.             $approvalDropDown '<div class="d-flex justify-content-center"><select id="dropdownForDirectoryProfile" name="selectedOption" class="approve_action form-control custom-dd mb-4" data-id="' $value->getId() . '">
  434.                                 <option value="pending" disabled  ' . ($value->getIsApproved() === "pending" 'selected' '') . '>Pending</option>
  435.                                 <option value="approved" data-approve="approved" ' . ($value->getIsApproved() === "approved" 'selected' '') . '>Approved</option>
  436.                                 <option value="rejected" data-approve="rejected" ' . ($value->getIsApproved() === "rejected" 'selected' '') . '>Rejected</option>
  437.                                 </select></div>';
  438.             $typeName $this->directoryProfileCategoriesRepository->findOneBy(['type' => $title]);
  439.             $data[] = [
  440.                 $value->getId(),
  441.                 $directoryProfileAction,
  442.                 $typeName->getTitle(),
  443.                 $this->helper->formatFullName($value->getBusinessName()),
  444.                 ucfirst($value->getAddress()),
  445.                 $value->getEmail(),
  446.                 $value->getPhone(),
  447.                 $image,
  448.                 $createdDate,
  449.                 $approvalDropDown,
  450.                 $isDirectoryProfileApproved,
  451.                 $isPublished,
  452.             ];
  453.         }
  454.         $json_data = array(
  455.             "draw" => intval($request->query->get('draw')),
  456.             "data" => $data,
  457.         );
  458.         return new JsonResponse($json_data);
  459.     }
  460.     #[Route('/dashboard-educations-list'name'dashboard_education_listing')]
  461.     public function getDashboardEducationList(Request $request): Response
  462.     {
  463.         // To check user permission for edit , delete or approve actions
  464.         $arrWhoCanCheck $this->params->get('arrWhoCanCheck');
  465.         $isEditable $this->helper->whoCanCheck($arrWhoCanCheck'admin_education_edit');
  466.         $isDeletable $this->helper->whoCanCheck($arrWhoCanCheck'admin_education_delete');
  467.         $isApprovable $this->helper->whoCanCheck($arrWhoCanCheck'admin_education_approve_reject');
  468.         // set all request param to a variable
  469.         $req $request->query->all();
  470.         $start 0;
  471.         $length 5;
  472.         $order = isset($req['order'][0]['dir']) ? $req['order'][0]['dir'] : 'asc';
  473.         $column = isset($req['order'][0]['column']) ? $req['order'][0]['column'] : 0;
  474.         $orderby = ['id''''title''education_type_id''''''upload_date''is_approved''''''created_on'];
  475.         // call repository function to get all non deleted and active education count
  476.         $total $this->educationRepository->findTotalActiveCount();
  477.         // query builder to get data
  478.         $queryBuilder $this->educationRepository->createQueryBuilder('e');
  479.         $subqueryBuilder = clone $queryBuilder;
  480.         $subquery $subqueryBuilder
  481.             ->select('e.id'// Select only the IDs to avoid unnecessary data retrieval
  482.             ->where('e.deleted_at IS NULL')
  483.             ->andWhere('e.is_approved = :status')
  484.             ->setParameter('status''pending')
  485.             ->setMaxResults(5)
  486.             ->getQuery()
  487.             ->getResult();
  488.         $recordIds array_column($subquery'id');
  489.         $query $queryBuilder
  490.             ->where('e.id IN (:recordIds)')
  491.             ->setParameter('recordIds'$recordIds)
  492.             ->orderBy('e.' $orderby[$column], $order)
  493.             ->getQuery()
  494.             ->getResult();
  495.         //             ->where('e.deleted_at IS NULL')
  496.         //             ->andWhere('e.is_approved =:status')->setParameter('status', 'pending')
  497.         //             ->setFirstResult(0)
  498.         //             ->setMaxResults(5);
  499.         //
  500.         //         // order by query
  501.         //         $query = $queryBuilder->orderBy('e.' . $orderby[$column], $order)
  502.         //
  503.         //             ->getQuery()
  504.         //             ->getResult();
  505.         $data = [];
  506.         // loop the result data
  507.         foreach ($query as $key => $value) {
  508.             $isPublished '';
  509.             $action '';
  510.             $routePrefix $this->params->get('routePrefix');
  511.             // set status data array
  512.             $statusData = [
  513.                 'editable' => $isEditable true false,
  514.                 'id' => $value->getId(),
  515.                 'active' => $value->isIsActive() ? 'active' '',
  516.             ];
  517.             // render view for active inactive toggle
  518.             $isActive $this->renderView('components/toggleButton.html.twig', [
  519.                 'statusData' => $statusData,
  520.             ]);
  521.             // render view for premium toggle
  522.             $isPremium $this->renderView('components/isPremiumBadge.html.twig', [
  523.                 'active' => $value->isIsPremium(),
  524.             ]);
  525.             // set data array for premium
  526.             $publishData = [
  527.                 'editable' => $isEditable true false,
  528.                 'id' => $value->getId(),
  529.                 'published' => $value->isIsPremium() ? 'premium' '',
  530.             ];
  531.             $availableActions = [];
  532.             // set data for toggle button
  533.             $isPublished $this->renderView('components/toggleButton.html.twig', [
  534.                 'PublishData' => $publishData,
  535.             ]);
  536.             // if is editable generate url for edit action
  537.             if ($isEditable) {
  538.                 $availableActions['edit'] = [
  539.                     'route' => $this->generateUrl($this->params->get('routePrefix') . '_education_edit', ['id' => $value->getId()]),
  540.                 ];
  541.             }
  542.             // if is deletable set data for popup
  543.             if ($isDeletable) {
  544.                 $availableActions['delete'] = [
  545.                     'id' => $value->getId(),
  546.                     'premium' => $value->isIsPremium(),
  547.                     'status' => $value->isIsActive(),
  548.                 ];
  549.             }
  550.             //if active inactive set data for popup
  551.             if ($isApprovable) {
  552.                 $availableActions['approve'] = [
  553.                     'id' => $value->getId(),
  554.                     'status' => $value->getIsApproved(),
  555.                 ];
  556.             }
  557.             // load available action to action twig
  558.             $action $this->renderView('components/actions.html.twig', [
  559.                 'availableActions' => $availableActions,
  560.             ]);
  561.             // if image is uploaded
  562.             if ($value->getImage()) {
  563.                 $getImage '/educations/images/' $value->getImage();
  564.                 $image '<img src="' $getImage '" class="img-responsive" weight="50px" height="50px">';
  565.             } else {
  566.                 // load placeholder image
  567.                 $image '<img src="placeholder.webp" class="img-responsive" weight="50px" height="50px">';
  568.             }
  569.             //format dates
  570.             $createdDate $value->getCreatedOn()->format('M d, Y');
  571.             $uploadDate $value->getUploadDate()->format('M d, Y');
  572.             // explode the category id's
  573.             $categoryIds explode(','$value->getCategories());
  574.             $type $this->educationTypeRepository->find($value->getEducationTypeId());
  575.             $categories '';
  576.             $count 1;
  577.             foreach ($categoryIds as $ids) {
  578.                 if (count($categoryIds) > $count) {
  579.                     $categories .= $value->getNameById($ids$this->educationCategoryRepository) . ', ';
  580.                 } else {
  581.                     $categories .= $value->getNameById($ids$this->educationCategoryRepository);
  582.                 }
  583.                 $count++;
  584.             }
  585.             // badge if education is premium
  586.             $isPremiumBadge $this->renderView('components/isPremiumBadge.html.twig', [
  587.                 'active' => $value->isIsPremium(),
  588.             ]);
  589.             //dropdown for education approve reject
  590.             $approvalDropDown '<div class="d-flex justify-content-center"><select id="dropdownForEducation" name="selectedOption" class="form-control custom-dd mb-4" data-id="' $value->getId() . '">
  591.             <option value="pending" disabled  ' . ($value->getIsApproved() === "pending" 'selected' '') . '>Pending</option>
  592.             <option value="approved" data-approve="approved" ' . ($value->getIsApproved() === "approved" 'selected' '') . '>Approved</option>
  593.             <option value="rejected" data-approve="rejected" ' . ($value->getIsApproved() === "rejected" 'selected' '') . '>Rejected</option>
  594.             </select></div>';
  595.             // push the data into array for response
  596.             $data[] = [$value->getId(), $action$isPremiumBadge $value->getTitle(), $type->getTitle(), $categories$image$uploadDate$approvalDropDown$isPublished$isActive$createdDate];
  597.         }
  598.         // build json array for response
  599.         $json_data = array(
  600.             "draw" => intval($request->query->get('draw')),
  601.             "data" => $data,
  602.         );
  603.         // return the json array to data table
  604.         return new JsonResponse($json_data);
  605.     }
  606.     #[Route('/dashboard-bar-chart'name'dashboard_premium_ads_chart')]
  607.     public function getTotalPremiumSubscriptionsPerMonth()
  608.     {
  609.         $months = [
  610.             'Jan' => 1,
  611.             'Feb' => 2,
  612.             'March' => 3,
  613.             'April' => 4,
  614.             'May' => 5,
  615.             'Jun' => 6,
  616.             'July' => 7,
  617.             'Aug' => 8,
  618.             'Sept' => 9,
  619.             'Oct' => 10,
  620.             'Nov' => 11,
  621.             'Dec' => 12,
  622.         ];
  623.         $premiumSubscriptions $this->subscriptionTransactionsRepository->getPremiumSubscriptionMonthlyDataForCurrentYear();
  624.         // Initialize the result array with 0 values for all months
  625.         $jsonData['months'] = array_keys($months);
  626.         $premiumResults array_fill_keys($months0);
  627.         $directoryProfileResult array_fill_keys($months0);
  628.         $privateCommunityResult array_fill_keys($months0);
  629.         foreach ($premiumSubscriptions as $value) {
  630.             $premiumResults[$value['month']] = $value['total'];
  631.         }
  632.         $jsonData['premiums'] = array_values($premiumResults);
  633.         $directoryProfileSubscriptions $this->subscriptionTransactionsRepository->getDirectoryProfileSubscriptionMonthlyDataForCurrentYear();
  634.         foreach ($directoryProfileSubscriptions as $value) {
  635.             $directoryProfileResult[$value['month']] = $value['total'];
  636.         }
  637.         $jsonData['directoryProfiles'] = array_values($directoryProfileResult);
  638.         //private community
  639.         $privateCommunitySubscriptions $this->subscriptionTransactionsRepository->getPrivateCommunitySubscriptionMonthlyDataForCurrentYear();
  640.         foreach ($privateCommunitySubscriptions as $value) {
  641.             $privateCommunityResult[$value['month']] = $value['total'];
  642.         }
  643.         $jsonData['privateCommunity'] = array_values($privateCommunityResult);
  644.         //supplier
  645.         $supplierListSubscriptions $this->subscriptionTransactionsRepository->getSuppliersSubscriptionMonthlyDataForCurrentYear();
  646.         foreach ($supplierListSubscriptions as $value) {
  647.             $directoryProfileResult[$value['month']] = $value['total'];
  648.         }
  649.         $jsonData['supplierList'] = array_values($directoryProfileResult);
  650.         //purchasing group
  651.         $purchasingGroupsSubscriptions $this->subscriptionTransactionsRepository->getPurchasingGroupSubscriptionMonthlyDataForCurrentYear();
  652.         foreach ($purchasingGroupsSubscriptions as $value) {
  653.             $directoryProfileResult[$value['month']] = $value['total'];
  654.         }
  655.         $jsonData['purchasingGroups'] = array_values($directoryProfileResult);
  656.         return new JsonResponse([
  657.             'status' => 'success',
  658.             'statusCode' => '200',
  659.             'message' => 'success',
  660.             'data' => $jsonData,
  661.         ], 200);
  662.     }
  663.     #[Route('/dashboard-pie-chart'name'dashboard_premium_ads_revenue_chart')]
  664.     public function totalSubscriptionsRevenue()
  665.     {
  666.         $premiumSubscriptionsRevenue $this->subscriptionTransactionsRepository->getPremiumSubscriptionMonthlyRevenueDataForCurrentYear();
  667.         $directoryProfilesSubscriptionsRevenue $this->subscriptionTransactionsRepository->getDirectoryProfilesSubscriptionsMonthlyRevenueDataForCurrentYear();
  668.         $privateCommunitySubscriptionsRevenue $this->subscriptionTransactionsRepository->getPrivateCommunitySubscriptionsMonthlyRevenueDataForCurrentYear();
  669.         $supplierListSubscriptionsRevenue $this->subscriptionTransactionsRepository->getSupplierSubscriptionsMonthlyRevenueDataForCurrentYear();
  670.         $purchasingGroupsSubscriptionsRevenue $this->subscriptionTransactionsRepository->getPurchasingGroupSubscriptionsMonthlyRevenueDataForCurrentYear();
  671.         $jsonData['premiumRevenue'] = $premiumSubscriptionsRevenue $premiumSubscriptionsRevenue 0.0;
  672.         $jsonData['directoryProfileRevenue'] = $directoryProfilesSubscriptionsRevenue $directoryProfilesSubscriptionsRevenue 0.0;
  673.         $jsonData['privateCommunityRevenue'] = $privateCommunitySubscriptionsRevenue $privateCommunitySubscriptionsRevenue 0.0;
  674.         $jsonData['supplierRevenue'] = $supplierListSubscriptionsRevenue $supplierListSubscriptionsRevenue 0.0;
  675.         $jsonData['purchasingGroupRevenue'] = $purchasingGroupsSubscriptionsRevenue $purchasingGroupsSubscriptionsRevenue 0.0;
  676.         return new JsonResponse([
  677.             'status' => 'success',
  678.             'statusCode' => '200',
  679.             'message' => 'success',
  680.             'data' => $jsonData,
  681.         ], 200);
  682.     }
  683.     #[Route('/dashboard-line-chart'name'dashboard_resource_published_unpublished_chart')]
  684.     public function resourcePublishedUnpublishedData()
  685.     {
  686.         $published $this->resourcesRepository->getPublishedResourcesMonthlyDataForCurrentYear();
  687.         $unpublished $this->resourcesRepository->getUnPublishedResourcesMonthlyDataForCurrentYear();
  688.         $months = [
  689.             'Jan' => 1,
  690.             'Feb' => 2,
  691.             'March' => 3,
  692.             'April' => 4,
  693.             'May' => 5,
  694.             'Jun' => 6,
  695.             'July' => 7,
  696.             'Aug' => 8,
  697.             'Sept' => 9,
  698.             'Oct' => 10,
  699.             'Nov' => 11,
  700.             'Dec' => 12,
  701.         ];
  702.         $published $this->resourcesRepository->getPublishedResourcesMonthlyDataForCurrentYear();
  703.         // Initialize the result array with 0 values for all months
  704.         $publishedResults array_fill_keys($months0);
  705.         $unpublishedResults array_fill_keys($months0);
  706.         foreach ($published as $value) {
  707.             $publishedResults[$value['month']] = $value['total'];
  708.         }
  709.         $jsonData['months'] = array_keys($months);
  710.         $jsonData['published'] = array_values($publishedResults);
  711.         $unpublished $this->resourcesRepository->getUnPublishedResourcesMonthlyDataForCurrentYear();
  712.         foreach ($unpublished as $value) {
  713.             $unpublishedResults[$value['month']] = $value['total'];
  714.         }
  715.         $jsonData['unpublished'] = array_values($unpublishedResults);
  716.         return new JsonResponse([
  717.             'status' => 'success',
  718.             'statusCode' => '200',
  719.             'message' => 'success',
  720.             'data' => $jsonData,
  721.         ], 200);
  722.     }
  723.     #[Route('/info'name'php_test_info')]
  724.     public function info()
  725.     {
  726.         phpinfo();
  727.         exit;
  728.     }
  729.     #[Route('/testUpload'name'test_upload')]
  730.     public function testUpload(Request $request)
  731.     {
  732.         return $this->render('test.html.twig', []);
  733.     }
  734.     #[Route('/s3upload'name'test_s3_upload')]
  735.     public function s3upload(Request $request)
  736.     {
  737.         $file $request->files->get('videoFile');
  738.         $url =  $this->imageService->uploadFileService('uploads'$file);
  739.         dd($url);
  740.         return new Response('No file provided'Response::HTTP_BAD_REQUEST);
  741.     }
  742.     /**
  743.      * @Route("/upload", name="upload_video", methods={"POST"})
  744.      */
  745.     #[Route('/s3uploadChunk'name'test_s3_upload_chunk')]
  746.     public function uploadVideo(Request $request): JsonResponse
  747.     {
  748.         $bucket 'gixli-live';
  749.         $chunkSize 1024 1024// 5 MB
  750.         $file $request->files->get('videoFile');
  751.         if (!$file) {
  752.             return new JsonResponse(['error' => 'No file uploaded'], 400);
  753.         }
  754.         $filePath $file->getRealPath();
  755.         $fileSize filesize($filePath);
  756.         $key 'uploads/' $file->getClientOriginalName();
  757.         $uploadId null;
  758.         try {
  759.             $multipartUploader $this->s3Client->createMultipartUpload([
  760.                 'Bucket' => $bucket,
  761.                 'Key' => $key,
  762.             ]);
  763.             $uploadId $multipartUploader['UploadId'];
  764.             $parts = [];
  765.             $fileHandle fopen($filePath'rb');
  766.             for ($i 1$i <= ceil($fileSize $chunkSize); $i++) {
  767.                 $chunk fread($fileHandle$chunkSize);
  768.                 $result $this->s3Client->uploadPart([
  769.                     'Bucket' => $bucket,
  770.                     'Key' => $key,
  771.                     'UploadId' => $uploadId,
  772.                     'PartNumber' => $i,
  773.                     'Body' => $chunk,
  774.                 ]);
  775.                 $parts[] = [
  776.                     'PartNumber' => $i,
  777.                     'ETag' => $result['ETag'],
  778.                 ];
  779.             }
  780.             fclose($fileHandle);
  781.             $res $this->s3Client->completeMultipartUpload([
  782.                 'Bucket' => $bucket,
  783.                 'Key' => $key,
  784.                 'UploadId' => $uploadId,
  785.                 'MultipartUpload' => ['Parts' => $parts],
  786.             ]);
  787.             return new JsonResponse(['message' => 'File uploaded successfully''data' => 'https://gixli-live.s3.amazonaws.com/' $key]);
  788.         } catch (\Exception $e) {
  789.             if ($uploadId) {
  790.                 $this->s3Client->abortMultipartUpload([
  791.                     'Bucket' => $bucket,
  792.                     'Key' => $key,
  793.                     'UploadId' => $uploadId,
  794.                 ]);
  795.             }
  796.             return new JsonResponse(['error' => 'File upload failed: ' $e->getMessage()], 500);
  797.         }
  798.     }
  799.     /**
  800.      * @Route("/info", name="info")
  801.      */
  802.     #[Route('/info'name'phpinfo')]
  803.     public function phpinfo(Request $request)
  804.     {
  805.         echo phpinfo();
  806.         exit;
  807.     }
  808.     #[Route('/test-mail'name'testMail')]
  809.     public function testMail(Request $request)
  810.     {
  811.         $data = [
  812.             'response' => 'Test mail..',
  813.         ];
  814.         $this->emailTemplates->sendMail('test'$data'kuldeepg.magneto@gmail.com');
  815.         $this->emailTemplates->sendMail('test'$data'colby@gixli.com');
  816.         $this->emailTemplates->sendMail('test'$data'hello@gixli.com');
  817.         $this->emailTemplates->sendMail('test'$data'gixli@gixli.com');
  818.         return new JsonResponse(['success' => 'Ok'], 200);
  819.     }
  820. }