src/Controller/Admin/FilmProjectCrudController.php line 92

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, ['viewSingleProgressReport''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.         }
  610.         return $actions;
  611.     }
  612.     public function configureFilters(Filters $filters): Filters
  613.     {
  614.         // Get current user profile
  615.         $user $this->getUser();
  616.         
  617.         if ($user->isAdmin()) {
  618.             $filters $filters
  619.                 ->add('owner')
  620.                 ->add(EntityFilter::new('filmProjectAdmin''Project Admin'))
  621.             ;
  622.         }
  623.         return $filters;
  624.     }
  625.     protected function getRedirectResponseAfterSave(AdminContext $contextstring $action): RedirectResponse
  626.     {
  627.         $submitButtonName $context->getRequest()->request->all()['ea']['newForm']['btn'];
  628.         $user $this->getUser();
  629.         // if (!$user->isAdmin()) { // IF USER IS NOT ADMIN
  630.         if (Action::SAVE_AND_CONTINUE === $submitButtonName) { // SAVE DRAFT RESPONSE
  631.             $entityInstance $context->getEntity()->getInstance();
  632.             
  633.             $this->filmApplicationService->setFilmProjectToDraft($entityInstance);
  634.             $this->addFlash('success''Your draft has been saved.');
  635.             $url $this->container->get(AdminUrlGenerator::class)
  636.                 ->setAction(Action::EDIT)
  637.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  638.                 ->generateUrl();
  639.             return $this->redirect($url);
  640.         }
  641.         if (Action::SAVE_AND_RETURN === $submitButtonName) { // FINISH APPLICATION RESPONSE
  642.             $entityInstance $context->getEntity()->getInstance();
  643.             $user $this->getUser();
  644.             // Save everything before 
  645.             $this->em->persist($entityInstance);
  646.             $this->em->flush();
  647.             // Check if image exists
  648.             $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  649.             if (!$isImage) {
  650.                 $backUrl $this->container->get(AdminUrlGenerator::class)
  651.                     ->setAction(Action::EDIT)
  652.                     ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  653.                     ->generateUrl();
  654.                 $this->addFlash('notice''Image in Project Details Tab is required.');
  655.                 return $this->redirect($backUrl);
  656.             }
  657.             if (!$entityInstance->getResubmitCount()) {
  658.                 $this->filmApplicationService->proceedPayment($entityInstance);
  659.             }
  660.             $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  661.             $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  662.             $this->filmApplicationService->generateSponsorsFromText($entityInstance); 
  663.             
  664.             $this->handleWordpressEndpoint($entityInstance); // handles Wordpress creation and update
  665.             $this->handleSalesforceEndpoint($entityInstance$user); // handles Salesforce creation and update
  666.             
  667.             if (!$entityInstance->getResubmitCount()) { 
  668.                 $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);
  669.                 $this->filmApplicationService->sendEmail($entityInstance);
  670.             }
  671.             
  672.             $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  673.             $url $this->container->get(AdminUrlGenerator::class)
  674.                 ->setController(PendingFilmProjectCrudController::class)
  675.                 ->setAction(Action::INDEX)
  676.                 ->generateUrl();
  677.             return $this->redirect($url);
  678.         }
  679.         if (Action::SAVE_AND_ADD_ANOTHER === $submitButtonName) {
  680.             $url $this->container->get(AdminUrlGenerator::class)->setAction(Action::NEW)->generateUrl();
  681.             return $this->redirect($url);
  682.         }
  683.         return $this->redirectToRoute($context->getDashboardRouteName());
  684.     }
  685.     private function handleWordpressEndpoint(FilmProject $entityInstance) {
  686.         $wordpressId $entityInstance->getWordpressId();
  687.         $oldWordpressId $entityInstance->getOldWordpressId();
  688.                
  689.         if ($wordpressId && $wordpressId != $oldWordpressId) {
  690.             $this->filmApplicationService->updateWordpressObject($entityInstance);
  691.         } else {
  692.             $this->filmApplicationService->createWordpressObject($entityInstance);
  693.         }
  694.     }
  695.     private function handleSalesforceEndpoint(FilmProject $entityInstance$user null) {
  696.         $salesforceCampaignId $entityInstance->getSalesforceId();
  697.         if ($salesforceCampaignId) {
  698.             $this->filmApplicationService->updateCampaignSalesforce($entityInstance);
  699.         } else {
  700.             $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  701.         }
  702.         
  703.         if (empty($orderDetailsSalesforceId) && empty($oldWordpressId) && !$user->isAdmin() && !$entityInstance->getResubmitCount()) {
  704.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  705.         }
  706.         if ($user->isAdmin()) {
  707.             $this->filmApplicationService->updateCampaignSalesforceAdmin($entityInstance);
  708.         }
  709.     }
  710.     public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  711.     {
  712.         if ( $_GET['crudAction'] === Action::EDIT) {
  713.             $filmProject $this->getFilmProjectFromEntityId();
  714.             if ($filmProject) {
  715.                 $responseParameters
  716.                     ->set('filmProject'$filmProject)
  717.                 ;
  718.             }
  719.         }
  720.         $product $this->filmApplicationService->getDefaultProduct();
  721.         $cards $this->userBillingService->getCurrentSavedCards(); // Get saved cards
  722.         $responseParameters->setAll([
  723.             'product' => $product,
  724.             'cards' => $cards,
  725.         ]);
  726.         return $responseParameters;
  727.     }
  728.     // Custom Actions
  729.     public function saveDraft(AdminContext $context): Response
  730.     {
  731.         $entityInstance $context->getEntity()->getInstance();
  732.         $entityInstance->setStatus('draft');
  733.         if ( $entityInstance->getResubmitCount() ) {
  734.             $entityInstance->setStatus('resubmit');
  735.         }
  736.         
  737.         $this->em->persist($entityInstance);
  738.         $this->em->flush();
  739.         $this->addFlash('success''Your draft has been saved');
  740.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(DraftFilmProjectCrudController::class)
  741.             ->setAction(Action::INDEX)
  742.             ->generateUrl();
  743.         return new RedirectResponse($filmProjectIndexUrl);
  744.     }
  745.     
  746.     public function exportOriginalCopy(AdminContext $context): Response
  747.     {
  748.         $entityInstance $context->getEntity()->getInstance();
  749.         $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal()->getData();
  750.         $csvExporter = new CsvExporter();
  751.         $csvExporter->exportArrayToCsv($filmProjectOriginalCopy$entityInstance->getTitle() .'-V1.csv');
  752.         $this->addFlash('success''Your original copy has been exported');
  753.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  754.             ->setAction(Action::INDEX)
  755.             ->generateUrl();
  756.         return new RedirectResponse($filmProjectIndexUrl);
  757.     }
  758.     public function exportCurrentVersionCopy(AdminContext $context): Response
  759.     {
  760.         $entityInstance $context->getEntity()->getInstance();
  761.         $filmProjectConverter = new FilmProjectObjectConverter();
  762.         $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  763.         $csvExporter = new CsvExporter();
  764.         $csvExporter->exportArrayToCsv($serializedFilmProject$entityInstance->getTitle() .'.csv');
  765.         $this->addFlash('success''Your current version project has been exported');
  766.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  767.             ->setAction(Action::INDEX)
  768.             ->generateUrl();
  769.         return new RedirectResponse($filmProjectIndexUrl);
  770.     }
  771.     public function updateProjectDetails(AdminContext $context): Response
  772.     {
  773.         $entityInstance $context->getEntity()->getInstance();
  774.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  775.             ->setAction(Action::EDIT)
  776.             ->setEntityId($entityInstance->getId())
  777.             ->generateUrl();
  778.         if ($entityInstance->isIsProgressReportActive() && $entityInstance->getProgressReportStatusUpdate() != 'complete') {
  779.             $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  780.                 ->setAction(Action::EDIT)
  781.                 ->setEntityId($entityInstance->getId())
  782.                 ->set('disableFields'"true"
  783.                 ->generateUrl()
  784.             ;
  785.         }
  786.         return new RedirectResponse($projectUpdateUrl);
  787.     }
  788.     public function viewProjectUpdates(AdminContext $context): Response
  789.     {
  790.         $entityInstance $context->getEntity()->getInstance();
  791.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  792.             ->setAction(Action::INDEX)
  793.             ->unset('entityId')
  794.             ->set('project'$entityInstance->getId())
  795.             ->generateUrl();
  796.         return new RedirectResponse($projectUpdateUrl);
  797.     }
  798.     public function addProjectUpdates(AdminContext $context): Response
  799.     {
  800.         $entityInstance $context->getEntity()->getInstance();
  801.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  802.             ->setAction(Action::NEW)
  803.             ->unset('entityId')
  804.             ->set('project'$entityInstance->getId())
  805.             ->generateUrl();
  806.         return new RedirectResponse($projectUpdateUrl);
  807.     }
  808.     public function manageMedia(AdminContext $context): Response
  809.     {
  810.         $entityInstance $context->getEntity()->getInstance();
  811.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectMediaCrudController::class)
  812.             ->setAction(Action::EDIT)
  813.             ->setEntityId($entityInstance->getId())
  814.             ->generateUrl();
  815.         return new RedirectResponse($projectUpdateUrl);
  816.     }
  817.     public function managePartner(AdminContext $context): Response
  818.     {
  819.         $entityInstance $context->getEntity()->getInstance();
  820.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectPartnerCrudController::class)
  821.             ->setAction(Action::EDIT)
  822.             ->setEntityId($entityInstance->getId())
  823.             ->generateUrl();
  824.         return new RedirectResponse($projectUpdateUrl);
  825.     }
  826.     /**
  827.      * BATCH ACTION: export original version
  828.      *
  829.      * @param BatchActionDto $batchActionDto
  830.      * @return void
  831.      */
  832.     public function exportOriginalCopies(BatchActionDto $batchActionDto)
  833.     {
  834.         $className $batchActionDto->getEntityFqcn();
  835.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  836.         
  837.         $filmProjectOriginalCopies = [];
  838.         foreach ($batchActionDto->getEntityIds() as $id) {
  839.             $entityInstance $entityManager->find($className$id);
  840.             $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal();
  841.             if (empty($filmProjectOriginalCopy)) {
  842.                 $this->addFlash('warning''Only approved projects can be exported into CSV');
  843.                 return $this->redirect($batchActionDto->getReferrerUrl());
  844.             }
  845.             array_push($filmProjectOriginalCopies$filmProjectOriginalCopy->getData());
  846.         }
  847.         
  848.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  849.         $csvExporter = new CsvExporter();
  850.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects_V1-'$dateValue .'.xlsx');
  851.    
  852.         // return $this->redirect($batchActionDto->getReferrerUrl());
  853.     }
  854.     /**
  855.      * BATCH: Export current version copy
  856.      *
  857.      * @param BatchActionDto $batchActionDto
  858.      * @return void
  859.      */
  860.     public function exportCurrentVersionCopies(BatchActionDto $batchActionDto)
  861.     {
  862.         $className $batchActionDto->getEntityFqcn();
  863.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  864.         
  865.         $filmProjectConverter = new FilmProjectObjectConverter();
  866.         $filmProjectOriginalCopies = [];
  867.         foreach ($batchActionDto->getEntityIds() as $id) {
  868.             $entityInstance $entityManager->find($className$id);
  869.             $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  870.             array_push($filmProjectOriginalCopies$serializedFilmProject);
  871.         }
  872.         
  873.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  874.         $csvExporter = new CsvExporter();
  875.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects-'$dateValue .'.xlsx');
  876.     
  877.         // return $this->redirect($batchActionDto->getReferrerUrl());
  878.     }
  879.     /**
  880.      * BATCH: Publish projects
  881.      *
  882.      * @param BatchActionDto $batchActionDto
  883.      * @return void
  884.      */
  885.     public function publishProjects(BatchActionDto $batchActionDto)
  886.     {
  887.         $className $batchActionDto->getEntityFqcn();
  888.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  889.         // Check if there is non-approved projects
  890.         foreach ($batchActionDto->getEntityIds() as $id) {
  891.             $entityInstance $entityManager->find($className$id);
  892.             
  893.             if ($entityInstance->getStatus() != 'approved') {
  894.                 $this->addFlash('notice''Project(s) have to be approved before being published.');
  895.                 return $this->redirect($batchActionDto->getReferrerUrl());
  896.             }
  897.         }
  898.         foreach ($batchActionDto->getEntityIds() as $id) {
  899.             $entityInstance $entityManager->find($className$id);
  900.             $this->filmApplicationService->publishProject($entityInstance);
  901.         }
  902.         $this->addFlash('success''Project(s) have been published');
  903.         return $this->redirect($batchActionDto->getReferrerUrl());
  904.     }
  905.     /**
  906.      * BATCH: Unublish projects
  907.      *
  908.      * @param BatchActionDto $batchActionDto
  909.      * @return void
  910.      */
  911.     public function unpublishProjects(BatchActionDto $batchActionDto)
  912.     {
  913.         $className $batchActionDto->getEntityFqcn();
  914.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  915.         // Check if there is non-approved projects
  916.         foreach ($batchActionDto->getEntityIds() as $id) {
  917.             $entityInstance $entityManager->find($className$id);
  918.             
  919.             if ($entityInstance->getStatus() != 'approved') {
  920.                 $this->addFlash('notice''Project(s) have to be approved before being unpublished.');
  921.                 return $this->redirect($batchActionDto->getReferrerUrl());
  922.             }
  923.         }
  924.         foreach ($batchActionDto->getEntityIds() as $id) {
  925.             $entityInstance $entityManager->find($className$id);
  926.             $this->filmApplicationService->unpublishProject($entityInstance);
  927.         }
  928.         $this->addFlash('success''Project(s) have been unpublished');
  929.         return $this->redirect($batchActionDto->getReferrerUrl());
  930.     }
  931.     public function viewProject(AdminContext $adminContext)
  932.     {
  933.         $entityInstance $adminContext->getEntity()->getInstance();
  934.         return $this->redirect($entityInstance->getWordpressUrl());
  935.     }
  936.     /**
  937.      * BATCH: archive projects
  938.      *
  939.      * @param BatchActionDto $batchActionDto
  940.      * @return void
  941.      */
  942.     public function archiveProjects(BatchActionDto $batchActionDto)
  943.     {
  944.         $className $batchActionDto->getEntityFqcn();
  945.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  946.         // Check if there is non-approved projects
  947.         foreach ($batchActionDto->getEntityIds() as $id) {
  948.             $entityInstance $entityManager->find($className$id);
  949.             
  950.             if ($entityInstance->getStatus() != 'approved') {
  951.                 $this->addFlash('notice''Project(s) have to be approved before being archived.');
  952.                 return $this->redirect($batchActionDto->getReferrerUrl());
  953.             }
  954.         }
  955.         foreach ($batchActionDto->getEntityIds() as $id) {
  956.             $entityInstance $entityManager->find($className$id);
  957.             $this->filmApplicationService->archiveProject($entityInstance);
  958.         }
  959.         $this->addFlash('success''Project(s) have been archived');
  960.         return $this->redirect($batchActionDto->getReferrerUrl());
  961.     }
  962.     /**
  963.      * BATCH: Make private projects
  964.      *
  965.      * @param BatchActionDto $batchActionDto
  966.      * @return void
  967.      */
  968.     public function makePrivateProjects(BatchActionDto $batchActionDto)
  969.     {
  970.         $postPassword '';
  971.         if (isset($_COOKIE['postpassword'])) {
  972.             $postPassword $_COOKIE['postpassword'];
  973.         }
  974.         if ($postPassword) {
  975.             $className $batchActionDto->getEntityFqcn();
  976.             $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  977.             foreach ($batchActionDto->getEntityIds() as $id) {
  978.                 $entityInstance $entityManager->find($className$id);
  979.                 $this->filmApplicationService->makePrivateProject($entityInstance$postPassword);
  980.             }
  981.         }
  982.         $this->addFlash('success''Project(s) have been made private');
  983.         return $this->redirect($batchActionDto->getReferrerUrl());
  984.     }
  985.     public function downloadReport(AdminContext $contextEnvironment $twig nullPdf $pdf)
  986.     {
  987.         $filmProject $context->getEntity()->getInstance();
  988.         $pdfExporter = new PdfExporter($twig$pdf);
  989.         $pdfExporter->convertProjectToPdf($filmProject);
  990.     }
  991.     public function hideDonationBox(AdminContext $adminContext)
  992.     {
  993.         $entityInstance $adminContext->getEntity()->getInstance();
  994.         $this->filmApplicationService->hideDonationBox($entityInstance);
  995.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been hidden.');
  996.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  997.             ->setAction(Action::INDEX)
  998.             ->generateUrl();
  999.         return new RedirectResponse($filmProjectIndexUrl);
  1000.     }
  1001.     public function showDonationBox(AdminContext $adminContext)
  1002.     {
  1003.         $entityInstance $adminContext->getEntity()->getInstance();
  1004.         $this->filmApplicationService->showDonationBox($entityInstance);
  1005.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been displayed.');
  1006.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1007.             ->setAction(Action::INDEX)
  1008.             ->generateUrl();
  1009.         return new RedirectResponse($filmProjectIndexUrl);
  1010.     }
  1011.     public function submitProjectAsAdmin(AdminContext $context
  1012.     {
  1013.         $user $this->getUser();
  1014.         $entityInstance $context->getEntity()->getInstance();
  1015.         // Save everything before 
  1016.         $this->em->persist($entityInstance);
  1017.         $this->em->flush();
  1018.         // Check if image exists
  1019.         $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  1020.         if (!$isImage) {
  1021.             $backUrl $this->container->get(AdminUrlGenerator::class)
  1022.                 ->setAction(Action::EDIT)
  1023.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  1024.                 ->generateUrl();
  1025.             $this->addFlash('notice''Image in Project Details Tab is required.');
  1026.             return $this->redirect($backUrl);
  1027.         }
  1028.         $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  1029.         $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  1030.         
  1031.         $this->filmApplicationService->generateSponsorsFromText($entityInstance);
  1032.         $this->filmApplicationService->createWordpressObject($entityInstance);
  1033.         $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  1034.         if (!$entityInstance->getOldWordpressId()) {
  1035.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  1036.         }
  1037.         
  1038.         if (!$entityInstance->getResubmitCount()) {
  1039.             $this->filmApplicationService->proceedPayment($entityInstance);
  1040.             $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);       
  1041.             $this->filmApplicationService->sendEmail($entityInstance);
  1042.         }
  1043.         
  1044.         $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  1045.         $url $this->container->get(AdminUrlGenerator::class)
  1046.             ->setController(PendingFilmProjectCrudController::class)
  1047.             ->setAction(Action::INDEX)
  1048.             ->generateUrl();
  1049.         return $this->redirect($url);
  1050.     }
  1051.     
  1052.     public function exportAllDonations(AdminContext $adminContext) {
  1053.         $entityInstance $adminContext->getEntity()->getInstance();
  1054.         $donationRepository $this->em->getRepository(Donation::class);
  1055.         $donations $donationRepository->findDonationsByProjectOrderDate($entityInstance->getId());
  1056.         $spreadsheet = new Spreadsheet();
  1057.         $sheet $spreadsheet->getActiveSheet();
  1058.         // Generate columns first
  1059.         $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"];
  1060.         $excelCol 'A';
  1061.         $excelRow 1;
  1062.         foreach($columnTitles as $columnTitle) {
  1063.             $currentPosition $excelCol .''$excelRow;
  1064.             $sheet->setCellValue($currentPosition$columnTitle)->getColumnDimension($excelCol)->setAutoSize(TRUE);
  1065.             $excelCol++;
  1066.         }
  1067.         $excelRow++;
  1068.         // Universal project field(s)
  1069.         $filmProjectFunding $entityInstance->getFilmProjectFunding();
  1070.         $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1071.         $fundraisingStatus 0;
  1072.         // After that, we generate data respectively
  1073.         $limit 2000;
  1074.         foreach ($donations as $donation) {
  1075.             // Universal project field(s)
  1076.             $project $donation->getFilmProject();
  1077.             $filmProjectFunding $project->getFilmProjectFunding();
  1078.             $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1079.             $orderDetails $donation->getOrderDetails();
  1080.             $orderBillingDetails $orderDetails->getOrderBillingDetails();
  1081.             $paymentDetails $orderDetails->getPaymentDetails();
  1082.             $isAnonymous = (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent());
  1083.             $isAnon =  (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent()) ? 'yes' 'no';
  1084.             $totalAmount = (number_format((float)$orderDetails->getTotal() / 1002));
  1085.             if ($donation->getSupportDaf()) {
  1086.                 $totalAmount = (number_format(((float)$orderDetails->getTotal()- $donation->getSupportDaf()) / 1002));
  1087.             }
  1088.             $popupAmount = (number_format((float)$donation->getSupportDaf() / 1002));
  1089.             $isAnonymous = !$this->getUser()->isAdmin();
  1090.             $sheet->setCellValue('A'.$excelRow 'MW'.$orderDetails->getId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Order ID
  1091.             $sheet->setCellValue('B'.$excelRow $orderDetails->getInvoiceNumber())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Receipt ID
  1092.             $sheet->setCellValue('C'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getFirstName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // First Name
  1093.             $sheet->setCellValue('D'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getLastName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Last Name
  1094.             $sheet->setCellValue('E'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getEmailAddress())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Email
  1095.             $sheet->setCellValue('F'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getOrganisation())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Organisation
  1096.             $sheet->setCellValue('G'.$excelRow $donation->getFilmProject())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Donation to
  1097.             $sheet->setCellValue('H'.$excelRow , (string)$donation->getFilmProject()->getWordpressId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Wordpress ID
  1098.             $sheet->setCellValue('I'.$excelRow $isAnon)->getColumnDimension($excelCol)->setAutoSize(TRUE); // Is Anonymous
  1099.             $sheet->setCellValue('J'.$excelRow str_replace(","""$totalAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Total Amount
  1100.             $sheet->setCellValue('K'.$excelRow str_replace(","""$popupAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // pop-up Amount
  1101.             // $sheet->setCellValue('L'.$excelRow , str_replace(",", "", $fundraisingStatus))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Status
  1102.             $sheet->setCellValue('L'.$excelRow str_replace(","""$fundraisingGoal))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Goal
  1103.             $sheet->setCellValue('M'.$excelRow date_format($donation->getModifiedAt(), 'd/m/Y'))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Date
  1104.             $sheet->setCellValue('N'.$excelRow $paymentDetails->getStatus())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Status
  1105.             $sheet->setCellValue('O'.$excelRow $orderDetails->getSalesforceId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Salesforce ID
  1106.             $sheet->setCellValue('P'.$excelRow $orderDetails->getXeroId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Invoice ID
  1107.             $sheet->setCellValue('Q'.$excelRow $orderDetails->getXeroContactId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Contact ID
  1108.             $sheet->setCellValue('R'.$excelRow , ($orderDetails->getTransactionId()) ? $orderDetails->getTransactionId() : 'Manual Donation')->getColumnDimension($excelCol)->setAutoSize(TRUE); // Merchant Warrior ID
  1109.             $sheet->getStyle('J'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1110.             $sheet->getStyle('K'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1111.             $sheet->getStyle('L'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1112.             if ($excelRow $limit ) {
  1113.                 break;
  1114.             }
  1115.             $excelRow++;
  1116.         }
  1117.         ob_clean();
  1118.         $writer = new Xlsx($spreadsheet);
  1119.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1120.         header('Content-Disposition: attachment; filename="'$entityInstance->getTitle() .' donations.xlsx"');
  1121.         $writer->save('php://output');
  1122.         exit();
  1123.     }
  1124.     /**
  1125.      * Get film project from entity ID 
  1126.      *
  1127.      * @return FilmProject|null
  1128.      */
  1129.     protected function getFilmProjectFromEntityId(): ?FilmProject
  1130.     {
  1131.         $entityManager $this->container->get('doctrine')->getManagerForClass(FilmProject::class);
  1132.         $repository =  $entityManager->getRepository(FilmProject::class);
  1133.         $filmProject $repository->findOneBy(['id' => $_GET['entityId']]);
  1134.         return $filmProject;
  1135.     }
  1136.     protected function updateMainMembers(EntityManagerInterface $entityManagerFilmProject $entityInstance)
  1137.     {
  1138.         // Assign main members to project
  1139.         $administrator $entityInstance->getFilmProjectAdmin();
  1140.         $administrator->setAdminFilmProject($entityInstance);
  1141.         $entityManager->persist($administrator);
  1142.         $director $entityInstance->getFilmProjectDirector();
  1143.         $director->setDirectorFilmProject($entityInstance);
  1144.         $entityManager->persist($director);
  1145.         $producer $entityInstance->getFilmProjectProducer();
  1146.         $producer->setProducerFilmProject($entityInstance);
  1147.         $entityManager->persist($producer);
  1148.         $entityManager->flush();
  1149.     }
  1150.     /**
  1151.      * BATCH: Make hidden projects
  1152.      *
  1153.      * @param BatchActionDto $batchActionDto
  1154.      * @return void
  1155.      */
  1156.     public function makeHiddenProjects(BatchActionDto $batchActionDto)
  1157.     {
  1158.         $className $batchActionDto->getEntityFqcn();
  1159.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  1160.         foreach ($batchActionDto->getEntityIds() as $id) {
  1161.             $entityInstance $entityManager->find($className$id);
  1162.             $this->filmApplicationService->makeHiddenProject($entityInstance);
  1163.         }
  1164.         $this->addFlash('success''Project(s) have been made private');
  1165.         return $this->redirect($batchActionDto->getReferrerUrl());
  1166.     }
  1167.     public function exportDonorList(AdminContext $contextEntityManagerInterface $em
  1168.     {
  1169.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1170.         $donations $entityInstance->getDonations();
  1171.         
  1172.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  1173.         $csvExporter = new CsvExporter();
  1174.         $csvExporter->exportDonorList($donations$entityInstance->getTitle() .' Donor List -'$dateValue .'.xlsx'$this->getUser());
  1175.     }
  1176.     public function viewProgressReport(AdminContext $contextEntityManagerInterface $em)
  1177.     {
  1178.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1179.         $currentYear = (int) date('Y');
  1180.         $progressReportUrl '/progress-report/'$currentYear .'?projectId=' $entityInstance->getId();
  1181.         return $this->redirect($progressReportUrl);
  1182.     }
  1183.     public function downloadProgressReport(AdminContext $contextEnvironment $twig nullPdf $pdfEntityManagerInterface $em)
  1184.     {
  1185.         $filmProject $context->getEntity()->getInstance();
  1186.         $progressReportRepo $em->getRepository(FilmProjectProgressReport::class);
  1187.         $progressReport $progressReportRepo->findByYear((int)date("Y"), $filmProject->getId());
  1188.         if (empty($progressReport)) {
  1189.             $this->addFlash('Notice''Progress report is not available.');
  1190.             $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1191.                 ->setAction(Action::INDEX)
  1192.                 ->generateUrl();
  1193.             return new RedirectResponse($filmProjectIndexUrl);
  1194.         }
  1195.         $pdfExporter = new PdfExporter($twig$pdf);
  1196.         $pdfExporter->convertProgressReportToPdf($progressReport);
  1197.     }
  1198. }