<?php
namespace App\Controller;
use App\Entity\ArchitectDetails;
use App\Entity\ShowroomDetails;
use App\Form\ChangePasswordFormType;
use App\Form\CKEditorMessageType;
use App\Form\ProfileType;
use App\Repository\ContactPreferencesRepository;
use App\Repository\ContactUsRepository;
use App\Repository\DirectoryProfileCategoriesRepository;
use App\Repository\DirectoryProfileRepository;
use App\Repository\EducationCategoryRepository;
use App\Repository\EducationSponsorDetailsRepository;
use App\Repository\EducationsRepository;
use App\Repository\EducationTypeRepository;
use App\Repository\MemosRepository;
use App\Repository\PodcastRepository;
use App\Repository\PrivateCommunityRepository;
use App\Repository\ResourcesRepository;
use App\Repository\SubscriptionTransactionsRepository;
use App\Repository\UserRepository;
use App\Services\EmailTemplatesService;
use App\Services\ImageService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use App\Services\S3Service;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Aws\S3\S3Client;
class HomeController extends AbstractController
{
private $params;
private $translator;
private $userRepository;
private $helper;
private $contactUsRepository;
private $contactPreferenceRepository;
private $directoryProfileRepository;
private $directoryProfileCategoriesRepository;
private $educationRepository;
private $educationCategoryRepository;
private $educationTypeRepository;
private $educationSponsorDetailsRepository;
private $subscriptionTransactionsRepository;
private $resourcesRepository;
protected $entityManager;
protected $memosRepository;
protected $podcastRepository;
protected $privateCommunityRepository;
protected $imageService;
protected $emailTemplates;
private $s3Service;
private $s3Client;
public function __construct(
Environment $twig,
ParameterBagInterface $params,
TranslatorInterface $translator,
UserRepository $userRepository,
\App\Helper\helpers $helper,
ContactUsRepository $contactUsRepository,
ContactPreferencesRepository $contactPreferenceRepository,
DirectoryProfileRepository $directoryProfileRepository,
DirectoryProfileCategoriesRepository $directoryProfileCategoriesRepository,
EducationsRepository $educationRepository,
EducationTypeRepository $educationTypeRepository,
EducationCategoryRepository $educationCategoryRepository,
EducationSponsorDetailsRepository $educationSponsorDetailsRepository,
SubscriptionTransactionsRepository $subscriptionTransactionsRepository,
ResourcesRepository $resourcesRepository,
EntityManagerInterface $entityManager,
MemosRepository $memosRepository,
PodcastRepository $podcastRepository,
PrivateCommunityRepository $privateCommunityRepository,
EmailTemplatesService $emailTemplates,
ImageService $imageService,
S3Service $s3Service,
S3Client $s3Client
) {
// $this->loader = $twig->getLoader();
$this->translator = $translator;
$this->userRepository = $userRepository;
$this->helper = $helper;
$this->contactUsRepository = $contactUsRepository;
$this->contactPreferenceRepository = $contactPreferenceRepository;
$this->directoryProfileRepository = $directoryProfileRepository;
$this->directoryProfileCategoriesRepository = $directoryProfileCategoriesRepository;
$this->params = $params;
$this->educationRepository = $educationRepository;
$this->educationCategoryRepository = $educationCategoryRepository;
$this->educationTypeRepository = $educationTypeRepository;
$this->educationSponsorDetailsRepository = $educationSponsorDetailsRepository;
$this->subscriptionTransactionsRepository = $subscriptionTransactionsRepository;
$this->resourcesRepository = $resourcesRepository;
$this->entityManager = $entityManager;
$this->memosRepository = $memosRepository;
$this->podcastRepository = $podcastRepository;
$this->privateCommunityRepository = $privateCommunityRepository;
$this->emailTemplates = $emailTemplates;
$this->imageService = $imageService;
$this->s3Service = $s3Service;
$this->s3Client = $s3Client;
}
// #[Route('/', name: 'root')]
// public function home()
// {
// // Logic for the root path
// return $this->render('home.html.twig');
// }
#[Route('/dashboard', name: 'home')]
public function index(Request $request): Response
{
// Counter for Interior Designers
$interiorDesigners = $this->userRepository->createQueryBuilder('id')
->select('count(id.id) as total')
->andwhere('id.deleted_at IS NULL')
->andwhere('id.user_role_type = :user_role_type')
->setParameter('user_role_type', 'interior_designer')
->andwhere('id.status = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$interiorDesignersCount = $interiorDesigners['total'];
// Counter for Home Owners
$homeOwners = $this->userRepository->createQueryBuilder('ho')
->select('count(ho.id) as total')
->andwhere('ho.user_role_type = :user_role_type')
->andwhere('ho.deleted_at IS NULL')
->setParameter('user_role_type', 'home_owner')
->andwhere('ho.status = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$homeOwnerCount = $homeOwners['total'];
// Counter for Architects / Builders
$architects = $this->userRepository->createQueryBuilder('ar')
->select('count(ar.id) as total')
->Join(ArchitectDetails::class, 'ad', 'WITH', 'ar.id = ad.user_id')
->andwhere('ad.deleted_at IS NULL')
->andwhere('ar.deleted_at IS NULL')
->andwhere('ar.user_role_type = :user_role_type')
->setParameter('user_role_type', 'architect')
->andwhere('ar.status = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$architectCount = $architects['total'];
// Counter for Showrooms
$showrooms = $this->userRepository->createQueryBuilder('sr')
->select('count(sr.id) as total')
->Join(ShowroomDetails::class, 'sd', 'WITH', 'sr.id = sd.user')
->andWhere('sd.deleted_at IS NULL')
->andWhere('sr.user_role_type = :user_role_type')
->andWhere('sr.deleted_at IS NULL')
->setParameter('user_role_type', 'showroom')
->andwhere('sr.status = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$showroomCount = $showrooms['total'];
// counter for memos
$memos = $this->memosRepository->createQueryBuilder('mr')
->select('count(mr.id) as total')
->where('mr.deleted_at IS NULL')
->andwhere('mr.is_active = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$memoCount = $memos['total'];
// counter for Podcasts
$Podcasts = $this->podcastRepository->createQueryBuilder('pr')
->select('count(pr.id) as total')
->where('pr.deleted_at IS NULL')
->andwhere('pr.is_active = :status')
->setParameter('status', '1')
->getQuery()
->getOneOrNullResult();
$podcastCount = $Podcasts['total'];
// counter for directoryProfiles
$directoryProfiles = $this->directoryProfileRepository->createQueryBuilder('dpr')
->select('count(dpr.id) as total')
->where('dpr.deleted_at IS NULL')
->andWhere('dpr.is_approved = :is_approved')
->setParameter('is_approved', 'approved')
->andWhere('dpr.is_active = :is_active')
->setParameter('is_active', '1')
->getQuery()
->getOneOrNullResult();
$directoryProfilesCount = $directoryProfiles['total'];
// counter for privateCommunityUsers
$privateCommunityUsers = $this->privateCommunityRepository->createQueryBuilder('pcr')
->select('count(pcr.id) as total')
->where('pcr.deleted_at IS NULL')
->andWhere('pcr.is_approved = :is_approved')
->setParameter('is_approved', 'approved')
->andWhere('pcr.is_active = :is_active')
->setParameter('is_active', '1')
->getQuery()
->getOneOrNullResult();
$privateCommunityUsersCount = $privateCommunityUsers['total'];
$baseUrl = $request->getSchemeAndHttpHost();
return $this->render(
'index.html.twig',
[
'interiorDesignersCount' => $interiorDesignersCount,
'homeOwnerCount' => $homeOwnerCount,
'architectCount' => $architectCount,
'showroomCount' => $showroomCount,
'memoCount' => $memoCount,
'podcastCount' => $podcastCount,
'directoryProfilesCount' => $directoryProfilesCount,
'privateCommunityUsersCount' => $privateCommunityUsersCount,
'baseUrl' => $baseUrl,
]
);
}
#[Route('/myProfile', name: 'myProfile')]
public function myfrofile(Request $request, Security $security, UserRepository $userRepository, EntityManagerInterface $em): Response
{
$email = $security->getUser()->getId();
$user = $userRepository->find($email);
$user->setEmail($user->getEmail());
$form = $this->createForm(ProfileType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user->setFirstName($this->helper->formatFullName($user->getFirstName()));
$user->setLastName($this->helper->formatFullName($user->getLastName()));
$user->setPhone($user->getPhone());
$user->setEmail($user->getEmail());
$this->addFlash('success', 'User Updated Successfully');
$em->persist($user);
$em->flush();
return $this->redirectToRoute('myProfile');
}
return $this->render(
'user/profile.html.twig',
[
'form' => $form->createView(),
]
);
}
#[Route('/changePassword', name: 'changePassword')]
public function changePassword(Request $request, UserPasswordHasherInterface $passwordHasher, TranslatorInterface $translators, EntityManagerInterface $entityManager, Security $security, UserRepository $userRepository): Response
{
// The token is valid; allow the user to change their password.
$form = $this->createForm(ChangePasswordFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$email = $security->getUser()->getUserIdentifier();
$user = $userRepository->findOneBy(['email' => $email]);
$encodedPassword = $passwordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
);
$user->setPassword($encodedPassword);
$entityManager->flush();
$this->addFlash('success', $this->translator->trans('message.modules.success.pwd_reset'));
return $this->redirectToRoute('changePassword');
}
return $this->render('user/changePass.html.twig', [
'resetForm' => $form->createView(),
]);
}
#[Route('/dashboard-contact-us', name: 'dashboard_contact_us_list')]
public function getContactUsData(Request $request)
{
$arrWhoCanCheck = $this->params->get('arrWhoCanCheck');
$isRepliable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_contact_us_reply');
$isDeletable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_contact_us_delete');
$length = 5;
$queryBuilder = $this->contactUsRepository->createQueryBuilder('c')
->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')
->where('c.deleted_at IS NULL')
->orderBy('c.updated_at', 'DESC')->setFirstResult(0)->setMaxResults($length);
$contactUsData = $queryBuilder->getQuery()->getResult();
$data = [];
$form = $this->createForm(CKEditorMessageType::class);
$form->handleRequest($request);
$renderedTemplate = $this->renderView('contact_us/ckeditor.html.twig', [
'form' => $form->createView(),
]);
foreach ($contactUsData as $value) {
$action = '';
$availableActions = [];
if ($value['is_replied'] == 1) {
if ($isRepliable) {
$availableActions['replyView'] = [
'id' => $value['id'],
];
}
} else {
if ($isRepliable) {
$availableActions['reply'] = [
'id' => $value['id'],
];
}
}
if ($isDeletable) {
$availableActions['delete'] = [
'id' => $value['id'],
];
}
$action = $this->renderView('components/actions.html.twig', [
'availableActions' => $availableActions,
]);
$preferenceName = null;
$preferenceValue = $this->contactPreferenceRepository->find($value['preferences']);
if ($preferenceValue !== null) {
$preferenceName = $preferenceValue->getName();
}
$data[] = [
$value['id'],
$action,
$this->helper->formatFullName($value['first_name']),
$this->helper->formatFullName($value['last_name']),
$preferenceName,
$value['email'],
$value['phone'],
$value['created_at']->format('M d, Y'),
];
}
$json_data = array(
"draw" => intval($request->query->get('draw')),
"data" => $data,
"renderTemplate" => $renderedTemplate,
);
return new JsonResponse($json_data);
}
#[Route('/dashboard-directory-profiles', name: 'dashboard_directory_profile_list')]
public function getDirectoryProfileList(Request $request)
{
$arrWhoCanCheck = $this->params->get('arrWhoCanCheck');
$isDirectoryProfileEditable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_directory_profile_edit');
$isDirectoryProfileDeletable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_directory_profile_delete');
$isDirectoryProfileApproved = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_directory_profile_permission');
$isApprovable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_education_approve_reject');
// Get filter parameters
$req = $request->query->all();
$search = isset($req['search']['value']) ? $req['search']['value'] : '';
$order = isset($req['order'][0]['dir']) ? $req['order'][0]['dir'] : 'asc';
$column = isset($req['order'][0]['column']) ? $req['order'][0]['column'] : 0;
$orderby = ['id', 'type', 'business_name', 'address', 'email', 'phone', 'photo', 'created_on'];
$directoryProfileQueryBuilder = $this->directoryProfileRepository->createQueryBuilder('rc');
$subqueryBuilder = clone $directoryProfileQueryBuilder;
$subquery = $subqueryBuilder
->select('rc.id')
->where('rc.deleted_at IS NULL')
->andWhere('rc.is_approved = :isApproved')
->setParameter('isApproved', 'pending')
->setFirstResult(0)
->setMaxResults(5)
->getQuery()
->getResult();
// dd($subquery);
// ->where('rc.deleted_at IS NULL')
// ->andWhere('rc.is_approved = :isApproved')
// ->setParameter('isApproved', 'pending')
// ->orderBy('rc.created_on', 'DESC')
// ->setFirstResult(0)
// ->setMaxResults(5)
// ->getQuery()
// ->getResult();
$recordIds = array_column($subquery, 'id');
$query = $directoryProfileQueryBuilder
->where('rc.id IN (:recordIds)')
->setParameter('recordIds', $recordIds)
->orderBy('rc.' . $orderby[$column], $order)
->getQuery()
->getResult();
$data = [];
foreach ($query as $key => $value) {
$isPublished = '';
$isApprovable = '';
$directoryProfileAction = '';
$routePrefix = $this->params->get('routePrefix');
$PublishData = [
'editable' => $isDirectoryProfileEditable ? true : false,
'id' => $value->getId(),
'published' => $value->getIsPublished() ? 'published' : '',
];
$availableActions = [];
$isPublished = $this->renderView('components/toggleButton.html.twig', [
'PublishData' => $PublishData,
'id' => $value->getId(),
'published' => $value->getIsPublished() ? 'true' : '',
]);
$isApprovable = [
'editable' => $isDirectoryProfileApproved ? true : false,
'id' => $value->getId(),
'active' => $value->getIsActive() ? '1' : '',
];
$isDirectoryProfileApproved = $this->renderView('components/toggleButton.html.twig', [
'isApprove' => $isApprovable,
'id' => $value->getId(),
'active' => $value->getIsActive() ? 'true' : '',
]);
if ($isDirectoryProfileEditable) {
$availableActions['edit'] = [
'route' => $this->generateUrl($this->params->get('routePrefix') . '_directory_profile_edit', ['id' => $value->getId()]),
];
}
if ($isDirectoryProfileDeletable) {
$availableActions['delete'] = [
'id' => $value->getId(),
'published' => $value->getIsPublished(),
];
}
//if active inactive set data for popup
if ($isApprovable) {
$availableActions['approve'] = [
'id' => $value->getId(),
'status' => $value->getIsApproved(),
];
}
$directoryProfileAction = $this->renderView('components/actions.html.twig', [
'availableActions' => $availableActions,
]);
$classRow = $value->getIsActive() ? "" : "row_inactive";
$createdDate = $value->getCreatedOn()->format('M d, Y');
$title = $value->gettype();
if (!empty($value->getCoverPicture())) {
$image = '<div class="admin-banner"><img src="/directory_profile_photos/cover_photos/' . $value->getCoverPicture() . '" height="50px" width="50px" alt=""/></div>';
} else {
$image = $value->getCoverPicture();
}
$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() . '">
<option value="pending" disabled ' . ($value->getIsApproved() === "pending" ? 'selected' : '') . '>Pending</option>
<option value="approved" data-approve="approved" ' . ($value->getIsApproved() === "approved" ? 'selected' : '') . '>Approved</option>
<option value="rejected" data-approve="rejected" ' . ($value->getIsApproved() === "rejected" ? 'selected' : '') . '>Rejected</option>
</select></div>';
$typeName = $this->directoryProfileCategoriesRepository->findOneBy(['type' => $title]);
$data[] = [
$value->getId(),
$directoryProfileAction,
$typeName->getTitle(),
$this->helper->formatFullName($value->getBusinessName()),
ucfirst($value->getAddress()),
$value->getEmail(),
$value->getPhone(),
$image,
$createdDate,
$approvalDropDown,
$isDirectoryProfileApproved,
$isPublished,
];
}
$json_data = array(
"draw" => intval($request->query->get('draw')),
"data" => $data,
);
return new JsonResponse($json_data);
}
#[Route('/dashboard-educations-list', name: 'dashboard_education_listing')]
public function getDashboardEducationList(Request $request): Response
{
// To check user permission for edit , delete or approve actions
$arrWhoCanCheck = $this->params->get('arrWhoCanCheck');
$isEditable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_education_edit');
$isDeletable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_education_delete');
$isApprovable = $this->helper->whoCanCheck($arrWhoCanCheck, 'admin_education_approve_reject');
// set all request param to a variable
$req = $request->query->all();
$start = 0;
$length = 5;
$order = isset($req['order'][0]['dir']) ? $req['order'][0]['dir'] : 'asc';
$column = isset($req['order'][0]['column']) ? $req['order'][0]['column'] : 0;
$orderby = ['id', '', 'title', 'education_type_id', '', '', 'upload_date', 'is_approved', '', '', 'created_on'];
// call repository function to get all non deleted and active education count
$total = $this->educationRepository->findTotalActiveCount();
// query builder to get data
$queryBuilder = $this->educationRepository->createQueryBuilder('e');
$subqueryBuilder = clone $queryBuilder;
$subquery = $subqueryBuilder
->select('e.id') // Select only the IDs to avoid unnecessary data retrieval
->where('e.deleted_at IS NULL')
->andWhere('e.is_approved = :status')
->setParameter('status', 'pending')
->setMaxResults(5)
->getQuery()
->getResult();
$recordIds = array_column($subquery, 'id');
$query = $queryBuilder
->where('e.id IN (:recordIds)')
->setParameter('recordIds', $recordIds)
->orderBy('e.' . $orderby[$column], $order)
->getQuery()
->getResult();
// ->where('e.deleted_at IS NULL')
// ->andWhere('e.is_approved =:status')->setParameter('status', 'pending')
// ->setFirstResult(0)
// ->setMaxResults(5);
//
// // order by query
// $query = $queryBuilder->orderBy('e.' . $orderby[$column], $order)
//
// ->getQuery()
// ->getResult();
$data = [];
// loop the result data
foreach ($query as $key => $value) {
$isPublished = '';
$action = '';
$routePrefix = $this->params->get('routePrefix');
// set status data array
$statusData = [
'editable' => $isEditable ? true : false,
'id' => $value->getId(),
'active' => $value->isIsActive() ? 'active' : '',
];
// render view for active inactive toggle
$isActive = $this->renderView('components/toggleButton.html.twig', [
'statusData' => $statusData,
]);
// render view for premium toggle
$isPremium = $this->renderView('components/isPremiumBadge.html.twig', [
'active' => $value->isIsPremium(),
]);
// set data array for premium
$publishData = [
'editable' => $isEditable ? true : false,
'id' => $value->getId(),
'published' => $value->isIsPremium() ? 'premium' : '',
];
$availableActions = [];
// set data for toggle button
$isPublished = $this->renderView('components/toggleButton.html.twig', [
'PublishData' => $publishData,
]);
// if is editable generate url for edit action
if ($isEditable) {
$availableActions['edit'] = [
'route' => $this->generateUrl($this->params->get('routePrefix') . '_education_edit', ['id' => $value->getId()]),
];
}
// if is deletable set data for popup
if ($isDeletable) {
$availableActions['delete'] = [
'id' => $value->getId(),
'premium' => $value->isIsPremium(),
'status' => $value->isIsActive(),
];
}
//if active inactive set data for popup
if ($isApprovable) {
$availableActions['approve'] = [
'id' => $value->getId(),
'status' => $value->getIsApproved(),
];
}
// load available action to action twig
$action = $this->renderView('components/actions.html.twig', [
'availableActions' => $availableActions,
]);
// if image is uploaded
if ($value->getImage()) {
$getImage = '/educations/images/' . $value->getImage();
$image = '<img src="' . $getImage . '" class="img-responsive" weight="50px" height="50px">';
} else {
// load placeholder image
$image = '<img src="placeholder.webp" class="img-responsive" weight="50px" height="50px">';
}
//format dates
$createdDate = $value->getCreatedOn()->format('M d, Y');
$uploadDate = $value->getUploadDate()->format('M d, Y');
// explode the category id's
$categoryIds = explode(',', $value->getCategories());
$type = $this->educationTypeRepository->find($value->getEducationTypeId());
$categories = '';
$count = 1;
foreach ($categoryIds as $ids) {
if (count($categoryIds) > $count) {
$categories .= $value->getNameById($ids, $this->educationCategoryRepository) . ', ';
} else {
$categories .= $value->getNameById($ids, $this->educationCategoryRepository);
}
$count++;
}
// badge if education is premium
$isPremiumBadge = $this->renderView('components/isPremiumBadge.html.twig', [
'active' => $value->isIsPremium(),
]);
//dropdown for education approve reject
$approvalDropDown = '<div class="d-flex justify-content-center"><select id="dropdownForEducation" name="selectedOption" class="form-control custom-dd mb-4" data-id="' . $value->getId() . '">
<option value="pending" disabled ' . ($value->getIsApproved() === "pending" ? 'selected' : '') . '>Pending</option>
<option value="approved" data-approve="approved" ' . ($value->getIsApproved() === "approved" ? 'selected' : '') . '>Approved</option>
<option value="rejected" data-approve="rejected" ' . ($value->getIsApproved() === "rejected" ? 'selected' : '') . '>Rejected</option>
</select></div>';
// push the data into array for response
$data[] = [$value->getId(), $action, $isPremiumBadge . $value->getTitle(), $type->getTitle(), $categories, $image, $uploadDate, $approvalDropDown, $isPublished, $isActive, $createdDate];
}
// build json array for response
$json_data = array(
"draw" => intval($request->query->get('draw')),
"data" => $data,
);
// return the json array to data table
return new JsonResponse($json_data);
}
#[Route('/dashboard-bar-chart', name: 'dashboard_premium_ads_chart')]
public function getTotalPremiumSubscriptionsPerMonth()
{
$months = [
'Jan' => 1,
'Feb' => 2,
'March' => 3,
'April' => 4,
'May' => 5,
'Jun' => 6,
'July' => 7,
'Aug' => 8,
'Sept' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
];
$premiumSubscriptions = $this->subscriptionTransactionsRepository->getPremiumSubscriptionMonthlyDataForCurrentYear();
// Initialize the result array with 0 values for all months
$jsonData['months'] = array_keys($months);
$premiumResults = array_fill_keys($months, 0);
$directoryProfileResult = array_fill_keys($months, 0);
$privateCommunityResult = array_fill_keys($months, 0);
foreach ($premiumSubscriptions as $value) {
$premiumResults[$value['month']] = $value['total'];
}
$jsonData['premiums'] = array_values($premiumResults);
$directoryProfileSubscriptions = $this->subscriptionTransactionsRepository->getDirectoryProfileSubscriptionMonthlyDataForCurrentYear();
foreach ($directoryProfileSubscriptions as $value) {
$directoryProfileResult[$value['month']] = $value['total'];
}
$jsonData['directoryProfiles'] = array_values($directoryProfileResult);
//private community
$privateCommunitySubscriptions = $this->subscriptionTransactionsRepository->getPrivateCommunitySubscriptionMonthlyDataForCurrentYear();
foreach ($privateCommunitySubscriptions as $value) {
$privateCommunityResult[$value['month']] = $value['total'];
}
$jsonData['privateCommunity'] = array_values($privateCommunityResult);
//supplier
$supplierListSubscriptions = $this->subscriptionTransactionsRepository->getSuppliersSubscriptionMonthlyDataForCurrentYear();
foreach ($supplierListSubscriptions as $value) {
$directoryProfileResult[$value['month']] = $value['total'];
}
$jsonData['supplierList'] = array_values($directoryProfileResult);
//purchasing group
$purchasingGroupsSubscriptions = $this->subscriptionTransactionsRepository->getPurchasingGroupSubscriptionMonthlyDataForCurrentYear();
foreach ($purchasingGroupsSubscriptions as $value) {
$directoryProfileResult[$value['month']] = $value['total'];
}
$jsonData['purchasingGroups'] = array_values($directoryProfileResult);
return new JsonResponse([
'status' => 'success',
'statusCode' => '200',
'message' => 'success',
'data' => $jsonData,
], 200);
}
#[Route('/dashboard-pie-chart', name: 'dashboard_premium_ads_revenue_chart')]
public function totalSubscriptionsRevenue()
{
$premiumSubscriptionsRevenue = $this->subscriptionTransactionsRepository->getPremiumSubscriptionMonthlyRevenueDataForCurrentYear();
$directoryProfilesSubscriptionsRevenue = $this->subscriptionTransactionsRepository->getDirectoryProfilesSubscriptionsMonthlyRevenueDataForCurrentYear();
$privateCommunitySubscriptionsRevenue = $this->subscriptionTransactionsRepository->getPrivateCommunitySubscriptionsMonthlyRevenueDataForCurrentYear();
$supplierListSubscriptionsRevenue = $this->subscriptionTransactionsRepository->getSupplierSubscriptionsMonthlyRevenueDataForCurrentYear();
$purchasingGroupsSubscriptionsRevenue = $this->subscriptionTransactionsRepository->getPurchasingGroupSubscriptionsMonthlyRevenueDataForCurrentYear();
$jsonData['premiumRevenue'] = $premiumSubscriptionsRevenue ? $premiumSubscriptionsRevenue : 0.0;
$jsonData['directoryProfileRevenue'] = $directoryProfilesSubscriptionsRevenue ? $directoryProfilesSubscriptionsRevenue : 0.0;
$jsonData['privateCommunityRevenue'] = $privateCommunitySubscriptionsRevenue ? $privateCommunitySubscriptionsRevenue : 0.0;
$jsonData['supplierRevenue'] = $supplierListSubscriptionsRevenue ? $supplierListSubscriptionsRevenue : 0.0;
$jsonData['purchasingGroupRevenue'] = $purchasingGroupsSubscriptionsRevenue ? $purchasingGroupsSubscriptionsRevenue : 0.0;
return new JsonResponse([
'status' => 'success',
'statusCode' => '200',
'message' => 'success',
'data' => $jsonData,
], 200);
}
#[Route('/dashboard-line-chart', name: 'dashboard_resource_published_unpublished_chart')]
public function resourcePublishedUnpublishedData()
{
$published = $this->resourcesRepository->getPublishedResourcesMonthlyDataForCurrentYear();
$unpublished = $this->resourcesRepository->getUnPublishedResourcesMonthlyDataForCurrentYear();
$months = [
'Jan' => 1,
'Feb' => 2,
'March' => 3,
'April' => 4,
'May' => 5,
'Jun' => 6,
'July' => 7,
'Aug' => 8,
'Sept' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
];
$published = $this->resourcesRepository->getPublishedResourcesMonthlyDataForCurrentYear();
// Initialize the result array with 0 values for all months
$publishedResults = array_fill_keys($months, 0);
$unpublishedResults = array_fill_keys($months, 0);
foreach ($published as $value) {
$publishedResults[$value['month']] = $value['total'];
}
$jsonData['months'] = array_keys($months);
$jsonData['published'] = array_values($publishedResults);
$unpublished = $this->resourcesRepository->getUnPublishedResourcesMonthlyDataForCurrentYear();
foreach ($unpublished as $value) {
$unpublishedResults[$value['month']] = $value['total'];
}
$jsonData['unpublished'] = array_values($unpublishedResults);
return new JsonResponse([
'status' => 'success',
'statusCode' => '200',
'message' => 'success',
'data' => $jsonData,
], 200);
}
#[Route('/info', name: 'php_test_info')]
public function info()
{
phpinfo();
exit;
}
#[Route('/testUpload', name: 'test_upload')]
public function testUpload(Request $request)
{
return $this->render('test.html.twig', []);
}
#[Route('/s3upload', name: 'test_s3_upload')]
public function s3upload(Request $request)
{
$file = $request->files->get('videoFile');
$url = $this->imageService->uploadFileService('uploads', $file);
dd($url);
return new Response('No file provided', Response::HTTP_BAD_REQUEST);
}
/**
* @Route("/upload", name="upload_video", methods={"POST"})
*/
#[Route('/s3uploadChunk', name: 'test_s3_upload_chunk')]
public function uploadVideo(Request $request): JsonResponse
{
$bucket = 'gixli-live';
$chunkSize = 5 * 1024 * 1024; // 5 MB
$file = $request->files->get('videoFile');
if (!$file) {
return new JsonResponse(['error' => 'No file uploaded'], 400);
}
$filePath = $file->getRealPath();
$fileSize = filesize($filePath);
$key = 'uploads/' . $file->getClientOriginalName();
$uploadId = null;
try {
$multipartUploader = $this->s3Client->createMultipartUpload([
'Bucket' => $bucket,
'Key' => $key,
]);
$uploadId = $multipartUploader['UploadId'];
$parts = [];
$fileHandle = fopen($filePath, 'rb');
for ($i = 1; $i <= ceil($fileSize / $chunkSize); $i++) {
$chunk = fread($fileHandle, $chunkSize);
$result = $this->s3Client->uploadPart([
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $i,
'Body' => $chunk,
]);
$parts[] = [
'PartNumber' => $i,
'ETag' => $result['ETag'],
];
}
fclose($fileHandle);
$res = $this->s3Client->completeMultipartUpload([
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' => ['Parts' => $parts],
]);
return new JsonResponse(['message' => 'File uploaded successfully', 'data' => 'https://gixli-live.s3.amazonaws.com/' . $key]);
} catch (\Exception $e) {
if ($uploadId) {
$this->s3Client->abortMultipartUpload([
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
]);
}
return new JsonResponse(['error' => 'File upload failed: ' . $e->getMessage()], 500);
}
}
/**
* @Route("/info", name="info")
*/
#[Route('/info', name: 'phpinfo')]
public function phpinfo(Request $request)
{
echo phpinfo();
exit;
}
#[Route('/test-mail', name: 'testMail')]
public function testMail(Request $request)
{
$data = [
'response' => 'Test mail..',
];
$this->emailTemplates->sendMail('test', $data, 'kuldeepg.magneto@gmail.com');
$this->emailTemplates->sendMail('test', $data, 'colby@gixli.com');
$this->emailTemplates->sendMail('test', $data, 'hello@gixli.com');
$this->emailTemplates->sendMail('test', $data, 'gixli@gixli.com');
return new JsonResponse(['success' => 'Ok'], 200);
}
}