src/Controller/DashboardController.php line 37
<?phpnamespace App\Controller;use App\Repository\TheCaseActionsRepository;use App\Repository\TheCaseRepository;use App\Service\EDeskService;use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;use Omines\DataTablesBundle\DataTableFactory;use PhpOffice\PhpSpreadsheet\Style\Border;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpFoundation\Session\SessionInterface;use Symfony\Component\HttpFoundation\StreamedResponse;use Symfony\Component\Routing\Annotation\Route;use Symfony\Contracts\Translation\TranslatorInterface;use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;use Symfony\UX\Chartjs\Model\Chart;use PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\Xlsx;class DashboardController extends AbstractController{private EDeskService $GetStep;private ChartBuilderInterface $chartBuilder;public function __construct(EDeskService $GetStep,ChartBuilderInterface $chartBuilder){$this->GetStep = $GetStep;$this->chartBuilder = $chartBuilder;}#[Route('/dashboard', name: 'app_dashboard')]public function index(TheCaseRepository $theCaseRepository,Request $request,TranslatorInterface $translator): Response{//dd($theCaseRepository->CaseWithLastAction());$GetCharte = $this->GetCharte($theCaseRepository, $translator->trans('Cases',[],'translation'));$GetCountCase = $theCaseRepository->CountCases($this->getUser()->getLawOffice());$GetStepStats = $this->GetStep->GetStepStat();return $this->render('dashboard/index.html.twig', ['controller_name' => 'DashboardController','StepStats' => $GetStepStats,'CountCases' => $GetCountCase,'ChartByMonth'=> $GetCharte,'CasesWithLastActions' => $theCaseRepository->CaseWithLastAction(),]);}#[Route('/light-mode', name: 'light-mode')]public function themeLight(SessionInterface $session): Response{$session->remove('theme');return $this->redirectToRoute('app_dashboard');}#[Route('/dark-mode', name: 'dark-mode')]public function themeDark(SessionInterface $session): Response{$session->set('theme', 'dark');return $this->redirectToRoute('app_dashboard');}function GetCharte(TheCaseRepository $theCaseRepository,String $ChartTitle): Chart{$TypeCharte = 'ChartSticks';$labels = [];$data = [];$max = 0;$DatasRepo= $theCaseRepository->CaseByMonth();//dd($DatasRepo);if (empty($DatasRepo)){return $this->chartBuilder->createChart($TypeCharte);}foreach ($DatasRepo as $DataRepo ){//dd($DataRepo);$labels[] = $DataRepo['Month'];$data[] = $DataRepo['Total'];if ($DataRepo['Total'] > $max){$max = $DataRepo['Total'];}}switch ($TypeCharte) {case "ChartCurved":$TypeCharte = Chart::TYPE_LINE;break;case "ChartPie":$TypeCharte = Chart::TYPE_PIE;break;case "ChartSticks":$TypeCharte = Chart::TYPE_BAR;break;}$chart = $this->chartBuilder->createChart($TypeCharte);$chart->setData(['labels' => $labels,'datasets' => [['label' => $ChartTitle,'backgroundColor' => $this->GetColor(count($data)),'data' => $data,],],]);$chart->setOptions(['scales' => ['y' => ['suggestedMin' => 0,'suggestedMax' => $max+0.2,],//'x'=>'gridLines'],]);return $chart;}function GetColor($num) {$ColorRanges =[];for ($i = 1; $i <= $num; $i++) {$hash = md5('color' . $i);$ColorRange = 'rgb('.hexdec(substr($hash, 0, 2)).','.hexdec(substr($hash, 2, 2)).','.hexdec(substr($hash, 4, 2)).')';array_push($ColorRanges, $ColorRange);}return $ColorRanges;}#[Route('Hearing', name: 'app_Hearing', methods: ['GET'])]public function showHearing(Request $request,TheCaseActionsRepository $theCaseActionsRepository,Encryptor $encryptor,DataTableFactory $dataTableFactory,TranslatorInterface $translator,): Response{$DateValue = $encryptor->decrypt($request->get("Date"));//$DateValue = $DateValue;$LawOffice = $this->getUser()->getLawOffice();$theCaseActions = $theCaseActionsRepository->FindByActionDate($DateValue,$LawOffice);//dd($theCaseActions);$Hearings = $this->render('the_case_actions/showmodal.html.twig', ['Hearings' => $theCaseActions,'ThisDate' => $request->get("Date"),'DateValue' => $DateValue,]);return $this->json(['Status' => 'Success','Hearing' => $Hearings,], 200);//return $this->redirectToRoute('app_case_continue', ['id'=>$theCaseAction->getTheCase()->getId()], Response::HTTP_SEE_OTHER);}#[Route('exportHearing', name: 'app_Hearing_Export', methods: ['GET'])]public function showHearingExport(Request $request,TheCaseActionsRepository $theCaseActionsRepository,Encryptor $encryptor,TranslatorInterface $translator,): Response{$DateValue = $encryptor->decrypt($request->get("Date"));//$DateValue = $DateValue;$LawOffice = $this->getUser()->getLawOffice();$theCaseActions = $theCaseActionsRepository->FindByActionDate($DateValue,$LawOffice);$SubTitleStyleArray = ['font' => ['bold' => true,'Size'=> 13],'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,],'borders' => ['top' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,],],'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,'startColor' => ['argb' => 'FFA0A0A0',],'endColor' => ['argb' => 'FFFFFFFF',],],];// Convert string $DateValue to date format:$DateSTRToDate = new \DateTime($DateValue);$spreadsheet = new Spreadsheet();$sheet = $spreadsheet->getActiveSheet();$sheet = $spreadsheet->getActiveSheet()->setTitle('جدول الجلسات');$sheet->setCellValue('A1', 'جدول الجلسات ليوم : '.$DateSTRToDate->format('Y/m/d'))->mergeCells('A1:H1');$sheet->getStyle('A1:H1')->getFont()->setSize(14);$sheet->getStyle('A1:H1')->getFont()->setBold(true);$sheet->getStyle('A1:H1')->getBorders()->getAllBorders()->setBorderStyle(true);$sheet->getStyle('A1:H1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);$sheet->getStyle('A2:H2')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);$sheet->getStyle('A2:H2')->getBorders()->getAllBorders()->setBorderStyle(true);$sheet->getStyle('A2:H2')->getFont()->setBold(true);$sheet->getColumnDimension('A')->setWidth(20);$sheet->getColumnDimension('B')->setWidth(26);$sheet->getColumnDimension('C')->setAutoSize(true);$sheet->getColumnDimension('D')->setAutoSize(true);$sheet->getColumnDimension('E')->setAutoSize(true);$sheet->getColumnDimension('F')->setAutoSize(true);$sheet->getColumnDimension('G')->setAutoSize(true);$sheet->getColumnDimension('H')->setAutoSize(true);/// Title Column$sheet->setCellValue('A2', $translator->trans('Memo',[],'translation'));$sheet->setCellValue('B2', $translator->trans('Demand',[],'translation'));$sheet->setCellValue('C2', $translator->trans('LawyerAdv',[],'translation'));$sheet->setCellValue('D2', $translator->trans('OpponentName',[],'translation'));$sheet->setCellValue('E2', $translator->trans('Client',[],'translation'));$sheet->setCellValue('F2', $translator->trans('CaseType',[],'translation'));$sheet->setCellValue('G2', $translator->trans('FullFileTpiNum',[],'translation'));$sheet->setCellValue('H2', $translator->trans('RefLawOffice',[],'translation'));$i = 3;//$Cells = ['A',"B","C","D","E","F","G","H"];foreach ($theCaseActions as $theCaseAction) {$sheet->setCellValue('A'.$i, '');$sheet->setCellValue('B'.$i, $theCaseAction->getActionName());$sheet->setCellValue('C'.$i, $theCaseAction->getTheCase()->getLawyerAdv());$sheet->setCellValue('D'.$i, $theCaseAction->getTheCase()->getOpponentName());$sheet->setCellValue('E'.$i, $theCaseAction->getTheCase()->getClient()->getFirstName().' '.$theCaseAction->getTheCase()->getClient()->getLastName());$sheet->setCellValue('F'.$i, $theCaseAction->getTheCase()->getCaseType()->getcaseTypeName());$sheet->setCellValue('G'.$i, $theCaseAction->getTheCase()->getFullFileTpiNum());$sheet->setCellValue('H'.$i, $theCaseAction->getTheCase()->getRefLawOffice());$i++;}$styleArrayContent = array('borders' => array('outline' => array('style' => Border::BORDER_MEDIUM,),),);$CellsCoordinate = "A3:H".$i;$sheet->getStyle($CellsCoordinate)->applyFromArray($styleArrayContent);//dd($theCaseActions);$contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';$writer = new Xlsx($spreadsheet);$response = new StreamedResponse();$response->headers->set('Content-Type', $contentType);$response->headers->set('Content-Disposition', 'attachment;filename="exports-'.time().'.xlsx"');$response->setPrivate();$response->headers->addCacheControlDirective('no-cache', true);$response->headers->addCacheControlDirective('must-revalidate', true);$response->setCallback(function() use ($writer) {$writer->save('php://output');});return $response;}}