src/Controller/Admin/FilmProjectCrudController.php line 468

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Donation;
  4. use App\Entity\FilmProject;
  5. use App\Entity\FilmProjectProgressReport;
  6. use App\Form\FilmApplicationMemberType;
  7. use App\Repository\ProductRepository;
  8. use App\Repository\FilmProjectProgressReportRepository;
  9. use App\Serializer\FilmProjectObjectConverter;
  10. use App\Service\FilmApplicationService;
  11. use App\Service\UserBillingService;
  12. use App\Service\ProgressReportService;
  13. use App\String\Constant;
  14. use App\String\ProjectString;
  15. use App\Utility\CsvExporter;
  16. use App\Utility\DropdownValues;
  17. use App\Utility\FormGenerator;
  18. use App\Utility\PdfExporter;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Doctrine\ORM\QueryBuilder;
  21. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  22. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  23. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  24. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  25. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  26. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  27. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  28. use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
  29. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  30. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  31. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  32. use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
  33. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  34. use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
  35. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  36. use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
  37. use EasyCorp\Bundle\EasyAdminBundle\Field\CountryField;
  38. use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
  39. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  40. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  41. use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
  42. use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
  43. use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
  44. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  45. use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
  46. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  47. use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
  48. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  49. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  50. use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;
  51. use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
  52. use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
  53. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  54. use Knp\Snappy\Pdf;
  55. use Symfony\Component\HttpFoundation\RedirectResponse;
  56. use Symfony\Component\HttpFoundation\RequestStack;
  57. use Symfony\Component\HttpFoundation\Response;
  58. use Symfony\Component\HttpFoundation\Session\Session;
  59. use Twig\Environment;
  60. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  61. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  62. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  63. class FilmProjectCrudController extends AbstractCrudController
  64. {
  65.     private EntityManagerInterface $em;
  66.     private AdminUrlGenerator $adminUrlGenerator;
  67.     private FilmApplicationService $filmApplicationService;
  68.     private UserBillingService $userBillingService;
  69.     private $requestStack;
  70.     private ProgressReportService $progressReportService;
  71.     private bool $isProgressReport false;
  72.     public function __construct(EntityManagerInterface $emAdminUrlGenerator $adminUrlGeneratorFilmApplicationService $filmApplicationServiceUserBillingService $userBillingServiceRequestStack $requestStackProgressReportService $progressReportService)
  73.     {
  74.         $this->em $em;
  75.         $this->adminUrlGenerator $adminUrlGenerator;
  76.         $this->filmApplicationService $filmApplicationService;
  77.         $this->userBillingService $userBillingService;
  78.         $this->requestStack $requestStack;
  79.         $this->progressReportService $progressReportService;
  80.     }
  81.     public static function getEntityFqcn(): string
  82.     {
  83.         return FilmProject::class;
  84.     }
  85.     public function configureFields(string $pageName): iterable
  86.     {
  87.         $formGenerator = new FormGenerator();
  88.         $formFields $formGenerator->generateForm(Constant::PROJECT_FORM);
  89.         $formFields array_merge($formFields, [
  90.             // FormField::addTab('Additional Information')->addCssClass('application_payment')->setPermission(Constant::PORTAL_USER_ROLE),
  91.             TextField::new('orderDetails.orderBillingDetails.firstName'ProjectString::PROJECT_PAYMENT_FIRST_NAME)->setColumns(6)->hideOnIndex()->setRequired(true)->addCssClass('firstName'),
  92.             TextField::new('orderDetails.orderBillingDetails.lastName'ProjectString::PROJECT_PAYMENT_LAST_NAME)->setColumns(6)->hideOnIndex()->setRequired(true)->addCssClass('lastName'),
  93.             TextField::new('orderDetails.orderBillingDetails.organisation'ProjectString::PROJECT_PAYMENT_ORGANISATION)->setColumns(12)->hideOnIndex(),
  94.             TextField::new('orderDetails.orderBillingDetails.abn'ProjectString::PROJECT_PAYMENT_ABN)->setColumns(12)->hideOnIndex()->setRequired(true)->addCssClass('abn'),
  95.             TextField::new('orderDetails.orderBillingDetails.street'ProjectString::PROJECT_PAYMENT_STREET)->setColumns(12)->hideOnIndex()->setRequired(true)->addCssClass('streetAddress'),
  96.             TextField::new('orderDetails.orderBillingDetails.suburb'ProjectString::PROJECT_PAYMENT_SUBURB)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('suburb'),
  97.             ChoiceField::new('orderDetails.orderBillingDetails.state'ProjectString::PROJECT_PAYMENT_STATE)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('state')->setChoices(DropdownValues::$states),
  98.             CountryField::new('orderDetails.orderBillingDetails.country'ProjectString::PROJECT_PAYMENT_COUNTRY)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('country'),
  99.             TextField::new('orderDetails.orderBillingDetails.postcode'ProjectString::PROJECT_PAYMENT_POSTCODE)->setColumns(3)->hideOnIndex()->setRequired(true)->setFormTypeOptions([
  100.                 'attr' => [
  101.                     'maxlength' => 4,
  102.                     'minlength' => 4,
  103.                 ]
  104.             ])->addCssClass('postcode'),
  105.             TextField::new('orderDetails.orderBillingDetails.phoneNumber'ProjectString::PROJECT_PAYMENT_PHONE)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('phone'),
  106.             TextField::new('orderDetails.orderBillingDetails.emailAddress'ProjectString::PROJECT_PAYMENT_EMAIL)->setColumns(5)->hideOnIndex()->setRequired(true)->addCssClass('emailAddress'),
  107.             // Hidden fields for Merchant Warrior payment
  108.             HiddenField::new('orderDetails.orderBillingDetails.payframeToken')->hideOnIndex()->hideOnDetail()->setCssClass('mw-token'),
  109.             HiddenField::new('orderDetails.orderBillingDetails.payframeKey')->hideOnIndex()->hideOnDetail()->setCssClass('mw-key'),
  110.             HiddenField::new('orderDetails.orderBillingDetails.cardId')->hideOnIndex()->hideOnDetail()->setCssClass('cardID'),
  111.             BooleanField::new('orderDetails.orderBillingDetails.isSavedCreditCard')->hideOnIndex()->hideOnDetail()->setCssClass('d-none is-saved-credit-card'),
  112.             
  113.             // Index fields
  114.             TextField::new('title''Project Name')->hideOnForm()->setTemplatePath('admin/field/project_title.html.twig'),
  115.             TextField::new('fundingStatus''Funding Status / Goal')->hideOnForm(),
  116.             DateField::new('filmProjectTimeline.fundraisingCampaignEndDate''End Date')->renderAsText()->hideOnForm()->setFormat('d MMM y')->setTemplatePath('admin/field/project_date.html.twig'),
  117.             TextField::new('productionStage''Project Stage')->hideOnForm()->setTemplatePath('admin/field/project_stage.html.twig'),
  118.             TextField::new('status''Status')->hideOnForm()->setTemplatePath('admin/field/project_status.html.twig'),
  119.             TextField::new('wordpressStatus''Wordpress Status')->hideOnForm()->setTemplatePath('admin/field/project_wordpress_status.html.twig'),
  120.             BooleanField::new('isHideDonationBox''Donation Box')->hideOnForm()->setTemplatePath('admin/field/is_display_donation.html.twig'),
  121.             IdField::new('wordpressId''WP ID')->hideOnForm()->setTemplatePath('admin/field/wordpress_id.html.twig')->setPermission(Constant::ADMIN_ROLE),
  122.             IdField::new('oldWordpressId''old WP ID')->hideOnForm()->setTemplatePath('admin/field/wordpress_id.html.twig')->setPermission(Constant::ADMIN_ROLE),
  123.         ]);
  124.         $user $this->getUser();
  125.         $isProgressReport $this->progressReportService->checkIfProgressReportStarts();
  126.         if($isProgressReport) {
  127.             $formFields array_merge($formFields, [
  128.                 // BooleanField::new('progressReportStatus', 'Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/is_progress_report_complete.html.twig'),
  129.                 TextField::new('progressReportStatusUpdate''Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/progress_report_status_update.html.twig'),
  130.             ]);
  131.         }
  132.         // $formFields = array_merge($formFields, [
  133.         //     BooleanField::new('isProgressReportActive', 'Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/is_progress_report_active.html.twig'),
  134.         // ]);
  135.         return $formFields;
  136.     }
  137.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  138.     {
  139.         // Get current user profile
  140.         $user $this->getUser();
  141.         
  142.         if ($user->isAdmin()) {
  143.             $response $this->container->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  144.             $response
  145.                 ->andWhere('entity.status = :declined or entity.status = :approved or entity.status = :resubmit')
  146.                 ->setParameter('declined''declined')
  147.                 ->setParameter('approved''approved')
  148.                 ->setParameter('resubmit''resubmit')
  149.                 // ->addOrderBy('entity.title', 'ASC')
  150.                 ->addOrderBy('entity.id''DESC')
  151.             ;
  152.             return $response;
  153.         }
  154.         $response $this->container->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  155.         $response
  156.             ->leftJoin('entity.filmProjectMembers','f')
  157.             ->andWhere('entity.owner = :userId or (f.email = :userEmail and f.isActive = true)')
  158.             ->andWhere('entity.status = :approved or entity.status = :declined or entity.status = :resubmit')
  159.             ->setParameter('userId'$user->getId())
  160.             ->setParameter('userEmail'$user->getEmail())
  161.             ->setParameter('approved''approved')
  162.             ->setParameter('declined''declined')
  163.             ->setParameter('resubmit''resubmit')
  164.             ->addOrderBy('entity.id''DESC');
  165.         return $response;
  166.     }
  167.     public function createEntity(string $entityFqcn)
  168.     {
  169.         $user $this->getUser();
  170.         
  171.         return $this->filmApplicationService->createFilmProjectObj($user);
  172.     }
  173.     public function persistEntity(EntityManagerInterface $entityManager$entityInstanceAdminContext $context null): void
  174.     {
  175.         $entityManager->persist($entityInstance);
  176.         $entityManager->flush();
  177.         $this->updateMainMembers($entityManager$entityInstance);
  178.     }
  179.     public function updateEntity(EntityManagerInterface $entityManager$entityInstance): void
  180.     {
  181.         $entityManager->persist($entityInstance);
  182.         $entityManager->flush();
  183.         $this->updateMainMembers($entityManager$entityInstance);
  184.     }
  185.     public function deleteEntity(EntityManagerInterface $entityManager$entityInstance): void
  186.     {
  187.         // $filmProjectAdmin = $entityInstance->getFilmProjectAdmin();
  188.         // $filmProjectProducer = $entityInstance->getFilmProjectProducer();
  189.         // $filmProjectDirector = $entityInstance->getFilmProjectDirector();
  190.         // $filmProjectMembers = $entityInstance->getFilmProjectMembers();
  191.         // $filmProjectAdmin->setAdminFilmProject(null);
  192.         // $filmProjectProducer->setProducerFilmProject(null);
  193.         // $filmProjectDirector->setDirectorFilmProject(null);
  194.         // $entityManager->persist($filmProjectAdmin);
  195.         // $entityManager->persist($filmProjectProducer);
  196.         // $entityManager->persist($filmProjectDirector);
  197.         // $entityManager->flush();
  198.         // $entityInstance
  199.         //     ->setFilmProjectAdmin(null)
  200.         //     ->setFilmProjectProducer(null)
  201.         //     ->setFilmProjectDirector(null)
  202.         // ;        
  203.         // $entityManager->remove($filmProjectAdmin);
  204.         // $entityManager->remove($filmProjectProducer);
  205.         // $entityManager->remove($filmProjectDirector);
  206.         // $entityManager->flush();
  207.         // foreach ($filmProjectMembers as $filmProjectMember) {
  208.         //     $entityManager->remove($filmProjectMember);
  209.         //     $entityInstance->removeFilmProjectMember($filmProjectMember);
  210.         // }
  211.         // $entityManager->persist($entityInstance);
  212.         // $entityManager->flush();
  213.         // $entityManager->remove($entityInstance);
  214.         // $entityManager->flush();
  215.         $entityInstance->setStatus('archived');
  216.         
  217.         $entityManager->persist($entityInstance);
  218.         $entityManager->flush();
  219.         $this->addFlash('Project removed''Project '$entityInstance->getTitle() .' has been removed.');   
  220.     }
  221.     public function configureCrud(Crud $crud): Crud
  222.     {
  223.         // $user = $this->getUser();
  224.         $crud
  225.             ->setPaginatorPageSize(60)
  226.             ->addFormTheme('admin/formTheme/film_application_theme.html.twig')
  227.             ->setPageTitle('index''Manage Projects')
  228.             ->setPageTitle('new''New Project Application')
  229.             ->setPageTitle('edit''Edit Film Project')
  230.             ->overrideTemplate('crud/new''admin/form/new_film_application_form.html.twig')
  231.             ->overrideTemplate('crud/edit''admin/form/film_application_form.html.twig')
  232.             ->overrideTemplate('crud/index''admin/index/film_project_index.html.twig')
  233.             ->overrideTemplate('flash_messages''admin/crud/flash_messages_alt.html.twig')
  234.         ;
  235.         return $crud;
  236.     }
  237.     public function configureActions(Actions $actions): Actions
  238.     {
  239.         $user $this->getUser();
  240.         $isProgressReport $this->progressReportService->checkProgressReportStartsWithUser($user);
  241.         $backAction Action::new('backAction''Save Draft''')
  242.             ->linkToCrudAction('backAction')
  243.         ;
  244.         $saveDraft Action::new('saveDraft''Save Draft''')
  245.             ->linkToCrudAction('saveDraft')
  246.             ->displayIf(static function ($entity) {
  247.                 $status $entity->getStatus();
  248.                 return $status == 'draft' || $status == 'resubmit';
  249.             })
  250.         ;
  251.         $viewWordpressLink Action::new('viewWordpressLink''View Project''')
  252.             ->linkToUrl(function (FilmProject $entity) {
  253.                 return $entity->getWordpressUrl();
  254.             })
  255.             ->displayIf(static function ($entity) {
  256.                 $status $entity->getWordpressStatus();
  257.                 $url $entity->getWordpressUrl();
  258.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_PUBLISH ));
  259.             })
  260.             ->setHtmlAttributes(['target' => '_blank'])
  261.         ;
  262.         $viewDraftWordpressLink Action::new('viewDraftWordpressLink''View Project''')
  263.             ->linkToUrl(function (FilmProject $entity) {
  264.                 return $entity->getWordpressDraftUrl();
  265.             })
  266.             ->displayIf(static function ($entity) {
  267.                 $status $entity->getWordpressStatus();
  268.                 $url $entity->getWordpressDraftUrl();
  269.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_DRAFT ));
  270.             })
  271.             ->setHtmlAttributes(['target' => '_blank'])
  272.         ;
  273.         $exportOriginalCopy Action::new('exportOriginalCopy''Export Original Copy''')
  274.             ->linkToCrudAction('exportOriginalCopy')
  275.             ->displayIf(static function ($entity) {
  276.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  277.                 return !empty($filmProjectOriginalCopy);
  278.             })
  279.         ;
  280.         $exportCurrentVersionCopy Action::new('exportCurrentVersionCopy''Export Current Version''')
  281.             ->linkToCrudAction('exportCurrentVersionCopy')
  282.             ->displayIf(static function ($entity) {
  283.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  284.                 return !empty($filmProjectOriginalCopy);
  285.             })
  286.         ;
  287.         $exportOriginalCopies Action::new('exportOriginalCopies''Export Original Copy')
  288.             ->linkToCrudAction('exportOriginalCopies')
  289.         ;
  290.         $exportCurrentVersionCopies Action::new('exportCurrentVersionCopies''Export Current Version')
  291.             ->linkToCrudAction('exportCurrentVersionCopies')
  292.         ;
  293.         $publishProjects Action::new('publishProjects''Publish')
  294.             ->linkToCrudAction('publishProjects')
  295.             ->addCssClass('wordpress-action')
  296.         ;
  297.         $unpublishProjects Action::new('unpublishProjects''Unpublish')
  298.             ->linkToCrudAction('unpublishProjects')
  299.             ->addCssClass('wordpress-action')
  300.         ;
  301.         $archiveProjects Action::new('archiveProjects''Archive')
  302.             ->linkToCrudAction('archiveProjects')
  303.             ->addCssClass('wordpress-action')
  304.         ;
  305.         $viewProject Action::new('viewProject''View Project''')
  306.             ->linktoCrudACtion('viewProject')
  307.             ->displayIf(static function ($entity) {
  308.                 $status $entity->getWordpressStatus();
  309.                 $url $entity->getWordpressUrl();
  310.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_PUBLISH ));
  311.             })
  312.             ->setHtmlAttributes(['target' => '_blank'])
  313.         ;
  314.         $makePrivateProjects Action::new('makePrivateProjects''Make Password Protected')
  315.             ->linkToCrudAction('makePrivateProjects')
  316.         ;
  317.         $makeHiddenProjects Action::new('makeHiddenProjects''Hide project')
  318.             ->linkToCrudAction('makeHiddenProjects')
  319.         ;
  320.         $editProject Action::new('editProject''Edit Project')
  321.             ->linkToCrudAction(Action::EDIT)
  322.             ->displayIf(static function ($entity) {
  323.                 $isDisplay false;
  324.                 $status $entity->getStatus();
  325.                 if ($status != 'approved' && $status != 'declined') {
  326.                     $isDisplay true;
  327.                 }
  328.                 return $isDisplay;
  329.             })
  330.         ;
  331.         $hideDonationBox Action::new('hideDonationBox''Hide Donation Box')
  332.             ->linkToCrudAction('hideDonationBox')
  333.             ->displayIf(static function ($entity) {
  334.                 $wpStatus $entity->getStatus();
  335.                 $status $entity->isIsHideDonationBox();
  336.                 $isProgressReportActive $entity->isIsProgressReportActive();
  337.                 if ($isProgressReportActive) {
  338.                     return (!$status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  339.                 }
  340.                 // return (!$status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  341.                 return (!$status && $wpStatus == 'approved');
  342.             })
  343.         ;
  344.         $showDonationBox Action::new('showDonationBox''Show Donation Box')
  345.             ->linkToCrudAction('showDonationBox')
  346.             ->displayIf(static function ($entity) {
  347.                 $wpStatus $entity->getStatus();
  348.                 $status $entity->isIsHideDonationBox();
  349.                 $isProgressReportActive $entity->isIsProgressReportActive();
  350.                 if ($isProgressReportActive) {
  351.                     return ($status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  352.                 }
  353.                 // return ($status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  354.                 return ($status && $wpStatus == 'approved');
  355.             })
  356.         ;
  357.         $updateProjectDetails Action::new('updateProjectDetails''Edit Project')
  358.             ->linkToCrudAction('updateProjectDetails')
  359.             ->displayIf(static function ($entity) {
  360.                 $status $entity->getStatus();
  361.                 return ($status == 'approved');
  362.             })
  363.         ;
  364.         $viewProjectUpdates Action::new('viewProjectUpdates''View Updates')
  365.             ->linkToCrudAction('viewProjectUpdates')
  366.             ->displayIf(static function ($entity) {
  367.                 $status $entity->getStatus();
  368.                 $isProgressReportActive $entity->isIsProgressReportActive();
  369.                 if ($isProgressReportActive) {
  370.                     return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  371.                 }
  372.                 
  373.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  374.                 return $status == 'approved';
  375.             })
  376.         ;
  377.         $addProjectUpdates Action::new('addProjectUpdates''Add an update')
  378.             ->linkToCrudAction('addProjectUpdates')
  379.             ->displayIf(static function ($entity) {
  380.                 $status $entity->getStatus();
  381.                 $isProgressReportActive $entity->isIsProgressReportActive();
  382.                 if ($isProgressReportActive) {
  383.                     return ($status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  384.                 }
  385.                 return $status == 'approved';
  386.                 // return $status == 'approved';
  387.             })
  388.         ;
  389.         $manageMedia Action::new('manageMedia''Manage Image Gallery')
  390.             ->linkToCrudAction('manageMedia')
  391.             ->displayIf(static function ($entity) {
  392.                 $status $entity->getStatus();
  393.                 $isProgressReportActive $entity->isIsProgressReportActive();
  394.                 if ($isProgressReportActive) {
  395.                     return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  396.                 }
  397.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  398.                 return $status == 'approved';
  399.             })
  400.         ;
  401.         $managePartner Action::new('managePartner''Manage Impact Partner')
  402.             ->linkToCrudAction('managePartner')
  403.             ->displayIf(static function ($entity) {
  404.                 $status $entity->getStatus();
  405.                 $isProgressReportActive $entity->isIsProgressReportActive();
  406.                 if ($isProgressReportActive) {
  407.                     return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  408.                 }
  409.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  410.                 return $status == 'approved';
  411.             })
  412.         ;
  413.           
  414.         $downloadReport Action::new('downloadReport''Download Application')
  415.             ->linkToCrudAction('downloadReport')
  416.             ->displayIf(static function ($entity) {
  417.                 $status $entity->getStatus();
  418.                 return $status == 'approved';
  419.             })
  420.         ;
  421.         $exportDonorList Action::new('exportDonorList''Export Donor List')
  422.             ->linkToCrudAction('exportDonorList')
  423.             ->displayIf(static function ($entity) {
  424.                 $status $entity->getStatus();
  425.                 $oldWordpressId $entity->getOldWordpressId();
  426.                 return ($status == 'approved' && !$oldWordpressId);
  427.             })
  428.         ;
  429.         $viewProgressReport Action::new('viewProgressReport''View Progress Report')
  430.             ->setHtmlAttributes(['target' => '_blank'])
  431.             ->linkToCrudAction('viewProgressReport')
  432.             ->setCssClass('view-progress-report-action')
  433.             ->displayIf(static function ($entity) {
  434.                 $status $entity->getProgressReportStatusUpdate();
  435.                 return $status != 'complete' && $status != 'not_available';
  436.             })
  437.         ;
  438.         $viewSingleProgressReport Action::new('viewSingleProgressReport''View Progress Report')
  439.             ->setHtmlAttributes(['target' => '_blank'])
  440.             ->linkToCrudAction('viewProgressReport')
  441.             ->setCssClass('view-progress-report-action')
  442.             ->displayIf(static function ($entity) {
  443.                 $status $entity->getProgressReportStatusUpdate();
  444.                 $isActive $entity->isIsprogressReportActive();
  445.                 return $isActive && $status != 'complete' && $status != 'not_available';
  446.             })
  447.         ;
  448.         // $submitProjectAsAdmin = Action::new('submitProjectAsAdmin', 'Submit Project', '')
  449.         //     ->linkToCrudAction('submitProjectAsAdmin')
  450.         //     ->displayIf(static function ($entity) {
  451.         //         $status = $entity->getStatus();
  452.         //         return $status == 'draft' || $status == 'resubmit';
  453.         //     })
  454.         // ;
  455.         $exportAllProjects Action::new('exportAllProjects''Export all projects')
  456.             ->linkToUrl('/admin/project/export-all')
  457.             ->createAsGlobalAction()
  458.             ->addCssClass('btn btn-primary me-2 d-block')
  459.         ;
  460.         $exportAllDonations Action::new('exportAllDonations''Export Donations''')
  461.             ->linkToCrudAction('exportAllDonations')
  462.             ->displayIf(static function ($entity) {
  463.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  464.                 return !empty($filmProjectOriginalCopy);
  465.             })
  466.         ;
  467.         // $exportDonorList->setCssClass('d-none');
  468.         // $exportAllDonations->setCssClass('d-none');
  469.         $toggleOnProgressReportStatus Action::new('toggleOnProgressReportStatus''Turn on Progress Report')
  470.             ->linkToUrl(function(FilmProject $project) {
  471.                 return '/admin/progress-report/workflow/cron/single/'$project->getId();
  472.             })
  473.             ->displayIf(static function ($entity) {
  474.                 return !$entity->isIsProgressReportActive();
  475.             })
  476.         ;
  477.         $toggleOffProgressReportStatus Action::new('toggleOffProgressReportStatus''Turn off Progress Report')
  478.             ->linkToUrl(function(FilmProject $project) {
  479.                 return '/admin/progress-report/workflow/cron/single/'$project->getId();
  480.             })
  481.             ->displayIf(static function ($entity) {
  482.                 return $entity->isIsProgressReportActive();
  483.             })
  484.         ;
  485.         $downloadProgressReport Action::new('downloadProgressReport''Download Progress Report''')
  486.             ->linkToCrudAction('downloadProgressReport')
  487.             // ->displayIf(static function ($entity) {
  488.             //     return $entity->isIsProgressReportActive();
  489.             // })
  490.         ;
  491.         if ($isProgressReport) {
  492.             // $updateProjectDetails->setCssClass('d-none');
  493.             $hideDonationBox->setCssClass('progress-report-action');
  494.             $showDonationBox->setCssClass('progress-report-action');
  495.             $manageMedia->setCssClass('progress-report-action');
  496.             $managePartner->setCssClass('progress-report-action');
  497.             $addProjectUpdates->setCssClass('progress-report-action');
  498.             $viewProjectUpdates->setCssClass('progress-report-action');
  499.             // $downloadProgressReport->setCssClass('progress-report-action');
  500.         }
  501.         $actions
  502.             ->add(Crud::PAGE_INDEX$editProject)
  503.             ->add(Crud::PAGE_INDEX$updateProjectDetails)
  504.             ->add(Crud::PAGE_INDEX$viewProjectUpdates)
  505.             ->add(Crud::PAGE_INDEX$addProjectUpdates)
  506.             ->add(Crud::PAGE_INDEX$manageMedia)
  507.             ->add(Crud::PAGE_INDEX$managePartner)
  508.             ->add(Crud::PAGE_INDEX$hideDonationBox)
  509.             ->add(Crud::PAGE_INDEX$showDonationBox)
  510.             ->add(Crud::PAGE_INDEX$downloadReport)
  511.             ->add(Crud::PAGE_INDEX$exportDonorList)
  512.             ->add(Crud::PAGE_INDEX$viewWordpressLink)
  513.             ->add(Crud::PAGE_INDEX$viewDraftWordpressLink)
  514.             ->add(Crud::PAGE_INDEX$exportAllProjects)
  515.             ->add(Crud::PAGE_INDEX$exportAllDonations)
  516.             ->add(Crud::PAGE_INDEX$toggleOnProgressReportStatus)
  517.             ->add(Crud::PAGE_INDEX$toggleOffProgressReportStatus)
  518.             // ->add(Crud::PAGE_INDEX, $viewSingleProgressReport)
  519.             ->add(Crud::PAGE_INDEX$downloadProgressReport)
  520.             ->add(Crud::PAGE_NEW$backAction)
  521.             ->add(Crud::PAGE_NEW$saveDraft)
  522.             // ->add(Crud::PAGE_NEW, Action::INDEX)
  523.             ->add(Crud::PAGE_NEWAction::SAVE_AND_CONTINUE)
  524.             ->add(Crud::PAGE_EDIT$backAction)
  525.             ->add(Crud::PAGE_EDIT$saveDraft)
  526.             ->add(Crud::PAGE_EDIT$exportOriginalCopy)
  527.             ->add(Crud::PAGE_EDIT$exportCurrentVersionCopy)
  528.             // ->add(Crud::PAGE_EDIT, $submitProjectAsAdmin)
  529.             // ->add(Crud::PAGE_EDIT, Action::INDEX)
  530.             ->add(Crud::PAGE_EDIT$viewProject)
  531.             ->add(Crud::PAGE_EDITAction::DELETE)
  532.             ->addBatchAction($exportOriginalCopies)
  533.             ->addBatchAction($exportCurrentVersionCopies)
  534.             ->addBatchAction($publishProjects)
  535.             ->addBatchAction($unpublishProjects)
  536.             ->addBatchAction($archiveProjects)
  537.             ->addBatchAction($makePrivateProjects)
  538.             ->addBatchAction($makeHiddenProjects)
  539.             ->update(Crud::PAGE_INDEXAction::NEW, function (Action $action) {
  540.                 return $action->setLabel('Start an Application');
  541.             })
  542.             // ->update(Crud::PAGE_NEW, Action::INDEX, function (Action $action) {
  543.             //     return $action
  544.             //         ->setLabel('<i class="fa-fw fa fa-list me-1"></i> View Project')
  545.             //         ->setCssClass('me-3 link-primary fw-bold')
  546.             //     ;
  547.             // })
  548.             ->update(Crud::PAGE_NEWAction::SAVE_AND_RETURN, function (Action $action) {
  549.                 return $action->setLabel('Next');
  550.             })
  551.             ->update(Crud::PAGE_NEW$saveDraft, function (Action $action) {
  552.                 return $action->addCssClass('ms-2 px-4 btn btn-secondary action-saveDraft');
  553.             })  
  554.             ->update(Crud::PAGE_NEW$backAction, function (Action $action) {
  555.                 return $action->addCssClass('btn btn-primary d-none action-backAction me-2')->setLabel('Back');
  556.             })
  557.             
  558.             ->update(Crud::PAGE_EDIT$viewProject, function (Action $action) {
  559.                 return $action
  560.                     ->setLabel('<i class="fa-fw fa fa-list me-1"></i> View Project')
  561.                     ->setCssClass('mx-3 link-primary fw-bold')
  562.                 ;
  563.             })
  564.             ->update(Crud::PAGE_EDITAction::SAVE_AND_RETURN, function (Action $action) {
  565.                 return $action->setLabel('Next');
  566.             })     
  567.             ->update(Crud::PAGE_EDIT$saveDraft, function (Action $action) {
  568.                 return $action->addCssClass('ms-2 px-4 btn btn-secondary action-saveDraft');
  569.             })
  570.             ->update(Crud::PAGE_EDIT$backAction, function (Action $action) {
  571.                 return $action->addCssClass('btn btn-primary d-none action-backAction me-2')->setLabel('Back');
  572.             })
  573.             ->update(Crud::PAGE_EDIT$exportOriginalCopy, function (Action $action) {
  574.                 return $action->addCssClass('btn btn-secondary me-2')->setLabel('Export Original Version');
  575.             })
  576.             ->update(Crud::PAGE_EDIT$exportCurrentVersionCopy, function (Action $action) {
  577.                 return $action->addCssClass('btn btn-secondary me-2')->setLabel('Export Current Version');
  578.             })
  579.             // ->update(Crud::PAGE_EDIT, $submitProjectAsAdmin, function (Action $action) {
  580.             //     return $action->addCssClass('btn btn-primary me-2 order-1')->setLabel('Submit Project');
  581.             // })
  582.             ->remove(Crud::PAGE_INDEXAction::EDIT)
  583.             ->setPermission($exportOriginalCopyConstant::ADMIN_ROLE)
  584.             ->setPermission($exportCurrentVersionCopyConstant::ADMIN_ROLE)
  585.             ->setPermission($publishProjectsConstant::ADMIN_ROLE)
  586.             ->setPermission($unpublishProjectsConstant::ADMIN_ROLE)
  587.             ->setPermission($archiveProjectsConstant::ADMIN_ROLE)
  588.             ->setPermission($makePrivateProjectsConstant::ADMIN_ROLE)
  589.             ->setPermission($makeHiddenProjectsConstant::ADMIN_ROLE)
  590.             ->setPermission(Action::DELETEConstant::ADMIN_ROLE)
  591.             ->setPermission(Action::BATCH_DELETEConstant::ADMIN_ROLE)
  592.             ->setPermission($exportAllProjectsConstant::ADMIN_ROLE)
  593.             ->setPermission($viewDraftWordpressLinkConstant::ADMIN_ROLE)
  594.             ->setPermission($exportAllDonationsConstant::ADMIN_ROLE)
  595.             ->setPermission($toggleOnProgressReportStatusConstant::ADMIN_ROLE)
  596.             ->setPermission($toggleOffProgressReportStatusConstant::ADMIN_ROLE)
  597.             // ->setPermission($submitProjectAsAdmin, Constant::ADMIN_ROLE)
  598.             ->reorder(Crud::PAGE_INDEX, ['viewDraftWordpressLink''viewWordpressLink''editProject''updateProjectDetails''showDonationBox''hideDonationBox''manageMedia''managePartner''addProjectUpdates''viewProjectUpdates''exportAllDonations''downloadReport''downloadProgressReport''exportDonorList''toggleOnProgressReportStatus''toggleOffProgressReportStatus'Action::DELETE])
  599.             ->reorder(Crud::PAGE_EDIT, [Action::DELETE'viewProject''backAction''saveDraft''exportOriginalCopy''exportCurrentVersionCopy'Action::SAVE_AND_RETURN])
  600.             ->reorder(Crud::PAGE_NEW, ['backAction''saveDraft'Action::SAVE_AND_RETURN])
  601.         ;
  602.         if ($isProgressReport) {
  603.             $actions
  604.                 ->add(Crud::PAGE_INDEX$viewProgressReport)
  605.                 ->update(Crud::PAGE_INDEX$updateProjectDetails, function(Action $action) {
  606.                     return $action->setLabel('View Project Details');
  607.                 })
  608.             ;
  609.         } else {
  610.             $actions
  611.                 ->add(Crud::PAGE_INDEX$viewSingleProgressReport)
  612.             ;
  613.         }
  614.         return $actions;
  615.     }
  616.     public function configureFilters(Filters $filters): Filters
  617.     {
  618.         // Get current user profile
  619.         $user $this->getUser();
  620.         
  621.         if ($user->isAdmin()) {
  622.             $filters $filters
  623.                 ->add('owner')
  624.                 ->add(EntityFilter::new('filmProjectAdmin''Project Admin'))
  625.             ;
  626.         }
  627.         return $filters;
  628.     }
  629.     protected function getRedirectResponseAfterSave(AdminContext $contextstring $action): RedirectResponse
  630.     {
  631.         $submitButtonName $context->getRequest()->request->all()['ea']['newForm']['btn'];
  632.         $user $this->getUser();
  633.         // if (!$user->isAdmin()) { // IF USER IS NOT ADMIN
  634.         if (Action::SAVE_AND_CONTINUE === $submitButtonName) { // SAVE DRAFT RESPONSE
  635.             $entityInstance $context->getEntity()->getInstance();
  636.             
  637.             $this->filmApplicationService->setFilmProjectToDraft($entityInstance);
  638.             $this->addFlash('success''Your draft has been saved.');
  639.             $url $this->container->get(AdminUrlGenerator::class)
  640.                 ->setAction(Action::EDIT)
  641.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  642.                 ->generateUrl();
  643.             return $this->redirect($url);
  644.         }
  645.         if (Action::SAVE_AND_RETURN === $submitButtonName) { // FINISH APPLICATION RESPONSE
  646.             $entityInstance $context->getEntity()->getInstance();
  647.             $user $this->getUser();
  648.             // Save everything before 
  649.             $this->em->persist($entityInstance);
  650.             $this->em->flush();
  651.             // Check if image exists
  652.             $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  653.             if (!$isImage) {
  654.                 $backUrl $this->container->get(AdminUrlGenerator::class)
  655.                     ->setAction(Action::EDIT)
  656.                     ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  657.                     ->generateUrl();
  658.                 $this->addFlash('notice''Image in Project Details Tab is required.');
  659.                 return $this->redirect($backUrl);
  660.             }
  661.             if (!$entityInstance->getResubmitCount()) {
  662.                 $this->filmApplicationService->proceedPayment($entityInstance);
  663.             }
  664.             $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  665.             $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  666.             $this->filmApplicationService->generateSponsorsFromText($entityInstance); 
  667.             
  668.             $this->handleWordpressEndpoint($entityInstance); // handles Wordpress creation and update
  669.             $this->handleSalesforceEndpoint($entityInstance$user); // handles Salesforce creation and update
  670.             
  671.             if (!$entityInstance->getResubmitCount()) { 
  672.                 $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);
  673.                 $this->filmApplicationService->sendEmail($entityInstance);
  674.             }
  675.             
  676.             $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  677.             $url $this->container->get(AdminUrlGenerator::class)
  678.                 ->setController(PendingFilmProjectCrudController::class)
  679.                 ->setAction(Action::INDEX)
  680.                 ->generateUrl();
  681.             return $this->redirect($url);
  682.         }
  683.         if (Action::SAVE_AND_ADD_ANOTHER === $submitButtonName) {
  684.             $url $this->container->get(AdminUrlGenerator::class)->setAction(Action::NEW)->generateUrl();
  685.             return $this->redirect($url);
  686.         }
  687.         return $this->redirectToRoute($context->getDashboardRouteName());
  688.     }
  689.     private function handleWordpressEndpoint(FilmProject $entityInstance) {
  690.         $wordpressId $entityInstance->getWordpressId();
  691.         $oldWordpressId $entityInstance->getOldWordpressId();
  692.                
  693.         if ($wordpressId && $wordpressId != $oldWordpressId) {
  694.             $this->filmApplicationService->updateWordpressObject($entityInstance);
  695.         } else {
  696.             $this->filmApplicationService->createWordpressObject($entityInstance);
  697.         }
  698.     }
  699.     private function handleSalesforceEndpoint(FilmProject $entityInstance$user null) {
  700.         $salesforceCampaignId $entityInstance->getSalesforceId();
  701.         if ($salesforceCampaignId) {
  702.             $this->filmApplicationService->updateCampaignSalesforce($entityInstance);
  703.         } else {
  704.             $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  705.         }
  706.         
  707.         if (empty($orderDetailsSalesforceId) && empty($oldWordpressId) && !$user->isAdmin() && !$entityInstance->getResubmitCount()) {
  708.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  709.         }
  710.         if ($user->isAdmin()) {
  711.             $this->filmApplicationService->updateCampaignSalesforceAdmin($entityInstance);
  712.         }
  713.     }
  714.     public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  715.     {
  716.         if ( $_GET['crudAction'] === Action::EDIT) {
  717.             $filmProject $this->getFilmProjectFromEntityId();
  718.             if ($filmProject) {
  719.                 $responseParameters
  720.                     ->set('filmProject'$filmProject)
  721.                 ;
  722.             }
  723.         }
  724.         $product $this->filmApplicationService->getDefaultProduct();
  725.         $cards $this->userBillingService->getCurrentSavedCards(); // Get saved cards
  726.         $responseParameters->setAll([
  727.             'product' => $product,
  728.             'cards' => $cards,
  729.         ]);
  730.         return $responseParameters;
  731.     }
  732.     // Custom Actions
  733.     public function saveDraft(AdminContext $context): Response
  734.     {
  735.         $entityInstance $context->getEntity()->getInstance();
  736.         $entityInstance->setStatus('draft');
  737.         if ( $entityInstance->getResubmitCount() ) {
  738.             $entityInstance->setStatus('resubmit');
  739.         }
  740.         
  741.         $this->em->persist($entityInstance);
  742.         $this->em->flush();
  743.         $this->addFlash('success''Your draft has been saved');
  744.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(DraftFilmProjectCrudController::class)
  745.             ->setAction(Action::INDEX)
  746.             ->generateUrl();
  747.         return new RedirectResponse($filmProjectIndexUrl);
  748.     }
  749.     
  750.     public function exportOriginalCopy(AdminContext $context): Response
  751.     {
  752.         $entityInstance $context->getEntity()->getInstance();
  753.         $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal()->getData();
  754.         $csvExporter = new CsvExporter();
  755.         $csvExporter->exportArrayToCsv($filmProjectOriginalCopy$entityInstance->getTitle() .'-V1.csv');
  756.         $this->addFlash('success''Your original copy has been exported');
  757.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  758.             ->setAction(Action::INDEX)
  759.             ->generateUrl();
  760.         return new RedirectResponse($filmProjectIndexUrl);
  761.     }
  762.     public function exportCurrentVersionCopy(AdminContext $context): Response
  763.     {
  764.         $entityInstance $context->getEntity()->getInstance();
  765.         $filmProjectConverter = new FilmProjectObjectConverter();
  766.         $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  767.         $csvExporter = new CsvExporter();
  768.         $csvExporter->exportArrayToCsv($serializedFilmProject$entityInstance->getTitle() .'.csv');
  769.         $this->addFlash('success''Your current version project has been exported');
  770.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  771.             ->setAction(Action::INDEX)
  772.             ->generateUrl();
  773.         return new RedirectResponse($filmProjectIndexUrl);
  774.     }
  775.     public function updateProjectDetails(AdminContext $context): Response
  776.     {
  777.         $entityInstance $context->getEntity()->getInstance();
  778.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  779.             ->setAction(Action::EDIT)
  780.             ->setEntityId($entityInstance->getId())
  781.             ->generateUrl();
  782.         if ($entityInstance->isIsProgressReportActive() && $entityInstance->getProgressReportStatusUpdate() != 'complete') {
  783.             $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  784.                 ->setAction(Action::EDIT)
  785.                 ->setEntityId($entityInstance->getId())
  786.                 ->set('disableFields'"true"
  787.                 ->generateUrl()
  788.             ;
  789.         }
  790.         return new RedirectResponse($projectUpdateUrl);
  791.     }
  792.     public function viewProjectUpdates(AdminContext $context): Response
  793.     {
  794.         $entityInstance $context->getEntity()->getInstance();
  795.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  796.             ->setAction(Action::INDEX)
  797.             ->unset('entityId')
  798.             ->set('project'$entityInstance->getId())
  799.             ->generateUrl();
  800.         return new RedirectResponse($projectUpdateUrl);
  801.     }
  802.     public function addProjectUpdates(AdminContext $context): Response
  803.     {
  804.         $entityInstance $context->getEntity()->getInstance();
  805.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  806.             ->setAction(Action::NEW)
  807.             ->unset('entityId')
  808.             ->set('project'$entityInstance->getId())
  809.             ->generateUrl();
  810.         return new RedirectResponse($projectUpdateUrl);
  811.     }
  812.     public function manageMedia(AdminContext $context): Response
  813.     {
  814.         $entityInstance $context->getEntity()->getInstance();
  815.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectMediaCrudController::class)
  816.             ->setAction(Action::EDIT)
  817.             ->setEntityId($entityInstance->getId())
  818.             ->generateUrl();
  819.         return new RedirectResponse($projectUpdateUrl);
  820.     }
  821.     public function managePartner(AdminContext $context): Response
  822.     {
  823.         $entityInstance $context->getEntity()->getInstance();
  824.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectPartnerCrudController::class)
  825.             ->setAction(Action::EDIT)
  826.             ->setEntityId($entityInstance->getId())
  827.             ->generateUrl();
  828.         return new RedirectResponse($projectUpdateUrl);
  829.     }
  830.     /**
  831.      * BATCH ACTION: export original version
  832.      *
  833.      * @param BatchActionDto $batchActionDto
  834.      * @return void
  835.      */
  836.     public function exportOriginalCopies(BatchActionDto $batchActionDto)
  837.     {
  838.         $className $batchActionDto->getEntityFqcn();
  839.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  840.         
  841.         $filmProjectOriginalCopies = [];
  842.         foreach ($batchActionDto->getEntityIds() as $id) {
  843.             $entityInstance $entityManager->find($className$id);
  844.             $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal();
  845.             if (empty($filmProjectOriginalCopy)) {
  846.                 $this->addFlash('warning''Only approved projects can be exported into CSV');
  847.                 return $this->redirect($batchActionDto->getReferrerUrl());
  848.             }
  849.             array_push($filmProjectOriginalCopies$filmProjectOriginalCopy->getData());
  850.         }
  851.         
  852.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  853.         $csvExporter = new CsvExporter();
  854.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects_V1-'$dateValue .'.xlsx');
  855.    
  856.         // return $this->redirect($batchActionDto->getReferrerUrl());
  857.     }
  858.     /**
  859.      * BATCH: Export current version copy
  860.      *
  861.      * @param BatchActionDto $batchActionDto
  862.      * @return void
  863.      */
  864.     public function exportCurrentVersionCopies(BatchActionDto $batchActionDto)
  865.     {
  866.         $className $batchActionDto->getEntityFqcn();
  867.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  868.         
  869.         $filmProjectConverter = new FilmProjectObjectConverter();
  870.         $filmProjectOriginalCopies = [];
  871.         foreach ($batchActionDto->getEntityIds() as $id) {
  872.             $entityInstance $entityManager->find($className$id);
  873.             $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  874.             array_push($filmProjectOriginalCopies$serializedFilmProject);
  875.         }
  876.         
  877.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  878.         $csvExporter = new CsvExporter();
  879.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects-'$dateValue .'.xlsx');
  880.     
  881.         // return $this->redirect($batchActionDto->getReferrerUrl());
  882.     }
  883.     /**
  884.      * BATCH: Publish projects
  885.      *
  886.      * @param BatchActionDto $batchActionDto
  887.      * @return void
  888.      */
  889.     public function publishProjects(BatchActionDto $batchActionDto)
  890.     {
  891.         $className $batchActionDto->getEntityFqcn();
  892.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  893.         // Check if there is non-approved projects
  894.         foreach ($batchActionDto->getEntityIds() as $id) {
  895.             $entityInstance $entityManager->find($className$id);
  896.             
  897.             if ($entityInstance->getStatus() != 'approved') {
  898.                 $this->addFlash('notice''Project(s) have to be approved before being published.');
  899.                 return $this->redirect($batchActionDto->getReferrerUrl());
  900.             }
  901.         }
  902.         foreach ($batchActionDto->getEntityIds() as $id) {
  903.             $entityInstance $entityManager->find($className$id);
  904.             $this->filmApplicationService->publishProject($entityInstance);
  905.         }
  906.         $this->addFlash('success''Project(s) have been published');
  907.         return $this->redirect($batchActionDto->getReferrerUrl());
  908.     }
  909.     /**
  910.      * BATCH: Unublish projects
  911.      *
  912.      * @param BatchActionDto $batchActionDto
  913.      * @return void
  914.      */
  915.     public function unpublishProjects(BatchActionDto $batchActionDto)
  916.     {
  917.         $className $batchActionDto->getEntityFqcn();
  918.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  919.         // Check if there is non-approved projects
  920.         foreach ($batchActionDto->getEntityIds() as $id) {
  921.             $entityInstance $entityManager->find($className$id);
  922.             
  923.             if ($entityInstance->getStatus() != 'approved') {
  924.                 $this->addFlash('notice''Project(s) have to be approved before being unpublished.');
  925.                 return $this->redirect($batchActionDto->getReferrerUrl());
  926.             }
  927.         }
  928.         foreach ($batchActionDto->getEntityIds() as $id) {
  929.             $entityInstance $entityManager->find($className$id);
  930.             $this->filmApplicationService->unpublishProject($entityInstance);
  931.         }
  932.         $this->addFlash('success''Project(s) have been unpublished');
  933.         return $this->redirect($batchActionDto->getReferrerUrl());
  934.     }
  935.     public function viewProject(AdminContext $adminContext)
  936.     {
  937.         $entityInstance $adminContext->getEntity()->getInstance();
  938.         return $this->redirect($entityInstance->getWordpressUrl());
  939.     }
  940.     /**
  941.      * BATCH: archive projects
  942.      *
  943.      * @param BatchActionDto $batchActionDto
  944.      * @return void
  945.      */
  946.     public function archiveProjects(BatchActionDto $batchActionDto)
  947.     {
  948.         $className $batchActionDto->getEntityFqcn();
  949.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  950.         // Check if there is non-approved projects
  951.         foreach ($batchActionDto->getEntityIds() as $id) {
  952.             $entityInstance $entityManager->find($className$id);
  953.             
  954.             if ($entityInstance->getStatus() != 'approved') {
  955.                 $this->addFlash('notice''Project(s) have to be approved before being archived.');
  956.                 return $this->redirect($batchActionDto->getReferrerUrl());
  957.             }
  958.         }
  959.         foreach ($batchActionDto->getEntityIds() as $id) {
  960.             $entityInstance $entityManager->find($className$id);
  961.             $this->filmApplicationService->archiveProject($entityInstance);
  962.         }
  963.         $this->addFlash('success''Project(s) have been archived');
  964.         return $this->redirect($batchActionDto->getReferrerUrl());
  965.     }
  966.     /**
  967.      * BATCH: Make private projects
  968.      *
  969.      * @param BatchActionDto $batchActionDto
  970.      * @return void
  971.      */
  972.     public function makePrivateProjects(BatchActionDto $batchActionDto)
  973.     {
  974.         $postPassword '';
  975.         if (isset($_COOKIE['postpassword'])) {
  976.             $postPassword $_COOKIE['postpassword'];
  977.         }
  978.         if ($postPassword) {
  979.             $className $batchActionDto->getEntityFqcn();
  980.             $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  981.             foreach ($batchActionDto->getEntityIds() as $id) {
  982.                 $entityInstance $entityManager->find($className$id);
  983.                 $this->filmApplicationService->makePrivateProject($entityInstance$postPassword);
  984.             }
  985.         }
  986.         $this->addFlash('success''Project(s) have been made private');
  987.         return $this->redirect($batchActionDto->getReferrerUrl());
  988.     }
  989.     public function downloadReport(AdminContext $contextEnvironment $twig nullPdf $pdf)
  990.     {
  991.         $filmProject $context->getEntity()->getInstance();
  992.         $pdfExporter = new PdfExporter($twig$pdf);
  993.         $pdfExporter->convertProjectToPdf($filmProject);
  994.     }
  995.     public function hideDonationBox(AdminContext $adminContext)
  996.     {
  997.         $entityInstance $adminContext->getEntity()->getInstance();
  998.         $this->filmApplicationService->hideDonationBox($entityInstance);
  999.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been hidden.');
  1000.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1001.             ->setAction(Action::INDEX)
  1002.             ->generateUrl();
  1003.         return new RedirectResponse($filmProjectIndexUrl);
  1004.     }
  1005.     public function showDonationBox(AdminContext $adminContext)
  1006.     {
  1007.         $entityInstance $adminContext->getEntity()->getInstance();
  1008.         $this->filmApplicationService->showDonationBox($entityInstance);
  1009.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been displayed.');
  1010.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1011.             ->setAction(Action::INDEX)
  1012.             ->generateUrl();
  1013.         return new RedirectResponse($filmProjectIndexUrl);
  1014.     }
  1015.     public function submitProjectAsAdmin(AdminContext $context
  1016.     {
  1017.         $user $this->getUser();
  1018.         $entityInstance $context->getEntity()->getInstance();
  1019.         // Save everything before 
  1020.         $this->em->persist($entityInstance);
  1021.         $this->em->flush();
  1022.         // Check if image exists
  1023.         $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  1024.         if (!$isImage) {
  1025.             $backUrl $this->container->get(AdminUrlGenerator::class)
  1026.                 ->setAction(Action::EDIT)
  1027.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  1028.                 ->generateUrl();
  1029.             $this->addFlash('notice''Image in Project Details Tab is required.');
  1030.             return $this->redirect($backUrl);
  1031.         }
  1032.         $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  1033.         $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  1034.         
  1035.         $this->filmApplicationService->generateSponsorsFromText($entityInstance);
  1036.         $this->filmApplicationService->createWordpressObject($entityInstance);
  1037.         $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  1038.         if (!$entityInstance->getOldWordpressId()) {
  1039.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  1040.         }
  1041.         
  1042.         if (!$entityInstance->getResubmitCount()) {
  1043.             $this->filmApplicationService->proceedPayment($entityInstance);
  1044.             $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);       
  1045.             $this->filmApplicationService->sendEmail($entityInstance);
  1046.         }
  1047.         
  1048.         $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  1049.         $url $this->container->get(AdminUrlGenerator::class)
  1050.             ->setController(PendingFilmProjectCrudController::class)
  1051.             ->setAction(Action::INDEX)
  1052.             ->generateUrl();
  1053.         return $this->redirect($url);
  1054.     }
  1055.     
  1056.     public function exportAllDonations(AdminContext $adminContext) {
  1057.         $entityInstance $adminContext->getEntity()->getInstance();
  1058.         $donationRepository $this->em->getRepository(Donation::class);
  1059.         $donations $donationRepository->findDonationsByProjectOrderDate($entityInstance->getId());
  1060.         $spreadsheet = new Spreadsheet();
  1061.         $sheet $spreadsheet->getActiveSheet();
  1062.         // Generate columns first
  1063.         $columnTitles = ["Order ID""Receipt ID""First Name""Last Name""Email""Organisation""Donation to""Wordpress ID""Is Anonymous""Total Amount""Pop-up Amount""Fundraising Goal""Date""Status""Salesforce ID""Xero Invoice ID""Xero Contact ID""Merchant Warrior ID"];
  1064.         $excelCol 'A';
  1065.         $excelRow 1;
  1066.         foreach($columnTitles as $columnTitle) {
  1067.             $currentPosition $excelCol .''$excelRow;
  1068.             $sheet->setCellValue($currentPosition$columnTitle)->getColumnDimension($excelCol)->setAutoSize(TRUE);
  1069.             $excelCol++;
  1070.         }
  1071.         $excelRow++;
  1072.         // Universal project field(s)
  1073.         $filmProjectFunding $entityInstance->getFilmProjectFunding();
  1074.         $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1075.         $fundraisingStatus 0;
  1076.         // After that, we generate data respectively
  1077.         $limit 2000;
  1078.         foreach ($donations as $donation) {
  1079.             // Universal project field(s)
  1080.             $project $donation->getFilmProject();
  1081.             $filmProjectFunding $project->getFilmProjectFunding();
  1082.             $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1083.             $orderDetails $donation->getOrderDetails();
  1084.             $orderBillingDetails $orderDetails->getOrderBillingDetails();
  1085.             $paymentDetails $orderDetails->getPaymentDetails();
  1086.             $isAnonymous = (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent());
  1087.             $isAnon =  (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent()) ? 'yes' 'no';
  1088.             $totalAmount = (number_format((float)$orderDetails->getTotal() / 1002));
  1089.             if ($donation->getSupportDaf()) {
  1090.                 $totalAmount = (number_format(((float)$orderDetails->getTotal()- $donation->getSupportDaf()) / 1002));
  1091.             }
  1092.             $popupAmount = (number_format((float)$donation->getSupportDaf() / 1002));
  1093.             $isAnonymous = !$this->getUser()->isAdmin();
  1094.             $sheet->setCellValue('A'.$excelRow 'MW'.$orderDetails->getId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Order ID
  1095.             $sheet->setCellValue('B'.$excelRow $orderDetails->getInvoiceNumber())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Receipt ID
  1096.             $sheet->setCellValue('C'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getFirstName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // First Name
  1097.             $sheet->setCellValue('D'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getLastName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Last Name
  1098.             $sheet->setCellValue('E'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getEmailAddress())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Email
  1099.             $sheet->setCellValue('F'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getOrganisation())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Organisation
  1100.             $sheet->setCellValue('G'.$excelRow $donation->getFilmProject())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Donation to
  1101.             $sheet->setCellValue('H'.$excelRow , (string)$donation->getFilmProject()->getWordpressId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Wordpress ID
  1102.             $sheet->setCellValue('I'.$excelRow $isAnon)->getColumnDimension($excelCol)->setAutoSize(TRUE); // Is Anonymous
  1103.             $sheet->setCellValue('J'.$excelRow str_replace(","""$totalAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Total Amount
  1104.             $sheet->setCellValue('K'.$excelRow str_replace(","""$popupAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // pop-up Amount
  1105.             // $sheet->setCellValue('L'.$excelRow , str_replace(",", "", $fundraisingStatus))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Status
  1106.             $sheet->setCellValue('L'.$excelRow str_replace(","""$fundraisingGoal))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Goal
  1107.             $sheet->setCellValue('M'.$excelRow date_format($donation->getModifiedAt(), 'd/m/Y'))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Date
  1108.             $sheet->setCellValue('N'.$excelRow $paymentDetails->getStatus())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Status
  1109.             $sheet->setCellValue('O'.$excelRow $orderDetails->getSalesforceId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Salesforce ID
  1110.             $sheet->setCellValue('P'.$excelRow $orderDetails->getXeroId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Invoice ID
  1111.             $sheet->setCellValue('Q'.$excelRow $orderDetails->getXeroContactId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Contact ID
  1112.             $sheet->setCellValue('R'.$excelRow , ($orderDetails->getTransactionId()) ? $orderDetails->getTransactionId() : 'Manual Donation')->getColumnDimension($excelCol)->setAutoSize(TRUE); // Merchant Warrior ID
  1113.             $sheet->getStyle('J'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1114.             $sheet->getStyle('K'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1115.             $sheet->getStyle('L'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1116.             if ($excelRow $limit ) {
  1117.                 break;
  1118.             }
  1119.             $excelRow++;
  1120.         }
  1121.         ob_clean();
  1122.         $writer = new Xlsx($spreadsheet);
  1123.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1124.         header('Content-Disposition: attachment; filename="'$entityInstance->getTitle() .' donations.xlsx"');
  1125.         $writer->save('php://output');
  1126.         exit();
  1127.     }
  1128.     /**
  1129.      * Get film project from entity ID 
  1130.      *
  1131.      * @return FilmProject|null
  1132.      */
  1133.     protected function getFilmProjectFromEntityId(): ?FilmProject
  1134.     {
  1135.         $entityManager $this->container->get('doctrine')->getManagerForClass(FilmProject::class);
  1136.         $repository =  $entityManager->getRepository(FilmProject::class);
  1137.         $filmProject $repository->findOneBy(['id' => $_GET['entityId']]);
  1138.         return $filmProject;
  1139.     }
  1140.     protected function updateMainMembers(EntityManagerInterface $entityManagerFilmProject $entityInstance)
  1141.     {
  1142.         // Assign main members to project
  1143.         $administrator $entityInstance->getFilmProjectAdmin();
  1144.         $administrator->setAdminFilmProject($entityInstance);
  1145.         $entityManager->persist($administrator);
  1146.         $director $entityInstance->getFilmProjectDirector();
  1147.         $director->setDirectorFilmProject($entityInstance);
  1148.         $entityManager->persist($director);
  1149.         $producer $entityInstance->getFilmProjectProducer();
  1150.         $producer->setProducerFilmProject($entityInstance);
  1151.         $entityManager->persist($producer);
  1152.         $entityManager->flush();
  1153.     }
  1154.     /**
  1155.      * BATCH: Make hidden projects
  1156.      *
  1157.      * @param BatchActionDto $batchActionDto
  1158.      * @return void
  1159.      */
  1160.     public function makeHiddenProjects(BatchActionDto $batchActionDto)
  1161.     {
  1162.         $className $batchActionDto->getEntityFqcn();
  1163.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  1164.         foreach ($batchActionDto->getEntityIds() as $id) {
  1165.             $entityInstance $entityManager->find($className$id);
  1166.             $this->filmApplicationService->makeHiddenProject($entityInstance);
  1167.         }
  1168.         $this->addFlash('success''Project(s) have been made private');
  1169.         return $this->redirect($batchActionDto->getReferrerUrl());
  1170.     }
  1171.     public function exportDonorList(AdminContext $contextEntityManagerInterface $em
  1172.     {
  1173.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1174.         $donations $entityInstance->getDonations();
  1175.         
  1176.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  1177.         $csvExporter = new CsvExporter();
  1178.         $csvExporter->exportDonorList($donations$entityInstance->getTitle() .' Donor List -'$dateValue .'.xlsx'$this->getUser());
  1179.     }
  1180.     public function viewProgressReport(AdminContext $contextEntityManagerInterface $em)
  1181.     {
  1182.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1183.         $currentYear = (int) date('Y');
  1184.         $progressReportUrl '/progress-report/'$currentYear .'?projectId=' $entityInstance->getId();
  1185.         return $this->redirect($progressReportUrl);
  1186.     }
  1187.     public function downloadProgressReport(AdminContext $contextEnvironment $twig nullPdf $pdfEntityManagerInterface $em)
  1188.     {
  1189.         $filmProject $context->getEntity()->getInstance();
  1190.         $progressReportRepo $em->getRepository(FilmProjectProgressReport::class);
  1191.         $progressReport $progressReportRepo->findByYear((int)date("Y"), $filmProject->getId());
  1192.         if (empty($progressReport)) {
  1193.             $this->addFlash('Notice''Progress report is not available.');
  1194.             $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1195.                 ->setAction(Action::INDEX)
  1196.                 ->generateUrl();
  1197.             return new RedirectResponse($filmProjectIndexUrl);
  1198.         }
  1199.         $pdfExporter = new PdfExporter($twig$pdf);
  1200.         $pdfExporter->convertProgressReportToPdf($progressReport);
  1201.     }
  1202. }