<?php
namespace App\Controller;
use App\Entity\Church;
use App\Form\ChurchType;
use App\Repository\ChurchRepository;
use App\Repository\LocationRepository;
use App\Repository\MemberRepository;
use App\Repository\PresbyteryRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MainController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(): Response
{
return $this->render('index.html.twig', [
'controller_name' => 'MainController',
]);
}
#[Route('/about-us', name: 'about_us')]
public function aboutUs(): Response
{
return $this->render('main/about-us.html.twig', [
'controller_name' => 'MainController',
]);
}
#[Route('/photo-gallery', name: 'photo_gallery')]
public function gallery(): Response
{
return $this->render('main/gallery.html.twig', [
'controller_name' => 'MainController',
]);
}
#[Route('/admin/dashboard', name: 'admin_dashboard')]
public function dashboard(MemberRepository $memberRepository, ChurchRepository $churchRepository, PresbyteryRepository $presbyteryRepository): Response
{
$presbyteryName = '';
if($this->isGranted('ROLE_SUPER_ADMIN')){
$members = $memberRepository->findAll();
$church = $churchRepository->findAll();
$presbytery = $presbyteryRepository->findAll();
}else{
$user = $this->getUser();
$id = $user->getPresbytery()->getId();
$church = $churchRepository->findBy(['presbytery' => $id]);
$members = $memberRepository->findBy(['presbytery' => $id]);
$presbytery = $presbyteryRepository->findBy(['id' => $id]);
$presbyteryName = $presbytery[0]->getName();
}
return $this->render('main/dashboard.html.twig', [
'totalMember' => count($members),
'totalChurch' => count($church),
'totalPresbytery' => count($presbytery),
'presbyteryName' => $presbyteryName
]);
}
#[Route('dashboard/chart', name: 'dashboard_chart')]
public function getReports(MemberRepository $memberRepository){
$user = $this->getUser();
$report = $memberRepository->reporting($user);
$gender = [];
$ageGroup = [];
foreach ($report['gender'] as $k => $v)
{
array_push($gender, $v);
}
foreach ($report['age'] as $value)
{
foreach ($value as $k => $v)
{
$ageGroup[$k] = $v;
}
}
$data = [
'gender' => $gender,
'age' => $ageGroup,
'presbytery' => $report['presbytery'],
'maritalStatus' => $report['maritalStatus']
];
return $this->json($data,200);
}
#[Route('/executives/list', name: 'executives_list')]
public function executives(): Response
{
$executive['central-committee'] = [
['name' => 'Mr. Phur Tshering Lepcha', 'image' => '8759063249.jpg','designation' => 'President','phone' => '8759063249','address' =>'EPC Anden, West Sikkim'],
['name'=> 'Mr. Yon Tshering Lepcha','image' => '9832632727.jpg','designation' => 'Vice- President','phone' => '9832632727','address' =>'EPC Rehnock, East Sikkim'],
['name'=> 'Mr. Nikanor Rai','image' => '7908440974.jpg','designation' => 'Secretary ','phone' => '7908440974','address' =>'EPC Penlong, East Sikkim'],
['name'=> 'Ms. Leegain Lepcha','image' => '9647853240.jpg','designation' => 'Joint-Secretary','phone' => '9647853240','address' =>'EPC Rumbuk, West Sikkim'],
['name'=> 'Ms. Samina Lakhey','image' => '701714172.jpg','designation' => 'Treasurer','phone' => '701714172','address' =>'EPC Tadong, East Sikkim'],
['name'=> 'Mr. Andrew Lepcha','image' => '8370936842.jpg','designation' => 'Joint-Treasurer','phone' => '8370936842','address' =>'EPC Pabong, South Sikkim'],
];
$executive['advisors'] = [
['name' => 'Rev. Pem Kitter Sherpa', 'image' => '8016628266.jpg','designation' => '','phone' => '8016628266','address' =>'EPC Mangalbaria, West Sikkim'],
['name'=> 'Rev. Thinlay Dorjee Lepcha','image' => '9593763235.jpg','designation' => '','phone' => '9593763235','address' =>'EPC Sagyong, North Sikkim'],
['name'=> 'Shri Lawrence Lepcha','image' => '9933092074.jpg','designation' => ' ','phone' => '9933092074','address' =>'EPC Gangtok, East Sikkim'],
['name'=> 'Shri Pema Sukmimoo','image' => '9434109962.jpg','designation' => '','phone' => '9434109962','address' =>'EPC Gangtok, East Sikkim'],
['name'=> 'Elder Bimal Sherpa','image' => '9647879249.jpg','designation' => '','phone' => '9647879249','address' =>'EPC Gangtok, East Sikkim']
];
$executive['sub-committee'] = [
['name' => 'Mr. Jeewan Kharel', 'image' => '9434382273.jpg','designation' => 'Construction In-Charge','phone' => '9434382273','address' =>'EPC Namthang, South Sikkim'],
['name'=> 'Ms. Jessica M. Tamang','image' => '7076174397.jpg','designation' => 'Property In-Charge','phone' => '7076174397 ','address' =>'EPC Bardang, East Sikkim'],
['name'=> 'Mr. Samuel Tasho','image' => '9474059363.jpg','designation' => 'Property In-Charge','phone' => '9474059363 ','address' =>'EPC Fambong, West Sikkim'],
];
$executive['executive-committee'] = [
['name' => 'Mr. Pravin Chettri ', 'image' => '7047908765.jpg','designation' => 'Sports In-Charge','phone' => '7047908765','address' =>'EPC Namchi, South Sikkim'],
['name'=> 'Elder Moses Tamu','image' => '9593269521.jpg','designation' => 'Publicity Secretary','phone' => '9593269521 ','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. Simeyon Sukita Rai','image' => '8392086260.jpg','designation' => 'Literature In-Charge','phone' => '8392086260 ','address' =>'EPC Ranguthang, South Sikkim'],
['name'=> 'Dr. Romona Lepcha','image' => '8906347419.jpg','designation' => 'Literature In-Charge','phone' => '8906347419 ','address' =>'EPC Rehnock, East Sikkim'],
['name'=> 'Mrs. Srijana Subba','image' => 'sdfs','designation' => 'Literature In-Charge','phone' => ' ','address' =>'EPC Soreng, West Sikkim'],
['name'=> 'Elder. Jagat Jhon Rai','image' => '9434486793.jpg','designation' => 'Social Wing In-Charge (North)','phone' => '9434486793','address' =>'EPC Gangtok, East Sikkim'],
['name'=> 'Mr. Milan Rai ','image' => '9733110850.jpg','designation' => 'Social Wing In-Charge (East)','phone' => '9733110850','address' =>'EPC Gangtok, East Sikkim'],
['name'=> 'Mr. Mohan Bista','image' => '7797300940.jpg','designation' => 'Social Wing In-Charge (South)','phone' => '7797300940','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. Joel Lepcha','image' => '1111111111.jpg','designation' => 'Social Wing In-Charge (West)','phone' => '','address' =>'EPC Fambong, West Sikkim'],
['name'=> 'Mr. Emanuel Rai','image' => '9434382209.jpg','designation' => 'Culture In-Charge','phone' => '9434382209','address' =>'EPC Ranka, East Sikkim'],
['name'=> 'Mr. Mahindra Bardewa','image' => 'sdfs','designation' => 'Culture In-Charge','phone' => '','address' =>'EPC _________, East Sikkim'],
['name'=> 'Mr. Biren Subba','image' => 'sdfs','designation' => 'Culture In-Charge','phone' => '','address' =>'EPC Pabong, South Sikkim'],
['name'=> 'Mr. Allen Lepcha','image' => '9434410319.jpg','designation' => 'President, North Presbytery Youth Fellowship','phone' => '9434410319','address' =>'EPC Penlong, North Sikkim'],
['name'=> 'Mr. Dhan Bahadur Biswakarma','image' => '2222222222.jpg','designation' => 'Vice-President, North Presbytery Youth Fellowship','phone' => '','address' =>'EPC Mangshila, North Sikkim'],
['name'=> 'Mr. Dan Tshering Lepcha','image' => '9641214429.jpg','designation' => 'Secretary, North Presbytery Youth Fellowship','phone' => '9641214429','address' =>'EPC Zim-Gor, North Sikkim'],
['name'=> 'Ms. Sara Rai','image' => '7908199163.jpg','designation' => 'Joint Secretary, North Presbytery Youth Fellowship','phone' => '7908199163','address' =>'EPC Penlong, North Sikkim'],
['name'=> 'Mr. Tempa Tshering Sherpa','image' => '3333333333.jpg','designation' => 'Treasurer, North Presbytery Youth Fellowship','phone' => '9434410319','address' =>'EPC Kabi, East Sikkim'],
['name'=> 'Mr. Purna Limboo','image' => '8158977999.jpg','designation' => 'Co-Ordianator, North Presbytery Youth Fellowship','phone' => '8158977999','address' =>'EPC Mangshila, East Sikkim'],
['name'=> 'Mr. Pravesh Chettri','image' => '7407126839.jpg','designation' => 'President, South Presbytery Youth Fellowship, Namchi','phone' => '7407126839','address' =>'EPC Namchi, South Sikkim'],
['name'=> 'Ms. Shinemit Lepcha','image' => '9593987841.jpg','designation' => 'Secretary, South Presbytery Youth Fellowship, Namchi','phone' => '9593987841','address' =>'EPC Lungchok, South Sikkim'],
['name'=> 'Ms. Dawa Ongmu Sherpa','image' => '8348521349.jpg','designation' => 'Treasurer, South Presbytery Youth Fellowship, Namchi','phone' => '8348521349','address' =>'EPC Damthang, South Sikkim'],
['name'=> 'Mr. Shawal Lepcha','image' => '7384224816.jpg','designation' => 'Co-Ordianator, South Presbytery Youth Fellowship, Namchi','phone' => '7384224816','address' =>'EPC Wok, South Sikkim'],
['name'=> 'Mr. Palden Sukmimoo','image' => '9474357415.jpg','designation' => 'President, East Presbytery Youth Fellowship','phone' => '9474357415','address' =>'EPC Tshalamthang, East Sikkim'],
['name'=> 'Mr. Solomon Sharma','image' => '7076219337.jpg','designation' => 'Vice-President, East Presbytery Youth Fellowship','phone' => '7076219337','address' =>'EPC Tadong, East Sikkim'],
['name'=> 'Mr. Robin Gurung','image' => '7602997746.jpg','designation' => 'Secretary, East Presbytery Youth Fellowship','phone' => '7602997746','address' =>'EPC Gangtok, East Sikkim'],
['name'=> 'Ms. Mayel Lepcha','image' => '7679685490.jpg','designation' => 'Joint-Secretary, East Presbytery Youth Fellowship','phone' => '7679685490','address' =>'EPC Nandok, East Sikkim'],
['name'=> 'Ms. Uma Thapa','image' => '859791806.jpg','designation' => 'Treasurer, East Presbytery Youth Fellowship','phone' => '859791806','address' =>'EPC Pakyong, East Sikkim'],
['name'=> 'Mr. Daniel Sukmimoo','image' => '8370978364.jpg','designation' => 'Joint-Treasurer, East Presbytery Youth Fellowship','phone' => '8370978364','address' =>'EPC Pakyong, East Sikkim'],
['name'=> ' ','image' => 'sdfs','designation' => 'Co-Ordinator, East Presbytery Youth Fellowship','phone' => '','address' =>'EPC , East Sikkim'],
['name'=> 'Elder Moses Tamu','image' => '9593269521.jpg','designation' => 'President, Ravangla Presbytery Youth Fellowship','phone' => '9593269521','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. James Rai','image' => '9733146024.jpg','designation' => 'Vice-President, Ravangla Presbytery Youth Fellowship','phone' => '9733146024','address' =>'EPC Phamtam, South Sikkim'],
['name'=> 'Mr. Lall Singh Limboo','image' => '9593387373.jpg','designation' => 'Secretary, Ravangla Presbytery Youth Fellowship','phone' => '9593387373','address' =>'EPC Pawdara, South Sikkim'],
['name'=> 'Ms. Anjali Biswa','image' => '7872657418.jpg','designation' => 'Joint-Secretary, Ravangla Presbytery Youth Fellowship','phone' => '7872657418','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. Mohan Bista (Chettri)','image' => '7797300940.jpg','designation' => 'Treasurer, Ravangla Presbytery Youth Fellowship','phone' => '7797300940.jpg','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. Aliya Rai','image' => '9732956909.jpg','designation' => 'Co-Ordinator, Ravangla Presbytery Youth Fellowship','phone' => '9732956909','address' =>'EPC Ravangla, South Sikkim'],
['name'=> 'Mr. Moses Pradhan','image' => '8372044509.jpg','designation' => 'President, West Presbytery Youth Fellowship','phone' => '8372044509','address' =>'EPC Soreng, West Sikkim'],
['name'=> 'Ms. Galen Lepcha','image' => '9734330031.jpg','designation' => 'Secretary, West Presbytery Youth Fellowship','phone' => '9734330031','address' =>'EPC Rumbuk, West Sikkim'],
['name'=> 'Mr. Ashit Subba','image' => '8509823278.jpg','designation' => 'Treasurer, West Presbytery Youth Fellowship','phone' => '8509823278','address' =>'EPC Soreng, West Sikkim'],
['name'=> '','image' => '','designation' => 'Co-Ordinator, West Presbytery Youth Fellowship','phone' => '','address' =>'EPC , West Sikkim'],
];
return $this->render('main/executives.html.twig', [
'executive' => $executive,
]);
}
#[Route('/member/list', name: 'member_list')]
public function memberList(MemberRepository $memberRepository, PresbyteryRepository $presbyteryRepository): Response
{
if($this->isGranted('ROLE_SUPER_ADMIN')){
$members = $memberRepository->findBy([],['id' => 'DESC']);
$presbyteryList = $presbyteryRepository->findBy([],['name' => 'ASC']);
}else{
$user = $this->getUser();
$id = $user->getPresbytery()->getId();
$members = $memberRepository->findBy(['presbytery' => $id],['id' => 'DESC']);
$presbyteryList = $presbyteryRepository->findBy(['id' => $id],['name' => 'ASC']);
}
return $this->render('main/member-list.html.twig', [
'members' => $members,
'count' => count($members),
'presbytery' => $presbyteryList
]);
}
#[Route('/presbytery/list', name: 'presbytery_list')]
public function presbyteryList(PresbyteryRepository $presbyteryRepository): Response
{
$presbytery = $presbyteryRepository->findAll();
$dataArray = [];
foreach ($presbytery as $data){
$dataArray[] = [
'presbytery' => $data->getName(),
'church' => $data->getChurch()->getValues()
];
}
return $this->render('main/presbytery_list.html.twig', [
'data' => $dataArray,
]);
}
#[Route('/location/list', name: 'location_list')]
public function locationList(LocationRepository $locationRepository): Response
{
$data = $locationRepository->findAll();
return $this->render('main/location_list.html.twig', [
'data' => $data,
]);
}
#[Route('/church/list', name: 'church_list')]
public function churchList(ChurchRepository $churchRepository): Response
{
if($this->isGranted('ROLE_SUPER_ADMIN')){
$churches = $churchRepository->findAll();
}else{
$user = $this->getUser();
$id = $user->getPresbytery()->getId();
$churches = $churchRepository->findBy(['presbytery' => $id],['id' => 'DESC']);
}
return $this->render('church/index.html.twig', [
'churches' => $churches,
]);
}
#[Route('/church/add', name: 'add_church')]
public function addChurch(Request $request, ChurchRepository $churchRepository): Response
{
$church = new Church();
$user = $this->getUser();
$form = $this->createForm(ChurchType::class, $church,['presbyteryId' => $user->getPresbytery() ? $user->getPresbytery()->getId() : null]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$churchRepository->add($form->getData(), true);
return $this->redirectToRoute('church_list', [], Response::HTTP_SEE_OTHER);
}
return $this->render('church/new.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/church/edit/{id}', name: 'edit_church')]
public function editChurch(Request $request, ChurchRepository $churchRepository, $id): Response
{
$church = $churchRepository->find($id);
$user = $this->getUser();
$form = $this->createForm(ChurchType::class, $church,['presbyteryId' => $user->getPresbytery() ? $user->getPresbytery()->getId() : null]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$churchRepository->add($form->getData(), true);
return $this->redirectToRoute('church_list', [], Response::HTTP_SEE_OTHER);
}
return $this->render('church/edit.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/filter-location', name: 'filter_location')]
public function filterLocation(Request $request, LocationRepository $locationRepository)
{
$id = $request->query->get('id');
$filterdLocation = $locationRepository->filterLocation($id);
return $this->json($filterdLocation,Response::HTTP_OK,[],['groups' => ['presbytery']]);
}
#[Route('/filter-church', name: 'filter_church')]
public function filterChurch(Request $request, ChurchRepository $churchRepository,MemberRepository $memberRepository)
{
$type = intval($request->get('church'));
$id = $request->query->get('id');
$filteredChurch = $churchRepository->filterChurch($id);
$memberCount = $memberRepository->totalMembersCount($id,$type);
return $this->json([$filteredChurch,'count' => $memberCount],Response::HTTP_OK,[],['groups' => ['presbytery']]);
}
}