src/OceanExpertBundle/Controller/EventController.php line 2122

Open in your IDE?
  1. <?php
  2. /**
  3.  * Controller for the events
  4.  *
  5.  * @author Mithun
  6.  * @author Arno Lambert <a.lambert@unesco.org>
  7.  * @since  06/10/16
  8.  */
  9. namespace OceanExpertBundle\Controller;
  10. use CommerceGuys\Addressing\Formatter\DefaultFormatter;
  11. use CommerceGuys\Addressing\Model\Address;
  12. use CommerceGuys\Addressing\Repository\AddressFormatRepository;
  13. use CommerceGuys\Addressing\Repository\CountryRepository;
  14. use CommerceGuys\Addressing\Repository\SubdivisionRepository;
  15. use DateTime;
  16. use Doctrine\ORM\AbstractQuery;
  17. use Doctrine\ORM\NoResultException;
  18. use ErrorException;
  19. use FOS\UserBundle\Model\UserManagerInterface;
  20. use FOS\UserBundle\Util\TokenGeneratorInterface;
  21. use OceanExpertBundle\Entity\DocumentFiles;
  22. use OceanExpertBundle\Entity\EventAgendaitems;
  23. use OceanExpertBundle\Entity\EventBackgrounddocs;
  24. use OceanExpertBundle\Entity\EventContacts;
  25. use OceanExpertBundle\Entity\EventFiles;
  26. use OceanExpertBundle\Entity\EventGroups;
  27. use OceanExpertBundle\Entity\EventLabels;
  28. use OceanExpertBundle\Entity\EventOtherdocs;
  29. use OceanExpertBundle\Entity\EventParticipantImportFiles;
  30. use OceanExpertBundle\Entity\EventParticipantroles;
  31. use OceanExpertBundle\Entity\EventParticipants;
  32. use OceanExpertBundle\Entity\EventParticipantUpload;
  33. use OceanExpertBundle\Entity\EventPresentations;
  34. use OceanExpertBundle\Entity\EventReports;
  35. use OceanExpertBundle\Entity\Events;
  36. use OceanExpertBundle\Entity\EventStaff;
  37. use OceanExpertBundle\Entity\MailQueueFiles;
  38. use OceanExpertBundle\Entity\Mails;
  39. use OceanExpertBundle\Entity\Messages;
  40. use PhpOffice\PhpSpreadsheet\IOFactory;
  41. use PhpOffice\PhpSpreadsheet\Reader\Exception;
  42. use Swift_Message;
  43. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  44. use Symfony\Component\HttpFoundation\JsonResponse;
  45. use Symfony\Component\HttpFoundation\RedirectResponse;
  46. use Symfony\Component\HttpFoundation\Request;
  47. use Symfony\Component\HttpFoundation\Response;
  48. use Symfony\Component\Routing\Generator\UrlGenerator;
  49. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  50. /**
  51.  * Class EventController
  52.  * @package OceanExpertBundle\Controller
  53.  */
  54. class EventController extends AbstractController
  55. {
  56.     /**
  57.      * list of possibe event labels
  58.      *
  59.      * @var array
  60.      */
  61.     private $availableEventLabels = array(
  62.         => array(
  63.             'id' => 1,
  64.             'type' => 'Official meeting'
  65.         ),
  66.         => array(
  67.             'id' => 2,
  68.             'type' => 'Training course'
  69.         ),
  70.         => array(
  71.             'id' => 3,
  72.             'type' => 'Expert assistance'
  73.         ),
  74.         => array(
  75.             'id' => 4,
  76.             'type' => 'Priority 1'
  77.         ),
  78.         => array(
  79.             'id' => 5,
  80.             'type' => 'Priority 2'
  81.         ),
  82.         => array(
  83.             'id' => 6,
  84.             'type' => 'Priority 3'
  85.         ),
  86.     );
  87.     /**
  88.      * list of possible participant status
  89.      *
  90.      * @var array
  91.      */
  92.     private $participantStatus = array(
  93.         '0' => 'Confirmed & Approved',
  94.         '1' => 'Need Confirmation',
  95.         '2' => 'Need Approval',
  96.         '3' => 'Declined',
  97.         '4' => 'Rejected',
  98.     );
  99.     private UserManagerInterface $fosUserManager;
  100.     public function __construct(UserManagerInterface $fosUserManager)
  101.     {
  102.         $this->fosUserManager $fosUserManager;
  103.     }
  104.     /**
  105.      * @return Response
  106.      */
  107.     public function indexAction()
  108.     {
  109.         return new Response('Index Page');
  110.     }
  111.     /**
  112.      * create a new event OR edit an existing one
  113.      *
  114.      * @param Request $request
  115.      * @param int $idEvent id of the event to create
  116.      *
  117.      * @return Response
  118.      *
  119.      * @throws \Exception
  120.      */
  121.     public function createEventAction(Request $request$idEvent)
  122.     {
  123.         /*
  124.          * @remark: the security check is not really needed here (but better safe than sorry)
  125.          * because we already have the line ' - { path: ^/admin, role: ROLE_USER }' in security.yaml
  126.          * and this prevents us from going to /admin/event without loging in
  127.          */
  128.         $security_context $this->get('security.authorization_checker');
  129.         if ($security_context->isGranted('IS_AUTHENTICATED_FULLY')) {
  130.             //let's check if the logged-in user has a 'real' profile
  131.             //the mandatory profile fields are all filled and the expert is active
  132.             $em $this->getDoctrine()->getManager();
  133.             $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  134.             if (!SecurityController::checkUserProfile($em$userId)) {
  135.                 return $this->redirect(
  136.                     $this->generateUrl(
  137.                         'user_profile_edit'
  138.                     )
  139.                 );
  140.             }
  141.             $participantRoles = array();
  142.             $participants = array();
  143.             $eventStaff = array();
  144.             $eventContacts = array();
  145.             $unknownParticipants = array();
  146.             $eventLabels = array();
  147.             $eventPresentations = array();
  148.             $eventBackgrounddocs = array();
  149.             $eventOtherdocs = array();
  150.             $agendaItems '';
  151.             $agendaItemsdocs = array();
  152.             $eventImage = array();
  153.             $report = array();
  154.             $idContact = array();
  155.             /*
  156.              * while the function is called createEvent, we just edit an event if a idEvent is given
  157.              * OE logic :-(
  158.              */
  159.             if ($idEvent != 0) {
  160.                 $event $em
  161.                     ->getRepository('OceanExpertBundle:Events')
  162.                     ->findOneBy(
  163.                         array(
  164.                             'idEvent' => $idEvent
  165.                         )
  166.                     );
  167.                 if ($event) {
  168.                     $isOrganiser $em->getRepository('OceanExpertBundle:EventContacts')
  169.                         ->createQueryBuilder('ec')
  170.                         ->select('count(ec.idInd)')
  171.                         ->where('ec.idInd =:idInd')
  172.                         ->andWhere('ec.idEvent =:event')
  173.                         ->setParameters(
  174.                             array(
  175.                                 'idInd' => $userId,
  176.                                 'event' => $idEvent
  177.                             )
  178.                         )
  179.                         ->getQuery()->getSingleScalarResult();
  180.                     $isCreator $em->getRepository('OceanExpertBundle:Events')
  181.                         ->createQueryBuilder('e')
  182.                         ->select('count(e.idEvent)')
  183.                         ->where('e.createdBy =:idInd')
  184.                         ->orWhere('e.lastEditBy =:idInd')
  185.                         ->orWhere('e.idContact =:idInd')
  186.                         ->andWhere('e.idEvent =:event')
  187.                         ->setParameters(array('idInd' => $userId'event' => $idEvent))
  188.                         ->getQuery()->getSingleScalarResult();
  189.                     if ($isOrganiser == 1
  190.                         || $isCreator == 1
  191.                         || $this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')
  192.                     ) {
  193.                         //@todo what happens here? Arno 21/06/21
  194.                     } else {
  195.                         return $this->redirect(
  196.                             $this->generateUrl(
  197.                                 'view_event',
  198.                                 array(
  199.                                     'event' => $idEvent
  200.                                 )
  201.                             )
  202.                         );
  203.                     }
  204.                     if (null != $event->getIdContact()) {
  205.                         $idContact $this->getDoctrine()
  206.                             ->getRepository('OceanExpertBundle:Indiv')
  207.                             ->createQueryBuilder('i')
  208.                             ->select("i.fname,i.sname, i.idInd")
  209.                             ->where('i.idInd = :idInd')
  210.                             ->setParameter('idInd'$event->getIdContact())
  211.                             ->getQuery()
  212.                             ->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
  213.                         $idContact = array(
  214.                             'idInd' => $idContact['idInd'],
  215.                             'user' => $idContact['fname'] . ' ' $idContact['sname'],
  216.                         );
  217.                     }
  218.                     $eventImage $this->getDoctrine()
  219.                         ->getRepository('OceanExpertBundle:EventFiles')
  220.                         ->findOneBy(
  221.                             array(
  222.                                 'idEvent' => $event->getIdEvent()
  223.                             )
  224.                         );
  225.                     $participantRoles $this->getDoctrine()
  226.                         ->getRepository('OceanExpertBundle:EventParticipantroles')
  227.                         ->findBy(
  228.                             array('idEvent' => $idEvent),
  229.                             array('ordering' => 'asc')
  230.                         );
  231.                     $participants $this->getEventParticipants($idEvent);
  232.                     $eventStaff $this->getEventStaff($idEvent);
  233.                     $eventContacts $this->getEventOrganisers($idEvent);
  234.                     $unknownParticipants $this->getDoctrine()
  235.                         ->getRepository('OceanExpertBundle:EventUnknownparticipants')
  236.                         ->findBy(
  237.                             array('idEvent' => $idEvent)
  238.                         );
  239.                     $eventLabels $em
  240.                         ->getRepository('OceanExpertBundle:EventLabels')
  241.                         ->findBy(
  242.                             array('idEvent' => $idEvent)
  243.                         );
  244.                     $eventPresentations $this->getEventPresentations($idEvent);
  245.                     $eventBackgrounddocs $this->getBackgrounddocs($idEvent);
  246.                     $eventOtherdocs $this->getEventOtherDocs($idEvent);
  247.                     $agendaItems $this->getAgendaItems($event);
  248.                     $agendaItemsdocs $this->getDocuments(
  249.                         'OceanExpertBundle:AgendaitemDocuments',
  250.                         $idEvent
  251.                     );
  252.                     $report $this->getEventReport($idEvent);
  253.                 } else {
  254.                     return $this->render(
  255.                         'Exception/error.html.twig',
  256.                         array(
  257.                             'message' => "cannot find the event with id '$idEvent'"
  258.                         )
  259.                     );
  260.                 }
  261.             } else {
  262.                 $event = new Events();
  263.                 $event->setStatus(0);
  264.                 $event->setCreatedBy($userId);
  265.                 $event->setCreatedAt(new DateTime());
  266.                 $event->agenda '';
  267.             }
  268.             if ($request->getMethod() === 'POST') {
  269.                 $formData $request->request->all();
  270.                 $files $request->files;
  271.                 return $this->storeTheEvent(
  272.                     $event,
  273.                     $formData,
  274.                     $files,
  275.                     $userId
  276.                 );
  277.             }
  278.             /*
  279.             $participantStatus = array(
  280.                 '0' => 'Confirmed & Approved',
  281.                 '1' => 'Need Confirmation',
  282.                 '2' => 'Need Approval',
  283.                 '3' => 'Declined',
  284.                 '4' => 'Rejected',
  285.             );
  286.             */
  287.             $calenderGroups $this->getDoctrine()
  288.                 ->getRepository('OceanExpertBundle:EventGroups')
  289.                 ->createQueryBuilder('e')
  290.                 ->select('e.idGroup')
  291.                 ->where('e.idEvent = :idEvent')
  292.                 ->setParameter('idEvent'$idEvent)
  293.                 ->getQuery()
  294.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  295.             $calenderGroups array_column($calenderGroups'idGroup');
  296.             $availableEventType $em
  297.                 ->getRepository('OceanExpertBundle:Eventtypes')
  298.                 ->findBy(
  299.                     array(),
  300.                     array(
  301.                         'eventtypeName' => 'ASC'
  302.                     )
  303.                 );
  304.             $countries $this->getDoctrine()
  305.                 ->getRepository('OceanExpertBundle:Countries')
  306.                 ->findBy(
  307.                     array(),
  308.                     ['country' => 'ASC']
  309.                 );
  310.             $instituteSeaRegion $this->getDoctrine()
  311.                 ->getRepository('OceanExpertBundle:Regions')
  312.                 ->seaRegions();
  313.             $availableCalenderGroups $this->getSitesGroup();
  314.             $documentList $this->getDocumentList();
  315.             $data = array(
  316.                 'data' => array(
  317.                     'event' => $event,
  318.                     'countries' => $countries,
  319.                     'availableCalenderGroups' => $availableCalenderGroups,
  320.                     'availableEventType' => $availableEventType,
  321.                     'availableEventLabels' => $this->availableEventLabels,
  322.                     'availableSeaRegions' => $instituteSeaRegion,
  323.                     'participantRoles' => $participantRoles,
  324.                     'calenderGroups' => $calenderGroups,
  325.                     'eventLabels' => $eventLabels,
  326.                     'participants' => $participants,
  327.                     'eventStaff' => $eventStaff,
  328.                     'eventContacts' => $eventContacts,
  329.                     'unknownParticipants' => $unknownParticipants,
  330.                     'eventPresentations' => $eventPresentations,
  331.                     'eventBackgrounddocs' => $eventBackgrounddocs,
  332.                     'eventOtherdocs' => $eventOtherdocs,
  333.                     'agendaItems' => $agendaItems,
  334.                     'agendaItemsdocs' => $agendaItemsdocs,
  335.                     'report' => $report,
  336.                     'participantStatus' => $this->participantStatus,
  337.                     'documentList' => $documentList,
  338.                     'eventEmailContact' => $idContact,
  339.                     'eventImage' => $eventImage,
  340.                 )
  341.             );
  342.             return $this->render(
  343.                 'Event/addEvent.html.twig',
  344.                 $data
  345.             );
  346.         } else {
  347.             return $this->render(
  348.                 'Exception/error.html.twig',
  349.                 array(
  350.                     'message' => 'seems you do not have permissions to do this, please log in before making an event'
  351.                 )
  352.             );
  353.         }
  354.     }
  355.     /**
  356.      * copy the event with the given idEvent
  357.      * show the new event in edit mode
  358.      *
  359.      * @param Request $request
  360.      * @param int $idEvent id of the event to copy
  361.      *
  362.      * @return Response
  363.      *
  364.      * @throws \Exception
  365.      */
  366.     public function copyEventAction(Request $requestint $idEvent): Response
  367.     {
  368.         /*
  369.          * @remark: the security check is not really needed here (but better safe than sorry)
  370.          * because we already have the line ' - { path: ^/admin, role: ROLE_USER }' in security.yaml
  371.          * and this prevents us from going to /admin/copyEvent without loging in
  372.          */
  373.         $security_context $this->get('security.authorization_checker');
  374.         if ($security_context->isGranted('IS_AUTHENTICATED_FULLY')) {
  375.             $em $this->getDoctrine()->getManager();
  376.             $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  377.             $participantRoles = array();
  378.             $participants = array();
  379.             $eventStaffs = array();
  380.             $eventContacts = array();
  381.             $unknownParticipants = array();
  382.             $eventLabels = array();
  383.             $eventPresentations = array();
  384.             $eventBackgrounddocs = array();
  385.             $eventOtherdocs = array();
  386.             $agendaItems '';
  387.             $agendaItemsdocs = array();
  388.             $eventImage = array();
  389.             $report = array();
  390.             $idContact = array();
  391.             /**
  392.              * copy the event with the given idEvent
  393.              */
  394.             if ($idEvent != 0) {
  395.                 //this is the event we will copy
  396.                 $oldEvent $em
  397.                     ->getRepository('OceanExpertBundle:Events')
  398.                     ->findOneBy(
  399.                         array(
  400.                             'idEvent' => $idEvent
  401.                         )
  402.                     );
  403.                 if ($oldEvent) {
  404.                     //make a new title
  405.                     $eventTitle $oldEvent->getTitle() . ' (COPY)';
  406.                     //get all the other info of the event we copy
  407.                     $eventImage $this->getDoctrine()
  408.                         ->getRepository('OceanExpertBundle:EventFiles')
  409.                         ->findOneBy(
  410.                             array(
  411.                                 'idEvent' => $oldEvent->getIdEvent()
  412.                             )
  413.                         );
  414.                     if (null != $oldEvent->getIdContact()) {
  415.                         $oldIdContact $oldEvent->getIdContact();
  416.                         $idContact $this->getDoctrine()
  417.                             ->getRepository('OceanExpertBundle:Indiv')
  418.                             ->createQueryBuilder('i')
  419.                             ->select("i.fname,i.sname, i.idInd")
  420.                             ->where('i.idInd = :idInd')
  421.                             ->setParameter('idInd'$oldEvent->getIdContact())
  422.                             ->getQuery()
  423.                             ->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
  424.                         $idContact = array(
  425.                             'idInd' => $idContact['idInd'],
  426.                             'user' => $idContact['fname'] . ' ' $idContact['sname'],
  427.                         );
  428.                     }
  429.                     $participantRoles $this->getDoctrine()
  430.                         ->getRepository('OceanExpertBundle:EventParticipantroles')
  431.                         ->findBy(
  432.                             array('idEvent' => $idEvent),
  433.                             array('ordering' => 'asc')
  434.                         );
  435.                     $participants $this->getEventParticipants($idEvent);
  436.                     $eventStaffs $this->getEventStaff($idEvent);
  437.                     $eventContacts $this->getEventOrganisers($idEvent);
  438.                     //don't do this, is stupid
  439.                     /*
  440.                     $unknownParticipants = $this->getDoctrine()
  441.                         ->getRepository('OceanExpertBundle:EventUnknownparticipants')
  442.                         ->findBy(
  443.                             array('idEvent' => $idEvent)
  444.                         );
  445.                     */
  446.                     $eventLabels $em
  447.                         ->getRepository('OceanExpertBundle:EventLabels')
  448.                         ->findBy(
  449.                             array('idEvent' => $idEvent)
  450.                         );
  451.                     $eventGroups $em
  452.                         ->getRepository('OceanExpertBundle:EventGroups')
  453.                         ->findBy(
  454.                             array('idEvent' => $idEvent)
  455.                         );
  456.                     //useless to copy agenda's
  457.                     /*
  458.                     $agendaItems = $this->getAgendaItems($oldEvent);
  459.                     $agendaItemsdocs = $this->getDocuments(
  460.                         'OceanExpertBundle:AgendaitemDocuments',
  461.                         $idEvent
  462.                     );
  463.                     */
  464.                     //useless to copy documents
  465.                     /*
  466.                     $eventPresentations = $this->getEventPresentations($idEvent);
  467.                     $eventBackgrounddocs = $this->getBackgrounddocs($idEvent);
  468.                     $eventOtherdocs = $this->getEventOtherDocs($idEvent);
  469.                     */
  470.                     //we cannot have a final report as this is a new event....
  471.                     //$report = $this->getEventReport($idEvent);
  472.                     //check the start and end date
  473.                     //cannot be in the past
  474.                     $startOn $oldEvent->getStartOn();
  475.                     $endOn $oldEvent->getEndOn();
  476.                     $today = new DateTime();
  477.                     if ($startOn $today) {
  478.                         $startOn $today;
  479.                         $endOn $today;
  480.                     }
  481.                     //make the new event
  482.                     $event = new Events();
  483.                     $event->setIdEventtype($oldEvent->getIdEventtype());
  484.                     $event->setTitle($eventTitle);
  485.                     $event->setShorttitle($oldEvent->getShorttitle());
  486.                     $event->setSummary($oldEvent->getSummary());
  487.                     $event->setStartOn($startOn);
  488.                     $event->setendOn($endOn);
  489.                     $event->setAddress($oldEvent->getAddress());
  490.                     $event->setCity($oldEvent->getCity());
  491.                     $event->setState($oldEvent->getState());
  492.                     $event->setPostcode($oldEvent->getPostcode());
  493.                     $event->setIdCountry($oldEvent->getIdCountry());
  494.                     $event->setIdInst($oldEvent->getIdInst());
  495.                     $event->setUseInstAddr($oldEvent->getUseInstAddr());
  496.                     $event->setNotes($oldEvent->getNotes());
  497.                     $event->setWebsite($oldEvent->getWebsite());
  498.                     $event->setRedirectWebsite($oldEvent->getRedirectWebsite());
  499.                     $event->setKeywords($oldEvent->getKeywords());
  500.                     $event->setCreatedBy($userId);
  501.                     $event->setCreatedAt(new DateTime());
  502.                     $event->setUpdatedAt(new DateTime());
  503.                     $event->setLastEditBy($userId);
  504.                     $event->setIsPublic($oldEvent->getIsPublic());
  505.                     $event->setIsOpen($oldEvent->getIsOpen());
  506.                     $event->setShowTravel($oldEvent->getShowTravel());
  507.                     $event->setEmailPeople($oldEvent->getEmailPeople());
  508.                     $event->setRegOnline($oldEvent->getRegOnline());
  509.                     $event->setStatus(0);
  510.                     if (isset($oldIdContact)) {
  511.                         $event->setIdContact($oldIdContact);
  512.                     }
  513.                     $em->persist($event);
  514.                     $em->flush();
  515.                     $idEvent $event->getIdEvent();
  516.                     //participants and their roles should be copied also
  517.                     foreach ($participantRoles as $participantRole) {
  518.                         $newParticipantRole = new EventParticipantroles();
  519.                         $newParticipantRole
  520.                             ->setIdEvent($idEvent)
  521.                             ->setOrdering($participantRole->getOrdering())
  522.                             ->setPptOrdering($participantRole->getPptOrdering())
  523.                             ->setRole($participantRole->getRole())
  524.                             ->setIdRole($participantRole->getIdRole());
  525.                         $em->persist($newParticipantRole);
  526.                         $em->flush();
  527.                     }
  528.                     //participants
  529.                     foreach ($participants as $participant) {
  530.                         $newRequest = new Request();
  531.                         $newRequest->request->set('idInd'$participant['idInd']);
  532.                         $newRequest->request->set('idEvent'$idEvent);
  533.                         $newRequest->request->set('membertype'3);
  534.                         $this->addEventMemberAction($newRequest);
  535.                     }
  536.                     foreach ($eventStaffs as $eventStaff) {
  537.                         $newRequest = new Request();
  538.                         $newRequest->request->set('idInd'$eventStaff['id']);
  539.                         $newRequest->request->set('idEvent'$idEvent);
  540.                         $newRequest->request->set('membertype'2);
  541.                         $this->addEventMemberAction($newRequest);
  542.                     }
  543.                     foreach ($eventContacts as $eventContact) {
  544.                         $newRequest = new Request();
  545.                         $newRequest->request->set('idInd'$eventContact['id']);
  546.                         $newRequest->request->set('idEvent'$idEvent);
  547.                         $newRequest->request->set('membertype'1);
  548.                         $this->addEventMemberAction($newRequest);
  549.                     }
  550.                     //labels
  551.                     foreach ($eventLabels as $eventLabel) {
  552.                         $newEventLabel = new EventLabels();
  553.                         $newEventLabel
  554.                             ->setIdEvent($idEvent)
  555.                             ->setIdGroup($eventLabel->getIdGroup())
  556.                             ->setIdLabel($eventLabel->getIdLabel());
  557.                         $em->persist($newEventLabel);
  558.                         $em->flush();
  559.                     }
  560.                     //groups
  561.                     foreach ($eventGroups as $eventGroup) {
  562.                         $newEventGroup = new EventGroups();
  563.                         $newEventGroup
  564.                             ->setIdEvent($idEvent)
  565.                             ->setIdGroup($eventGroup->getIdGroup())
  566.                             ->setInCalendar($eventGroup->getInCalendar());
  567.                         $em->persist($newEventGroup);
  568.                         $em->flush();
  569.                     }
  570.                 } else {
  571.                     return $this->render(
  572.                         'Exception/error.html.twig',
  573.                         array(
  574.                             'message' => "cannot find the event with id '$idEvent'"
  575.                         )
  576.                     );
  577.                 }
  578.             } else {
  579.                 /*
  580.                  * seems we have no 'real' idEvent,
  581.                  * strange but no panick, let's just make an empty event
  582.                  */
  583.                 $event = new Events();
  584.                 $event->setStatus(0);
  585.                 $event->setCreatedBy($userId);
  586.                 $event->setCreatedAt(new DateTime());
  587.                 $em->persist($event);
  588.                 $em->flush();
  589.                 $idEvent $event->getIdEvent();
  590.             }
  591.             /*
  592.              * DO NOT DO THIS as this will persist and flush the event again
  593.              * remove this if this is still here in 2.4.0
  594.              * #641
  595.             if ($request->getMethod() === 'POST') {
  596.                 $formData = $request->request->all();
  597.                 $files = $request->files;
  598.                 return $this->storeTheEvent(
  599.                     $event,
  600.                     $formData,
  601.                     $files,
  602.                     $userId
  603.                 );
  604.             }
  605.             */
  606.             /*
  607.             $participantStatus = array(
  608.                 '0' => 'Confirmed & Approved',
  609.                 '1' => 'Need Confirmation',
  610.                 '2' => 'Need Approval',
  611.                 '3' => 'Declined',
  612.                 '4' => 'Rejected',
  613.             );
  614.             */
  615.             $calenderGroups $this->getDoctrine()
  616.                 ->getRepository('OceanExpertBundle:EventGroups')
  617.                 ->createQueryBuilder('e')
  618.                 ->select('e.idGroup')
  619.                 ->where('e.idEvent = :idEvent')
  620.                 ->setParameter('idEvent'$idEvent)
  621.                 ->getQuery()
  622.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  623.             $calenderGroups array_column(
  624.                 $calenderGroups,
  625.                 'idGroup'
  626.             );
  627.             $availableEventType $em
  628.                 ->getRepository('OceanExpertBundle:Eventtypes')
  629.                 ->findBy(
  630.                     array(),
  631.                     array(
  632.                         'eventtypeName' => 'ASC'
  633.                     )
  634.                 );
  635.             $countries $this->getDoctrine()
  636.                 ->getRepository('OceanExpertBundle:Countries')
  637.                 ->findBy(
  638.                     array(),
  639.                     ['country' => 'ASC']
  640.                 );
  641.             $instituteSeaRegion $this->getDoctrine()
  642.                 ->getRepository('OceanExpertBundle:Regions')
  643.                 ->seaRegions();
  644.             $availableCalenderGroups $this->getSitesGroup();
  645.             $documentList $this->getDocumentList();
  646.             $data = array(
  647.                 'data' => array(
  648.                     'event' => $event,
  649.                     'countries' => $countries,
  650.                     'availableCalenderGroups' => $availableCalenderGroups,
  651.                     'availableEventType' => $availableEventType,
  652.                     'availableEventLabels' => $this->availableEventLabels,
  653.                     'availableSeaRegions' => $instituteSeaRegion,
  654.                     'participantRoles' => $participantRoles,
  655.                     'calenderGroups' => $calenderGroups,
  656.                     'eventLabels' => $eventLabels,
  657.                     'participants' => $participants,
  658.                     'eventStaff' => $eventStaffs,
  659.                     'eventContacts' => $eventContacts,
  660.                     'unknownParticipants' => $unknownParticipants,
  661.                     'eventPresentations' => $eventPresentations,
  662.                     'eventBackgrounddocs' => $eventBackgrounddocs,
  663.                     'eventOtherdocs' => $eventOtherdocs,
  664.                     'agendaItems' => $agendaItems,
  665.                     'agendaItemsdocs' => $agendaItemsdocs,
  666.                     'report' => $report,
  667.                     'participantStatus' => $this->participantStatus,
  668.                     'documentList' => $documentList,
  669.                     'eventEmailContact' => $idContact,
  670.                     'eventImage' => $eventImage,
  671.                 )
  672.             );
  673.             return $this->redirect(
  674.                 $this->generateUrl(
  675.                     'edit_event',
  676.                     array(
  677.                         'idEvent' => $event->getIdEvent()
  678.                     )
  679.                 ) . '#overview'
  680.             );
  681.         } else {
  682.             return $this->render(
  683.                 'Exception/error.html.twig',
  684.                 array(
  685.                     'message' => 'seems you do not have permissions to do this, please log in before making an event'
  686.                 )
  687.             );
  688.         }
  689.     }
  690.     /**
  691.      * store the form and go to the next step
  692.      *
  693.      * @param Events $event    the event that has been created/edited/copied
  694.      * @param array  $formData data from the form
  695.      * @param object $files    submitted files
  696.      * @param int    $userId   id of the user doing this
  697.      *
  698.      * @return RedirectResponse
  699.      *
  700.      * @throws \Exception
  701.      *
  702.      */
  703.     public function storeTheEvent(
  704.         Events $event,
  705.         array $formData,
  706.         object $files,
  707.         int $userId
  708.     ): RedirectResponse
  709.     {
  710.         $em $this->getDoctrine()->getManager();
  711.         $event->setLastEditBy($userId);
  712.         $event->setUpdatedAt(new DateTime());
  713.         if (isset($formData['form'])
  714.             && $formData['form'] == 'peopleOption'
  715.         ) {
  716.             $event->setRegOnline(isset($formData['registerOnline']) ? $formData['registerOnline'] : 0);
  717.             $event->setEmailPeople(isset($formData['emailPeople']) ? $formData['emailPeople'] : 0);
  718.             $em->persist($event);
  719.             $em->flush();
  720.             $idEvent $event->getIdEvent();
  721.             if (array_key_exists('role'$formData)
  722.                 && count($formData['role']) == count($formData['roledisplay'])
  723.             ) {
  724.                 $count count($formData['roledisplay']);
  725.                 $eventRoles $this->getDoctrine()
  726.                     ->getRepository('OceanExpertBundle:EventParticipantroles')
  727.                     ->findBy(
  728.                         array(
  729.                             'idEvent' => $event->getIdEvent()
  730.                         )
  731.                     );
  732.                 foreach ($eventRoles as $eventRole) {
  733.                     $em->remove($eventRole);
  734.                     $em->flush();
  735.                 }
  736.                 for ($i 0$i $count$i++) {
  737.                     if ($formData['role'][$i] != '') {
  738.                         $eventRoles = new EventParticipantroles();
  739.                         $eventRoles->setIdEvent($event->getIdEvent());
  740.                         $eventRoles->setRole($formData['role'][$i]);
  741.                         $eventRoles->setIdRole($formData['idRole'][$i]);
  742.                         $eventRoles->setPptOrdering($formData['roledisplay'][$i]);
  743.                         $eventRoles->setOrdering($i);
  744.                         $em->persist($eventRoles);
  745.                         $em->flush();
  746.                     }
  747.                 }
  748.             }
  749.             //finish event
  750.             //redirect to confirmation page
  751.             //see #35
  752.             if (isset($formData['finish'])
  753.                 && $formData['finish']
  754.             ) {
  755.                 return $this->redirect(
  756.                     $this->generateUrl(
  757.                         'confirm_event_creation',
  758.                         array(
  759.                             'eventId' => $idEvent
  760.                         )
  761.                     )
  762.                 );
  763.             }
  764.             return $this->redirect(
  765.                 $this->generateUrl(
  766.                     'edit_event',
  767.                     array(
  768.                         'idEvent' => $event->getIdEvent()
  769.                     )
  770.                 ) . '#people'
  771.             );
  772.         } else {
  773.             $event->setIdEventtype($formData['eventType']);
  774.             $event->setTitle($formData['eventTitle']);
  775.             $event->setShorttitle(isset($formData['shortTitle']) ? $formData['shortTitle'] : '');
  776.             $event->setSummary(isset($formData['summary']) ? $formData['summary'] : '');
  777.             $event->setStartOn(new DateTime(str_replace('/''-'$formData['startDate'])));
  778.             $event->setEndOn(new DateTime(str_replace('/''-'$formData['endDate'])));
  779.             $event->setAddress(isset($formData['eventAddress']) ? $formData['eventAddress'] : '');
  780.             $event->setCity(isset($formData['eventCity']) ? $formData['eventCity'] : '');
  781.             $event->setState(isset($formData['eventState']) ? $formData['eventState'] : '');
  782.             $event->setPostcode(isset($formData['eventPostCode']) ? $formData['eventPostCode'] : '');
  783.             $event->setIdCountry(isset($formData['country']) ? $formData['country'] : null);
  784.             if (isset($formData['institute'])) {
  785.                 $event->setIdInst($formData['institute']);
  786.             }
  787.             $event->setNotes(isset($formData['eventNotes']) ? $formData['eventNotes'] : '');
  788.             $event->setWebsite(isset($formData['eventWebsite']) ? $formData['eventWebsite'] : '');
  789.             $event->setKeywords(isset($formData['eventKeywords']) ? $formData['eventKeywords'] : '');
  790.             $event->setUseInstAddr(isset($formData['instAddr']) ? 0);
  791.             $event->setIdContact($userId);
  792.             $event->setIsPublic(1);
  793.             $event->setIsOpen(isset($formData['is_open']) ? $formData['is_open'] : 0);
  794.             $em->persist($event);
  795.             $em->flush();
  796.             $idEvent $event->getIdEvent();
  797.             if (array_key_exists('eventType'$formData)
  798.                 && in_array($formData['eventType'], [34])
  799.             ) {
  800.                 //for Workshop and training course we always have the roles of instructor and learner
  801.                 //check if these have already been set, if not create them
  802.                 foreach (['Instructor''Learner'] as $key => $role) {
  803.                     $fixedRole $em
  804.                         ->getRepository('OceanExpertBundle:EventParticipantroles')
  805.                         ->findOneBy(
  806.                             array(
  807.                                 'role' => $role,
  808.                                 'idEvent' => $idEvent
  809.                             )
  810.                         );
  811.                     if (!$fixedRole) {
  812.                         //this role seems not to exist, make it
  813.                         //find the new value for the role id
  814.                         try {
  815.                             $highestRoleIdReq $this->getDoctrine()
  816.                                 ->getRepository('OceanExpertBundle:EventParticipantroles')
  817.                                 ->createQueryBuilder('e')
  818.                                 ->select('e.idRole')
  819.                                 ->where('e.idEvent = :idEvent')
  820.                                 ->setParameter('idEvent'$idEvent)
  821.                                 ->orderBy('e.idRole''DESC')
  822.                                 ->setMaxResults(1)
  823.                                 ->getQuery()
  824.                                 ->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
  825.                             $highestRoleId $highestRoleIdReq['idRole'];
  826.                             $highestRoleId ++;
  827.                         } catch (NoResultException $e) {
  828.                             $highestRoleId 0;
  829.                         }
  830.                         $fixedRole = new EventParticipantroles();
  831.                         $fixedRole->setIdEvent($event->getIdEvent());
  832.                         $fixedRole->setRole($role);
  833.                         $fixedRole->setIdRole($highestRoleId);
  834.                         $fixedRole->setPptOrdering(0);
  835.                         $fixedRole->setOrdering($key 1);
  836.                         $em->persist($fixedRole);
  837.                         $em->flush();
  838.                     }
  839.                 }
  840.             }
  841.             //save the choosen calender groups
  842.             //mind that we have to remove the old ones first
  843.             $eventGroups $this->getDoctrine()
  844.                 ->getRepository('OceanExpertBundle:EventGroups')
  845.                 ->findBy(
  846.                     array(
  847.                         'idEvent' => $idEvent
  848.                     )
  849.                 );
  850.             foreach ($eventGroups as $eventGroup) {
  851.                 $em->remove($eventGroup);
  852.             }
  853.             $em->flush();
  854.             if (isset($formData['calenderGroups'])) {
  855.                 foreach ($formData['calenderGroups'] as $idGroup) {
  856.                     $eventGroup $em
  857.                         ->getRepository('OceanExpertBundle:EventGroups')
  858.                         ->findOneBy(
  859.                             array(
  860.                                 'idEvent' => $idEvent,
  861.                                 'idGroup' => $idGroup
  862.                             )
  863.                         );
  864.                     if (!$eventGroup) {
  865.                         $eventGroup = new EventGroups();
  866.                     }
  867.                     $eventGroup->setIdEvent($idEvent);
  868.                     $eventGroup->setIdGroup($idGroup);
  869.                     $eventGroup->setInCalendar(1);
  870.                     $em->persist($eventGroup);
  871.                     $em->flush();
  872.                 }
  873.             }
  874.             $eventLabels $this->getDoctrine()
  875.                 ->getRepository('OceanExpertBundle:EventLabels')
  876.                 ->findBy(
  877.                     array(
  878.                         'idEvent' => $idEvent
  879.                     )
  880.                 );
  881.             foreach ($eventLabels as $eachlabel) {
  882.                 $em->remove($eachlabel);
  883.             }
  884.             $em->flush();
  885.             if (isset($formData['labelGroup'])) {
  886.                 $labels array_combine($formData['labelGroup'], $formData['label']);
  887.                 foreach ($labels as $group => $grouplabel) {
  888.                     $eventLabel = new EventLabels();
  889.                     $eventLabel->setIdEvent($idEvent);
  890.                     $eventLabel->setIdGroup($group);
  891.                     $eventLabel->setIdLabel($grouplabel);
  892.                     $em->persist($eventLabel);
  893.                     $em->flush();
  894.                 }
  895.             }
  896.             if (null != $files->get('eventImage')) {
  897.                 $file $files->get('eventImage');
  898.                 $filedata = array(
  899.                     'id' => $idEvent,
  900.                     'file' => $file,
  901.                     'filename' => 'eventImage.png',
  902.                     'type' => 'image',
  903.                     'path' => "uploads/events/" $idEvent "/",
  904.                     'user' => $userId,
  905.                     'dbEntry' => 1,
  906.                 );
  907.                 $this->uploadFile($filedata);
  908.             } else {
  909.                 if (isset($formData['eventlogo'])
  910.                     && $formData['eventlogo'] == ''
  911.                 ) {
  912.                     $filename 'uploads/events/' $idEvent '/eventImage.png';
  913.                     if (file_exists($filename)) {
  914.                         unlink($filename);
  915.                     }
  916.                     $eventFile $this->getDoctrine()
  917.                         ->getManager()
  918.                         ->getRepository('OceanExpertBundle:EventFiles')
  919.                         ->findOneBy(
  920.                             array(
  921.                                 'idEvent' => $idEvent
  922.                             )
  923.                         );
  924.                     if ($eventFile) {
  925.                         $em->remove($eventFile);
  926.                         $em->flush();
  927.                     }
  928.                 }
  929.             }
  930.             //finish event
  931.             //redirect to confirmation page
  932.             //see #35
  933.             if (isset($formData['finish'])
  934.                 && $formData['finish']
  935.             ) {
  936.                 return $this->redirect(
  937.                     $this->generateUrl(
  938.                         'confirm_event_creation',
  939.                         array(
  940.                             'eventId' => $idEvent
  941.                         )
  942.                     )
  943.                 );
  944.             }
  945.             return $this->redirect(
  946.                 $this->generateUrl(
  947.                     'edit_event',
  948.                     array(
  949.                         'idEvent' => $idEvent
  950.                     )
  951.                 ) . '#peopleoptions'
  952.             );
  953.         }
  954.     }
  955.     /**
  956.      * show the confirmation page telling the event has been created
  957.      * OR updated
  958.      *
  959.      * @param Request $request
  960.      * @param $eventId
  961.      *
  962.      * @return Response
  963.      */
  964.     public function confirmEventCreationAction(Request $request$eventId)
  965.     {
  966.         //check if the event is active
  967.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  968.         $repository->add(
  969.             'select',
  970.             ' e.status'
  971.         );
  972.         $repository->add(
  973.             'from',
  974.             'OceanExpertBundle:Events e'
  975.         );
  976.         $repository->where('e.idEvent = :eventId');
  977.         $repository->setParameter('eventId'$eventId);
  978.         $active $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  979.         if ($active[0]['status'] == 0) {
  980.             $template 'Event/confirmEventCreation.html.twig';
  981.         } elseif ($active[0]['status'] == 1) {
  982.             $template 'Event/confirmEventUpdate.html.twig';
  983.         } else {
  984.             return $this->render(
  985.                 'Exception/error.html.twig',
  986.                 array(
  987.                     'message' => 'This event seems to be deleted, so no use to update it.'
  988.                 )
  989.             );
  990.         }
  991.         return $this->render(
  992.             $template,
  993.             array(
  994.                 'eventId' => $eventId,
  995.                 'active' => $active[0]
  996.             )
  997.         );
  998.     }
  999.     /**
  1000.      * @param $event
  1001.      * @return mixed
  1002.      */
  1003.     public function getEventParticipants($event)
  1004.     {
  1005.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1006.         $repository->add(
  1007.             'select',
  1008.             'e.idRole, 
  1009.             e.idInd, 
  1010.             i.idInd as id, 
  1011.             i.title, 
  1012.             i.fname, 
  1013.             i.sname, 
  1014.             i.tel, 
  1015.             r.role, 
  1016.             i.useInstAddr, 
  1017.             c.country, 
  1018.             r.role,
  1019.             r.ordering, 
  1020.             e.status, 
  1021.             e.accommodation, 
  1022.             i.tel'
  1023.         );
  1024.         $repository->add(
  1025.             'from',
  1026.             'OceanExpertBundle:EventParticipants e'
  1027.         );
  1028.         $repository->leftJoin(
  1029.             'OceanExpertBundle:Indiv',
  1030.             'i',
  1031.             'WITH',
  1032.             'i.idInd = e.idInd'
  1033.         );
  1034.         $repository->leftJoin(
  1035.             'OceanExpertBundle:Countries',
  1036.             'c',
  1037.             'WITH',
  1038.             'c.idCountry = i.countryCode'
  1039.         );
  1040.         $repository->leftJoin(
  1041.             'OceanExpertBundle:EventParticipantroles',
  1042.             'r',
  1043.             'WITH',
  1044.             'e.idRole = r.idRole and e.idEvent = r.idEvent'
  1045.         );
  1046.         $repository->andWhere('e.idEvent = :eventId');
  1047.         $repository->orderBy('r.ordering''asc');
  1048.         $repository->addOrderBy('i.sname''asc');
  1049.         $repository->setParameter('eventId'$event);
  1050.         $participants $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1051.         foreach ($participants as $key => $participant) {
  1052.             //correct the country if the expert has choosen to use the institute address
  1053.             if ($participant['useInstAddr'] === 1) {
  1054.                 //get the correct country, being the country of the institute
  1055.                 $participants[$key]['country'] = 'tbd';
  1056.                 $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1057.                 $repository->add(
  1058.                     'select',
  1059.                     'c.country'
  1060.                 );
  1061.                 $repository->add(
  1062.                     'from',
  1063.                     'OceanExpertBundle:Countries c'
  1064.                 );
  1065.                 $repository->leftJoin(
  1066.                     'OceanExpertBundle:Institutions',
  1067.                     'i',
  1068.                     'WITH',
  1069.                     'c.idCountry = i.countryCode'
  1070.                 );
  1071.                 $repository->leftJoin(
  1072.                     'OceanExpertBundle:IndivInstitution',
  1073.                     'ii',
  1074.                     'WITH',
  1075.                     'ii.idInst = i.idInst'
  1076.                 );
  1077.                 $repository->where('ii.idInd = :idInd');
  1078.                 $repository->setParameter('idInd'$participant['idInd']);
  1079.                 $country $repository->getQuery()->getResult();
  1080.                 if (isset($country[0])
  1081.                     && isset($country[0]['country'])
  1082.                     && $country[0]['country'] != ''
  1083.                 ) {
  1084.                     $participants[$key]['country'] = $country[0]['country'];
  1085.                 }
  1086.             }
  1087.         }
  1088.         return $participants;
  1089.     }
  1090.     /**
  1091.      * @param $event
  1092.      * @return mixed
  1093.      */
  1094.     public function getEventStaff($event)
  1095.     {
  1096.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1097.         $repository->add('select''i.idInd as id, i.title, i.fname, i.sname, c.country');
  1098.         $repository->add('from''OceanExpertBundle:EventStaff e');
  1099.         $repository->leftJoin('OceanExpertBundle:Indiv''i''WITH''i.idInd = e.idInd');
  1100.         $repository->leftJoin('OceanExpertBundle:Countries''c''WITH''c.idCountry = i.countryCode');
  1101.         $repository->where('e.idEvent = :eventId');
  1102.         $repository->setParameter('eventId'$event);
  1103.         return $repository->getQuery()->getResult();
  1104.     }
  1105.     /**
  1106.      * @param $event
  1107.      * @return mixed
  1108.      */
  1109.     public function getEventOrganisers($event)
  1110.     {
  1111.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1112.         $repository->add('select''i.idInd as id, i.title, i.fname, i.sname, e.contactFor, c.country');
  1113.         $repository->add('from''OceanExpertBundle:EventContacts e');
  1114.         $repository->leftJoin('OceanExpertBundle:Indiv''i''WITH''i.idInd = e.idInd');
  1115.         $repository->leftJoin('OceanExpertBundle:Countries''c''WITH''c.idCountry = i.countryCode');
  1116.         $repository->where('e.idEvent = :eventId');
  1117.         $repository->setParameter('eventId'$event);
  1118.         return $repository->getQuery()->getResult();
  1119.     }
  1120.     /**
  1121.      * @param int $event id of the event
  1122.      * @param string $order what column do we use to order the result
  1123.      *
  1124.      * @return array
  1125.      */
  1126.     public function getEventPresentations($event$order '')
  1127.     {
  1128.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1129.         $repository
  1130.             ->add(
  1131.                 'select',
  1132.                 'e.idAgendaitem, d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt'
  1133.             )
  1134.             ->add(
  1135.                 'from',
  1136.                 'OceanExpertBundle:EventPresentations e'
  1137.             )
  1138.             ->leftJoin(
  1139.                 'OceanExpertBundle:Documents',
  1140.                 'd',
  1141.                 'WITH',
  1142.                 'd.idDoc = e.idDoc'
  1143.             )
  1144.             ->where(
  1145.                 'e.idEvent = :eventId'
  1146.             )
  1147.             ->setParameter(
  1148.                 'eventId',
  1149.                 $event
  1150.             );
  1151.         if ($order == "date") {
  1152.             $repository->orderBy('d.updatedAt');
  1153.         } else {
  1154.             $repository->orderBy('e.idAgendaitem');
  1155.         }
  1156.         return $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1157.     }
  1158.     /**
  1159.      * @param int    $event id of the event
  1160.      * @param string $order what column will we use to order the results
  1161.      *
  1162.      * @return array
  1163.      */
  1164.     public function getBackgrounddocs(int $eventstring $order ''): array
  1165.     {
  1166.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1167.         $repository->add('select''d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt ,e.idAgendaitem');
  1168.         $repository->add('from''OceanExpertBundle:EventBackgrounddocs e');
  1169.         $repository->leftJoin('OceanExpertBundle:Documents''d''WITH''d.idDoc = e.idDoc');
  1170.         $repository->where('e.idEvent = :eventId');
  1171.         $repository->setParameter('eventId'$event);
  1172.         if ($order == "date") {
  1173.             $repository->orderBy('d.updatedAt');
  1174.         } else {
  1175.             $repository->orderBy('e.idAgendaitem');
  1176.         }
  1177.         $backgrounddocs $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1178.         return $backgrounddocs;
  1179.     }
  1180.     /**
  1181.      * @param $event
  1182.      * @param string $order
  1183.      * @return mixed
  1184.      */
  1185.     function getEventOtherDocs($event$order '')
  1186.     {
  1187.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1188.         $repository->add('select''d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
  1189.         $repository->add('from''OceanExpertBundle:EventOtherdocs o');
  1190.         $repository->leftJoin('OceanExpertBundle:Documents''d''WITH''d.idDoc = o.idDoc');
  1191.         $repository->where('o.idEvent = :eventId');
  1192.         $repository->setParameter('eventId'$event);
  1193.         if ($order == "date") {
  1194.             $repository->orderBy('d.updatedAt');
  1195.         } else {
  1196.             $repository->orderBy('o.ordering');
  1197.         }
  1198.         $otherDocs $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1199.         return $otherDocs;
  1200.     }
  1201.     /**
  1202.      * @param $table
  1203.      * @param $event
  1204.      *
  1205.      * @return array|DocumentFiles[]
  1206.      */
  1207.     public function getDocuments($table$event)
  1208.     {
  1209.         $idFiles $this->getDoctrine()
  1210.             ->getRepository($table)
  1211.             ->createQueryBuilder('e')
  1212.             ->select('d.idDoc')
  1213.             ->leftJoin('OceanExpertBundle:DocumentFiles''d''WITH''d.idDoc = e.idDoc')
  1214.             ->where('e.idEvent = :eventId')
  1215.             ->setParameter('eventId'$event)
  1216.             ->getQuery()
  1217.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  1218.         $idFiles array_column($idFiles'idDoc');
  1219.         $documents $this->getDoctrine()->getManager()
  1220.             ->getRepository('OceanExpertBundle:DocumentFiles')
  1221.             ->findBy(
  1222.                 array(
  1223.                     'idDoc' => $idFiles
  1224.                 )
  1225.             );
  1226.         return $documents;
  1227.     }
  1228.     /**
  1229.      * @param int $event id of the event
  1230.      *
  1231.      * @return mixed
  1232.      */
  1233.     function getEventReport($event)
  1234.     {
  1235.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1236.         $repository->add('select''d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
  1237.         $repository->add('from''OceanExpertBundle:EventReports e');
  1238.         $repository->leftJoin('OceanExpertBundle:Documents''d''WITH''d.idDoc = e.idDoc');
  1239.         $repository->where('e.idEvent = :eventId');
  1240.         $repository->setParameter('eventId'$event);
  1241.         $otherDocs $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1242.         return $otherDocs;
  1243.     }
  1244.     /**
  1245.      * @param $event
  1246.      *
  1247.      * @return string json
  1248.      */
  1249.     public function getAgendaItems($event)
  1250.     {
  1251.         $em $this->getDoctrine()->getManager();
  1252.         $checkEvent $em
  1253.             ->getRepository('OceanExpertBundle:EventAgendaitems')
  1254.             ->findOneBy(
  1255.                 array(
  1256.                     'idEvent' => $event
  1257.                 )
  1258.             );
  1259.         if (!is_null($checkEvent)) {
  1260.             $agendaItems $this->getDoctrine()
  1261.                 ->getRepository('OceanExpertBundle:EventAgendaitems')
  1262.                 ->createQueryBuilder('e')
  1263.                 ->select('e.idAgendaitem, e.id, e.title, e.parentIdevent, e.agendaOrder, e.notes, e.requiredActions')
  1264.                 ->where('e.idEvent = :eventId')
  1265.                 ->setParameter(':eventId'$event)
  1266.                 ->addOrderBy('e.agendaOrder''ASC')
  1267.                 ->getQuery()
  1268.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  1269.             foreach ($agendaItems as $key => $item) {
  1270.                 $agendaDocuments $this->getDoctrine()
  1271.                     ->getRepository('OceanExpertBundle:AgendaitemDocuments')
  1272.                     ->createQueryBuilder('a')
  1273.                     ->select('d.title as doctitle, d.idDoc, d.docCode')
  1274.                     ->leftJoin('OceanExpertBundle:Documents''d''WITH''d.idDoc = a.idDoc')
  1275.                     ->where('a.idEvent = :eventId')
  1276.                     ->andwhere('a.idAgendaitem = :idAgendaitem')
  1277.                     ->setParameter(':eventId'$event)
  1278.                     ->setParameter(':idAgendaitem'$item['idAgendaitem'])
  1279.                     ->getQuery()
  1280.                     ->getResult(AbstractQuery::HYDRATE_ARRAY);
  1281.                 $agendaItems[$key]['documents'] = $agendaDocuments;
  1282.             }
  1283.             // do not return a json response, we stay in this controller, so no headers needed
  1284.             //return new JsonResponse(
  1285.             return json_encode(
  1286.                 array(
  1287.                     'status' => 1,
  1288.                     EventController::buildTree(
  1289.                         $agendaItems,
  1290.                         0
  1291.                     )
  1292.                 )
  1293.             );
  1294.         }
  1295.         // do not return a json response, we stay in this controller, so no headers needed
  1296.         //return new JsonResponse(
  1297.         return json_encode(
  1298.             array(
  1299.                 'status' => 0,
  1300.                 'message' => 'no agenda items found'
  1301.             )
  1302.         );
  1303.     }
  1304.     /**
  1305.      * @param $ar
  1306.      * @param null $pid
  1307.      * @return array
  1308.      */
  1309.     public static function buildTree($ar$pid null)
  1310.     {
  1311.         $op = array();
  1312.         $i 1;
  1313.         foreach ($ar as $item) {
  1314.             if ($item['parentIdevent'] == $pid) {
  1315.                 $op[$i] = array(
  1316.                     'title' => $item['title'],
  1317.                     'notes' => $item['notes'],
  1318.                     'requiredActions' => $item['requiredActions'],
  1319.                     'parentIdevent' => $item['parentIdevent'],
  1320.                     'id' => $item['id'],
  1321.                     'agendaOrder' => $item['agendaOrder'],
  1322.                     'idAgendaitem' => $item['idAgendaitem'],
  1323.                     'documents' => $item['documents']
  1324.                 );
  1325.                 //using recursion
  1326.                 $children EventController::buildTree($ar$item['id']);
  1327.                 if ($children) {
  1328.                     $op[$i]['children'] = $children;
  1329.                 }
  1330.             }
  1331.             $i++;
  1332.         }
  1333.         return $op;
  1334.     }
  1335.     /**
  1336.      * @param $data
  1337.      */
  1338.     public function uploadFile($data)
  1339.     {
  1340.         $file $data['file'];
  1341.         $id $data['id'];
  1342.         if (null !== $file) {
  1343.             $filetype $file->guessClientExtension();
  1344.             if (array_key_exists('filename'$data)) {
  1345.                 $filename $data['filename'];
  1346.             } else {
  1347.                 $filename $file->getClientOriginalName();
  1348.             }
  1349.             if (array_key_exists('path'$data)) {
  1350.                 $directory $data['path'];
  1351.             } else {
  1352.                 $directory "uploads/events/" $id "/";
  1353.             }
  1354.             $uploadfile $file->move($directory$filename);
  1355.             if ($data['dbEntry'] == 1) {
  1356.                 $em $this->getDoctrine()->getManager();
  1357.                 $eventFile $this->getDoctrine()->getManager()
  1358.                     ->getRepository('OceanExpertBundle:EventFiles')
  1359.                     ->findOneBy(
  1360.                         array(
  1361.                             'idEvent' => $id,
  1362.                             'filename' => $filename,
  1363.                             'path' => $directory
  1364.                         )
  1365.                     );
  1366.                 if (!$eventFile) {
  1367.                     $eventFile = new EventFiles();
  1368.                 }
  1369.                 $eventFile->setIdEvent($id);
  1370.                 $eventFile->setType($data['type']);
  1371.                 $eventFile->setFilename($filename);
  1372.                 $eventFile->setPath($directory);
  1373.                 $eventFile->setCreatedBy($data['user']);
  1374.                 $eventFile->setCreatedAt(new DateTime());
  1375.                 $eventFile->setDeleted(0);
  1376.                 $em->persist($eventFile);
  1377.                 $em->flush();
  1378.             }
  1379.         }
  1380.     }
  1381.     /**
  1382.      * @return mixed
  1383.      */
  1384.     public function getSitesGroup()
  1385.     {
  1386.         $sitesGroup $this->getDoctrine()
  1387.             ->getRepository('OceanExpertBundle:Groups')
  1388.             ->createQueryBuilder('g')
  1389.             ->select('g.idGroup, g.groupname, g.description')
  1390.             ->where('g.hasSite = 1')
  1391.             ->orderBy('g.groupname''ASC')
  1392.             ->getQuery()
  1393.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  1394.         return $sitesGroup;
  1395.     }
  1396.     /**
  1397.      * @return array
  1398.      */
  1399.     function getDocumentList()
  1400.     {
  1401.         $grouplist array_map('current'$this->getUserGroups());
  1402.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1403.         $repository->add('select''distinct(d.idGroup) as idGroup, g.groupname');
  1404.         $repository->add('from''OceanExpertBundle:DoclistGroups d');
  1405.         $repository->leftJoin('OceanExpertBundle:Groups''g''WITH''d.idGroup = g.idGroup');
  1406.         $repository->where('g.idGroup in (:grouplist)');
  1407.         $repository->setParameter('grouplist'$grouplist);
  1408.         $repository->orderBy('g.groupname');
  1409.         $docGroups $repository->getQuery()->getResult();
  1410.         $documentList = array();
  1411.         foreach ($docGroups as $docGroup) {
  1412.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1413.             $repository->add('select''d.idDoclist, d.title, dg.idGroup');
  1414.             $repository->add('from''OceanExpertBundle:Doclists d');
  1415.             $repository->leftJoin('OceanExpertBundle:DoclistGroups''dg''WITH''dg.idDoclist = d.idDoclist');
  1416.             $repository->where('dg.idGroup =:idGroup');
  1417.             $repository->setParameter('idGroup'$docGroup['idGroup']);
  1418.             $repository->orderBy('d.title''asc');
  1419.             $documentList[$docGroup['groupname']] = $repository->getQuery()->getResult();
  1420.         }
  1421.         return $documentList;
  1422.     }
  1423.     /**
  1424.      * @return array
  1425.      */
  1426.     function getUserGroups()
  1427.     {
  1428.         $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  1429.         if ($userId) {
  1430.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  1431.             $repository->add('select''g.idGroup');
  1432.             /*
  1433.              * @todo cleanup
  1434.              * Arno 17/02/2021
  1435.              * #62
  1436.              *
  1437.             $repository->add('from', 'OceanExpertBundle:GroupMembers g');
  1438.             */
  1439.             $repository->add('from''OceanExpertBundle:MemberGroups g');
  1440.             $repository->where('g.idInd = :userId');
  1441.             $repository->setParameter('userId'$userId);
  1442.             return $repository->getQuery()->getResult();
  1443.         } else {
  1444.             return array();
  1445.         }
  1446.     }
  1447.     /**
  1448.      * show all past and upcoming events
  1449.      *
  1450.      * @param Request $request
  1451.      *
  1452.      * @return Response
  1453.      */
  1454.     public function calendarAction(Request $request): Response
  1455.     {
  1456.         //is the current user an editor?
  1457.         $globalEditor $this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR');
  1458.         //entity manager
  1459.         $em $this->getDoctrine()->getManager();
  1460.         //get a list of all event types
  1461.         $repository $em->createQueryBuilder();
  1462.         $repository->add(
  1463.             'select',
  1464.             'et.idEventtype, 
  1465.             et.eventtypeName'
  1466.         );
  1467.         $repository->add(
  1468.             'from',
  1469.             'OceanExpertBundle:Eventtypes et'
  1470.         );
  1471.         $repository->orderBy('et.idEventtype');
  1472.         $eventTypes $repository->getQuery()->getResult();
  1473.         $availableEventTypes = array();
  1474.         foreach ($eventTypes as $eventType) {
  1475.             $availableEventTypes[$eventType['idEventtype']] = $eventType['eventtypeName'];
  1476.         }
  1477.         //get a list of all groups
  1478.         $availableEventGroups array_column(
  1479.             $this->getSitesGroup(),
  1480.             'groupname',
  1481.             'idGroup'
  1482.         );
  1483.         //some name are way too long, so we shorten them
  1484.         foreach ($availableEventGroups as $key => $group) {
  1485.             if (strlen($group) > 18) {
  1486.                 $availableEventGroups[$key] = substr($group018) . '...';
  1487.             }
  1488.         }
  1489.         /*
  1490.          * don't use the following lines to add 'All' to the types, groups and label lists
  1491.          * as this will mess up the order of the groups or the id's
  1492.          * idem for the labels of course
  1493.          *
  1494.         //$availableEventGroups[0] = 'All';
  1495.         //array_unshift($availableEventGroups, 'All');
  1496.         */
  1497.         $availableEventTypes = array(=> 'All') + $availableEventTypes;
  1498.         $availableEventGroups = array(=> 'All') + $availableEventGroups;
  1499.         $availableEventLabels = array(
  1500.             => array(
  1501.                 'id' => 0,
  1502.                 'type' => 'All'
  1503.             )
  1504.         ) + $this->availableEventLabels;
  1505.         $repository $em->createQueryBuilder();
  1506.         $repository->add(
  1507.             'select',
  1508.             'month(e.startOn) as month, 
  1509.             year(e.startOn) as year, 
  1510.             e.idEvent,
  1511.             e.title, 
  1512.             e.shorttitle, 
  1513.             e.idEventtype,
  1514.             e.startOn, 
  1515.             e.endOn, 
  1516.             e.summary, 
  1517.             e.city, 
  1518.             c.country, 
  1519.             e.isOpen, 
  1520.             e.status'
  1521.         );
  1522.         $repository->add(
  1523.             'from',
  1524.             'OceanExpertBundle:Events e'
  1525.         );
  1526.         $repository->leftJoin(
  1527.             'OceanExpertBundle:Countries',
  1528.             'c',
  1529.             'WITH',
  1530.             'c.idCountry = e.idCountry'
  1531.         );
  1532.         $repository->leftJoin(
  1533.             'OceanExpertBundle:EventGroups',
  1534.             'eg',
  1535.             'WITH',
  1536.             'eg.idEvent = e.idEvent'
  1537.         );
  1538.         $repository->leftJoin(
  1539.             'OceanExpertBundle:EventLabels',
  1540.             'l',
  1541.             'WITH',
  1542.             'l.idEvent = e.idEvent AND l.idGroup = eg.idGroup'
  1543.         );
  1544.         //only show the approved / active ones for the non editor users
  1545.         if ($globalEditor != 1) {
  1546.             $repository->where('e.status = 1');
  1547.         }
  1548.         $repository->groupBy('e.idEvent');
  1549.         $repository->orderBy('e.startOn');
  1550.         //did the user select one or more types?
  1551.         $activeEventTypes '0';
  1552.         if (trim($request->query->get('types')) != '') {
  1553.             $activeEventTypes json_decode(
  1554.                 trim(
  1555.                     $request->query->get('types')
  1556.                 )
  1557.             );
  1558.         }
  1559.         //did the user select one or more calendars?
  1560.         //this is not the calendar that is used with the labels!!!!!!!!!!
  1561.         $activeEventGroups '0';
  1562.         if (trim($request->query->get('groups')) != ''
  1563.             //&& trim($request->query->get('groups')) != 0
  1564.         ) {
  1565.             $repository->leftJoin(
  1566.                 'OceanExpertBundle:EventGroups',
  1567.                 'eg2',
  1568.                 'WITH',
  1569.                 'eg2.idEvent = e.idEvent'
  1570.             );
  1571.             $activeEventGroups json_decode(
  1572.                 trim(
  1573.                     $request->query->get(
  1574.                         'groups')
  1575.                 )
  1576.             );
  1577.         }
  1578.         //did the user select one or more labels
  1579.         //we don't care about the groups here
  1580.         $activeEventLabels '0';
  1581.         if (trim($request->query->get('labels')) != ''
  1582.             //&& trim($request->query->get('label')) != 0
  1583.         ){
  1584.             $joinCondition 'l2.idEvent = e.idEvent';
  1585.             /*
  1586.             if ($activeEventGroups != 0) {
  1587.                 $joinCondition .= ' AND l.idGroup = eg.idGroup';
  1588.             }
  1589.             */
  1590.             $repository->leftJoin(
  1591.                 'OceanExpertBundle:EventLabels',
  1592.                 'l2',
  1593.                 'WITH',
  1594.                 $joinCondition
  1595.             );
  1596.             $activeEventLabels json_decode(
  1597.                 trim(
  1598.                     $request->query->get(
  1599.                         'labels')
  1600.                 )
  1601.             );
  1602.         }
  1603.         /*
  1604.         dump($request->query);
  1605.         dump(trim($request->query->get('types')));
  1606.         dump(trim($request->query->get('groups')));
  1607.         dump(trim($request->query->get('labels')));
  1608.         dump($activeEventTypes);
  1609.         dump($activeEventGroups);
  1610.         dump($activeEventLabels);
  1611.         die;
  1612.         */
  1613.         //did the user select a start and end date?
  1614.         if ((null !== ($request->query->get('start'))
  1615.                 && trim($request->query->get('start')) != '')
  1616.                 && (null !== ($request->query->get('end'))
  1617.                     && trim($request->query->get('end')) != '')
  1618.         ) {
  1619.             //there is a start and end date in the url
  1620.             $startdate $request->query->get('start');
  1621.             $enddate $request->query->get('end');
  1622.             $repository->andWhere('e.startOn BETWEEN :startdate AND :enddate');
  1623.             $repository->orWhere('e.endOn BETWEEN :startdate AND :enddate');
  1624.             $repository->setParameters(
  1625.                 array(
  1626.                     'startdate' => $startdate,
  1627.                     'enddate' => $enddate
  1628.                 )
  1629.             );
  1630.         } elseif (trim($request->query->get('year') != '')) {
  1631.             $year $request->query->get('year');
  1632.             $startdate date("$year-01-01");
  1633.             $enddate date("$year-12-31");
  1634.             $repository->andWhere('YEAR(e.startOn) = :year');
  1635.             $repository->orWhere('YEAR(e.endOn) = :year');
  1636.             $repository->setParameter(
  1637.                 'year',
  1638.                 $year
  1639.             );
  1640.         } else {
  1641.             //use the current year
  1642.             $year date('Y');
  1643.             $startdate date(
  1644.                 'Y-m-d'
  1645.             );
  1646.             $enddate date(
  1647.                 'Y-m-t',
  1648.                 strtotime(
  1649.                     "+3 months",
  1650.                     strtotime(
  1651.                         date(
  1652.                             'Y-m-d'
  1653.                         )
  1654.                     )
  1655.                 )
  1656.             );
  1657.             $repository->andWhere('(e.startOn BETWEEN :startdate AND :enddate) OR (e.endOn BETWEEN :startdate AND :enddate)');
  1658.             $repository->orWhere('(e.startOn < :enddate) AND (e.endOn > :startdate)');
  1659.             //$repository->orWhere('e.endOn BETWEEN :startdate AND :enddate');
  1660.             $repository->setParameters(
  1661.                 array(
  1662.                     'startdate' => $startdate,
  1663.                     'enddate' => $enddate
  1664.                 )
  1665.             );
  1666.         }
  1667.         //seems like we cannot set this earlier (overwritten bij setParameter???)
  1668.         //dump($activeEventTypes);
  1669.         //dump($activeEventGroups);
  1670.         //dump($activeEventTypes);
  1671.         if (is_array($activeEventTypes) && !(count($activeEventTypes) == && $activeEventTypes[0] == 0)) {
  1672.             $repository->andWhere('e.idEventtype IN (:types)');
  1673.             $repository->setParameter('types'$activeEventTypes);
  1674.         }
  1675.         //seems like we cannot set this earlier (overwritten bij setParameter???)
  1676.         if (is_array($activeEventGroups) && !(count($activeEventGroups) == && $activeEventGroups[0] == 0)) {
  1677.             $repository->andWhere('eg.idGroup IN (:groups)');
  1678.             $repository->setParameter('groups'$activeEventGroups);
  1679.         }
  1680.         //seems like we cannot set this earlier (overwritten bij setParameter???)
  1681.         if (is_array($activeEventLabels) && !(count($activeEventLabels) == && $activeEventLabels[0] == 0)) {
  1682.             $repository->andWhere('l.idLabel IN (:labels)');
  1683.             $repository->setParameter('labels'$activeEventLabels);
  1684.         }
  1685.         //if the current user is not a global editor, only show the events that are approved
  1686.         if ($globalEditor != 1) {
  1687.             $repository->andWhere('e.status = 1');
  1688.         }
  1689.         //get all the info for the events within the date range
  1690.         //dump($repository->getQuery()->getDQL());
  1691.         //dump($repository->getQuery()->getParameters());
  1692.         //die;
  1693.         $eventData $repository->getQuery()->getResult();
  1694.         //get a list of all years
  1695.         $repository $em->createQueryBuilder();
  1696.         $repository->add(
  1697.             'select',
  1698.             'distinct(year(e.startOn))'
  1699.         );
  1700.         $repository->add(
  1701.             'from',
  1702.             'OceanExpertBundle:Events e'
  1703.         );
  1704.         $repository->where('e.startOn != 0');
  1705.         /*
  1706.         $repository->leftJoin(
  1707.             'OceanExpertBundle:EventGroups',
  1708.             'eg',
  1709.             'WITH',
  1710.             'eg.idEvent = e.idEvent'
  1711.         );
  1712.         */
  1713.         if ($globalEditor != 1) {
  1714.             $repository->andWhere('e.status = 1');
  1715.         }
  1716.         /*
  1717.         if (is_array($activeEventGroups)) {
  1718.             $repository->andWhere('eg.idGroup IN (:groups)');
  1719.             $repository->setParameter('groups', implode(',', $activeEventGroups));
  1720.         }
  1721.         */
  1722.         $repository->orderBy('e.startOn');
  1723.         $years $repository->getQuery()->getResult();
  1724.         $years array_reduce(
  1725.             $years,
  1726.             'array_merge',
  1727.             array()
  1728.         );
  1729.         $eventCollection = array();
  1730.         //get the number of participants, presentations and agenda/background/report/other docs
  1731.         foreach ($eventData as $event) {
  1732.             $repository $em->createQueryBuilder();
  1733.             $repository->add('select''count(e.idInd) as participants');
  1734.             $repository->add('from''OceanExpertBundle:EventParticipants e');
  1735.             $repository->where('e.idEvent = :eventId');
  1736.             $repository->andWhere('e.status != 3');
  1737.             $repository->setParameter('eventId'$event['idEvent']);
  1738.             $participant $repository->getQuery()->getSingleScalarResult();
  1739.             $event['participants'] = $participant;
  1740.             $repository $em->createQueryBuilder();
  1741.             $repository->add('select''count(ep.idDoc) as presentation');
  1742.             $repository->add('from''OceanExpertBundle:EventPresentations ep');
  1743.             $repository->where('ep.idEvent = :eventId');
  1744.             $repository->setParameter('eventId'$event['idEvent']);
  1745.             $presentation $repository->getQuery()->getSingleScalarResult();
  1746.             $repository $em->createQueryBuilder();
  1747.             $repository->add('select''count(ad.idDoc) as agendadocs');
  1748.             $repository->add('from''OceanExpertBundle:AgendaitemDocuments ad');
  1749.             $repository->where('ad.idEvent = :eventId');
  1750.             $repository->setParameter('eventId'$event['idEvent']);
  1751.             $agendadocs $repository->getQuery()->getSingleScalarResult();
  1752.             $repository $em->createQueryBuilder();
  1753.             $repository->add('select''count(eb.idDoc) as backgrounddocs');
  1754.             $repository->add('from''OceanExpertBundle:EventBackgrounddocs eb');
  1755.             $repository->where('eb.idEvent = :eventId');
  1756.             $repository->setParameter('eventId'$event['idEvent']);
  1757.             $backgroundDocs $repository->getQuery()->getSingleScalarResult();
  1758.             $repository $em->createQueryBuilder();
  1759.             $repository->add('select''count(eO.idDoc) as otherdocs');
  1760.             $repository->add('from''OceanExpertBundle:EventOtherdocs eO');
  1761.             $repository->where('eO.idEvent = :eventId');
  1762.             $repository->setParameter('eventId'$event['idEvent']);
  1763.             $otherDocs $repository->getQuery()->getSingleScalarResult();
  1764.             $repository $em->createQueryBuilder();
  1765.             $repository->add('select''count(eO.idDoc) as reportdocs');
  1766.             $repository->add('from''OceanExpertBundle:EventReports eO');
  1767.             $repository->where('eO.idEvent = :eventId');
  1768.             $repository->setParameter('eventId'$event['idEvent']);
  1769.             $reportDocs $repository->getQuery()->getSingleScalarResult();
  1770.             $event['documents'] = $agendadocs $presentation $otherDocs $backgroundDocs $reportDocs;
  1771.             $eventDate date(
  1772.                 'F',
  1773.                 mktime(
  1774.                     0,
  1775.                     0,
  1776.                     0,
  1777.                     $event['month'],
  1778.                     10
  1779.                 )
  1780.             );
  1781.             $eventDate .= ' ' $event['year'];
  1782.             if (empty($eventCollection)) {
  1783.                 $eventCollection = array(
  1784.                     $eventDate => array($event)
  1785.                 );
  1786.             } else {
  1787.                 if (array_key_exists($eventDate$eventCollection)) {
  1788.                     $eventCollection[$eventDate][] = $event;
  1789.                 } else {
  1790.                     $eventCollection[$eventDate] = array($event);
  1791.                 }
  1792.             }
  1793.         }
  1794.         //start 4 months before the start date
  1795.         $earlierStart date(
  1796.             'Y-m-d',
  1797.             strtotime("$startdate -4 month")
  1798.         );
  1799.         //end where we started before
  1800.         $earlierEnd $startdate;
  1801.         //start where we left off
  1802.         $laterStart $enddate;
  1803.         //end 5 months after the later start date
  1804.         $laterEnd date(
  1805.             'Y-m-d',
  1806.             strtotime("$laterStart +5 month")
  1807.         );
  1808.         //dump($activeEventLabels);
  1809.         //die();
  1810.         return $this->render('Event/calendar.html.twig', array(
  1811.                 'data' => array(
  1812.                     'events' => $eventCollection,
  1813.                     //'eventTypes' => $eventTypes,
  1814.                     'eventTypes' => array(
  1815.                         'list' => $availableEventTypes,
  1816.                         'active' => $activeEventTypes
  1817.                     ),
  1818.                     'groups' => array(
  1819.                         'list' => $availableEventGroups,
  1820.                         'active' => $activeEventGroups
  1821.                     ),
  1822.                     'eventLabels' => array(
  1823.                         'list' => $availableEventLabels,
  1824.                         'active' => $activeEventLabels
  1825.                     ),
  1826.                     'date' => array(
  1827.                         'start' => $startdate,
  1828.                         'end' => $enddate
  1829.                     ),
  1830.                     'year' => array(
  1831.                         'list' => $years,
  1832.                         'active' => date('Y'strtotime($startdate)),
  1833.                     ),
  1834.                     'range' => array(
  1835.                         'earlier' => array(
  1836.                             'start' => $earlierStart,
  1837.                             'end' => $earlierEnd
  1838.                         ),
  1839.                         'later' => array(
  1840.                             'start' => $laterStart,
  1841.                             'end' => $laterEnd
  1842.                         )
  1843.                     )
  1844.                 )
  1845.             )
  1846.         );
  1847.     }
  1848.     /**
  1849.      *
  1850.      */
  1851.     public function listUserEventsAction($idInd)
  1852.     {
  1853.         $data $idInd;
  1854.         return $this->render('Event/listUserEvents.html.twig', array('data' => $data));
  1855.     }
  1856.     /**
  1857.      * create the PlanningWheel
  1858.      * get the info of events that
  1859.      * - are active
  1860.      * - have a priority set in the labels
  1861.      * - are within the next 11 months
  1862.      *
  1863.      * @return Response
  1864.      */
  1865.     public function viewPlanningWheelAction(): Response
  1866.     {
  1867.         // startdate is today
  1868.         // enddate is +11 months (to avoid confusion with the next year(s))
  1869.         $startdate date(
  1870.             'Y-m-d'
  1871.         );
  1872.         $enddate date(
  1873.             'Y-m-t',
  1874.             strtotime(
  1875.                 "+11 months",
  1876.                 strtotime(
  1877.                     date(
  1878.                         'Y-m-d'
  1879.                     )
  1880.                 )
  1881.             )
  1882.         );
  1883.         //get all the events that are active and have a priority set
  1884.         //this means they have a id labe set to 4 or 5 or 6
  1885.         //see $this->availableEventLabels
  1886.         //entity manager
  1887.         $em $this->getDoctrine()->getManager();
  1888.         //get all the info for the events within the date range
  1889.         //mind that concat only accepts single quotes in Doctrine :-(
  1890.         $repository $em->createQueryBuilder()
  1891.             ->add(
  1892.                 'select',
  1893.                 'e.title as name,
  1894.                 l.idLabel as priority,
  1895.                 e.startOn as date,
  1896.                 concat(\'/event/\', e.idEvent) as url'
  1897.             )
  1898.             ->add(
  1899.                 'from',
  1900.                 'OceanExpertBundle:Events e'
  1901.             )
  1902.             ->leftJoin(
  1903.                 'OceanExpertBundle:EventLabels',
  1904.                 'l',
  1905.                 'WITH',
  1906.                 'l.idEvent = e.idEvent'
  1907.             )
  1908.             ->where(
  1909.                 'e.status = 1'
  1910.             )
  1911.             ->andWhere(
  1912.                 'l.idLabel IN (4,5,6)'
  1913.             )
  1914.             ->andWhere(
  1915.                 "((e.startOn BETWEEN '$startdate' AND '$enddate') 
  1916.                 OR (e.endOn BETWEEN '$startdate' AND '$enddate'))"
  1917.             )
  1918.             ->orderBy(
  1919.                 'e.startOn'
  1920.             );
  1921.         $events $repository->getQuery()->getResult();
  1922.         foreach ($events as $key => $event) {
  1923.             //format the date as expected
  1924.             $events[$key]['date'] = $event['date']->format('Y-m-d');
  1925.             //correct the priority to match the wheel
  1926.             $events[$key]['priority'] = $event['priority'] - 3;
  1927.         }
  1928.         return $this->render(
  1929.             'Event/planningWheel.html.twig',
  1930.             array(
  1931.                 'events' => json_encode($events)
  1932.             )
  1933.         );
  1934.     }
  1935.     /**
  1936.      * show the info for an event, other views are used when making an event!!!
  1937.      *
  1938.      * @param int $event id of the event we want to see
  1939.      *
  1940.      * @return Response
  1941.      */
  1942.     public function viewEventAction($event)
  1943.     {
  1944.         $user = array();
  1945.         $user['canSendEmail'] = 0;
  1946.         $user['canEditEvent'] = 0;
  1947.         $isCreator 0;
  1948.         $isOrganiser 0;
  1949.         //container for errors
  1950.         $error '';
  1951.         //get database Connection
  1952.         $em $this->getDoctrine()->getManager();
  1953.         if (TRUE === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
  1954.             $query $this->getDoctrine()
  1955.                 ->getRepository('OceanExpertBundle:Indiv')
  1956.                 ->createQueryBuilder('i')
  1957.                 ->select('i.idInd,i.fname,i.sname,i.email1,i.email2')
  1958.                 ->where('i.idInd = :idInd')
  1959.                 ->setParameter('idInd'$this->get('security.token_storage')->getToken()->getUser())
  1960.                 ->getQuery();
  1961.             $user $query->getOneOrNullResult();
  1962.             $user['canSendEmail'] = 0;
  1963.             $user['canEditEvent'] = 0;
  1964.             if ($user) {
  1965.                 $isParticipant $em->getRepository('OceanExpertBundle:EventParticipants')
  1966.                     ->findOneBy(
  1967.                         array(
  1968.                             'idEvent' => $event,
  1969.                             'idInd' => $user['idInd']
  1970.                         )
  1971.                     );
  1972.                 $isCreator $em->getRepository('OceanExpertBundle:Events')
  1973.                     ->createQueryBuilder('e')
  1974.                     ->select('count(e.idEvent)')
  1975.                     ->where('e.createdBy =:idInd')
  1976.                     ->orWhere('e.lastEditBy =:idInd')
  1977.                     ->orWhere('e.idContact =:idInd')
  1978.                     ->andWhere('e.idEvent =:event')
  1979.                     ->setParameters(array('idInd' => $user['idInd'], 'event' => $event))
  1980.                     ->getQuery()->getSingleScalarResult();
  1981.                 $isOrganiser $em->getRepository('OceanExpertBundle:EventContacts')
  1982.                     ->findOneBy(
  1983.                         array(
  1984.                             'idEvent' => $event,
  1985.                             'idInd' => $user['idInd']
  1986.                         )
  1987.                     );
  1988.                 if ($isParticipant
  1989.                     || $isCreator == 1
  1990.                     || $isOrganiser == 1
  1991.                 ) {
  1992.                     $user['canSendEmail'] = 1;
  1993.                 }
  1994.             }
  1995.         }
  1996.         if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')
  1997.             || $isCreator == 1
  1998.             || $isOrganiser == 1
  1999.         ) {
  2000.             $eventDetails $em
  2001.                 ->getRepository('OceanExpertBundle:Events')
  2002.                 ->findOneBy(
  2003.                     array(
  2004.                         'idEvent' => $event
  2005.                     )
  2006.                 );
  2007.             $user['canSendEmail'] = 1;
  2008.             $user['canEditEvent'] = 1;
  2009.         } else {
  2010.             $eventDetails $em
  2011.                 ->getRepository('OceanExpertBundle:Events')
  2012.                 ->findOneBy(
  2013.                     array(
  2014.                         'idEvent' => $event,
  2015.                         'status' => 1
  2016.                     )
  2017.                 );
  2018.         }
  2019.         //get Event Type
  2020.         if (isset($eventDetails)) {
  2021.             $eventType $em->getRepository('OceanExpertBundle:Eventtypes')
  2022.                 ->findOneBy(
  2023.                     array(
  2024.                         'idEventtype' => $eventDetails->getIdEventtype()
  2025.                     )
  2026.                 );
  2027.             //get Country Events
  2028.             $eventImage $em->getRepository('OceanExpertBundle:EventFiles')
  2029.                 ->findOneBy(
  2030.                     array(
  2031.                         'idEvent' => $event
  2032.                     )
  2033.                 );
  2034.             //get the address to show in the view
  2035.             //this can be a custom address or the address of the institute
  2036.             //if there is no country set
  2037.             //  and we don't want to use the institute address,
  2038.             // we don't show the address
  2039.             $eventCountryCode 0;
  2040.             $organization '';
  2041.             if (($eventDetails->getIdCountry() != 0
  2042.                 && $eventDetails->getUseInstAddr() == 0)
  2043.                 || ($eventDetails->getUseInstAddr() != 0
  2044.                     && $eventDetails->getIdInst() != 0)
  2045.             ) {
  2046.                 if ($eventDetails->getUseInstAddr()) {
  2047.                     //get info about the institute
  2048.                     $institute $this->getDoctrine()
  2049.                         ->getRepository('OceanExpertBundle:Institutions')
  2050.                         ->findOneBy(
  2051.                             array(
  2052.                                 'idInst' => $eventDetails->getIdInst()
  2053.                             )
  2054.                         );
  2055.                     $eventAddressLine1 $institute->getInstAddress();
  2056.                     $eventPostcode $institute->getPostcode();
  2057.                     $eventCity $institute->getCity();
  2058.                     $eventState $institute->getState();
  2059.                     $eventCountryCode $institute->getCountryCode();
  2060.                     $organization $institute->getInstName();
  2061.                 } else {
  2062.                     $eventAddressLine1 $eventDetails->getAddress();
  2063.                     $eventPostcode $eventDetails->getPostcode();
  2064.                     $eventCity $eventDetails->getCity();
  2065.                     $eventState $eventDetails->getState();
  2066.                     $eventCountryCode $eventDetails->getIdCountry();
  2067.                 }
  2068.                 $country $em->getRepository('OceanExpertBundle:Countries')
  2069.                     ->findOneBy(
  2070.                         array(
  2071.                             'idCountry' => $eventCountryCode
  2072.                         )
  2073.                     );
  2074.                 //format the address with the correct country
  2075.                 $addressFormatRepository = new AddressFormatRepository();
  2076.                 $countryRepository = new CountryRepository();
  2077.                 $subdivisionRepository = new SubdivisionRepository();
  2078.                 $formatter = new DefaultFormatter(
  2079.                     $addressFormatRepository,
  2080.                     $countryRepository,
  2081.                     $subdivisionRepository
  2082.                 );
  2083.                 if (isset($country)
  2084.                     && $eventCountryCode != 0
  2085.                 ) {
  2086.                     $address = new Address();
  2087.                     $address $address
  2088.                         ->withCountryCode($country->getCountryCode())
  2089.                         ->withAdministrativeArea($eventState)
  2090.                         ->withLocality($eventCity)
  2091.                         ->withPostalCode($eventPostcode)
  2092.                         ->withAddressLine1($eventAddressLine1);
  2093.                     if ($organization != '') {
  2094.                         $address $address->withOrganization($organization);
  2095.                     }
  2096.                     $address $formatter->format($address);
  2097.                 } else {
  2098.                     $address 'no location defined or online event';
  2099.                 }
  2100.                 //Set event Address to use in view
  2101.                 $eventDetails->setAddress($address);
  2102.             } elseif ($eventDetails->getUseInstAddr() != 0
  2103.                 && $eventDetails->getIdInst() == 0) {
  2104.                 $error 'This event uses the address of an institute but no institute has been selected.';
  2105.             }
  2106.             //------------------ Get Organisers  ------------
  2107.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2108.             $repository->add('select''i.idInd as id, i.title, i.fname, i.sname');
  2109.             $repository->add('from''OceanExpertBundle:EventContacts e');
  2110.             $repository->leftJoin('OceanExpertBundle:Indiv''i''WITH''i.idInd = e.idInd');
  2111.             $repository->where('e.idEvent = :eventId');
  2112.             $repository->andWhere('i.sname is not null');
  2113.             $repository->setParameter('eventId'$event);
  2114.             $repository->orderBy('i.sname''ASC');
  2115.             $organisers $repository->getQuery()->getResult();
  2116.             //------------------ Get Staff  ------------
  2117.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2118.             $repository->add('select''i.idInd as id, i.title, i.fname, i.sname');
  2119.             $repository->add('from''OceanExpertBundle:EventStaff e');
  2120.             $repository->leftJoin('OceanExpertBundle:Indiv''i''WITH''i.idInd = e.idInd');
  2121.             $repository->where('e.idEvent = :eventId');
  2122.             $repository->setParameter('eventId'$event);
  2123.             $repository->orderBy('i.sname''ASC');
  2124.             $staff $repository->getQuery()->getResult();
  2125.             //------------------ Get Participant count  ------------
  2126.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2127.             $repository->add('select''count(e.idInd) as participants, e.status');
  2128.             $repository->add('from''OceanExpertBundle:EventParticipants e');
  2129.             $repository->where('e.idEvent = :eventId');
  2130.             $repository->groupBy('e.status');
  2131.             $repository->setParameter('eventId'$event);
  2132.             $participantArr $repository->getQuery()->getResult();
  2133.             $participant $provisional $unapproved $rejected $declined 0;
  2134.             foreach ($participantArr as $participants) {
  2135.                 switch ($participants['status']) {
  2136.                     case 0:
  2137.                         //confirmed and approved
  2138.                         $participant $participants['participants'];
  2139.                         break;
  2140.                     case 1:
  2141.                         //needs confirmation
  2142.                         $provisional $participants['participants'];
  2143.                         break;
  2144.                     case 2:
  2145.                         //needs approval
  2146.                         $unapproved $participants['participants'];
  2147.                         break;
  2148.                     case 3:
  2149.                         //declined
  2150.                         $declined $participants['participants'];
  2151.                         break;
  2152.                     case 4:
  2153.                         //rejected
  2154.                         $rejected $participants['participants'];
  2155.                         break;
  2156.                 }
  2157.             }
  2158.             $order '';
  2159.             $agenda $this->getAgendaItems($event);
  2160.             $agendaDocuments $this->getAgendaDocuments($event$order);
  2161.             $eventPresentations $this->getEventPresentations($event$order);
  2162.             $backgroundDocs $this->getBackgrounddocs($event$order);
  2163.             $otherDocs $this->getEventOtherDocs($event);
  2164.             $report $this->getEventReport($event);
  2165.             $participantlist $this->getEventParticipants($event);
  2166.             $participantsByRole $this->getParticipantsByRole($event);
  2167.             $eventGroups $this->getEventGroups($event);
  2168.             $edits $this->getEventEdits($event);
  2169.             $labels $this->getDoctrine()
  2170.                 ->getRepository('OceanExpertBundle:EventLabels')
  2171.                 ->createQueryBuilder('el')
  2172.                 ->select('g.groupname, el.idLabel')
  2173.                 ->leftJoin('OceanExpertBundle:Groups''g''WITH''g.idGroup = el.idGroup')
  2174.                 ->where('el.idEvent = :eventId')
  2175.                 ->setParameter(':eventId'$event)
  2176.                 ->orderBy('g.groupname')
  2177.                 ->getQuery()
  2178.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2179.             //add the label type to the labels
  2180.             //mind that the array id and the label id are not the same :-(
  2181.             foreach ($labels as $key => $label) {
  2182.                 $labels[$key]['labelType'] = $this->availableEventLabels[$label['idLabel']]['type'];
  2183.             }
  2184.             //make the array we need for OIH schema.org
  2185.             /*
  2186.             */
  2187.             $OIHTitle preg_replace(
  2188.                 "/[\n\r\t]+/",
  2189.                 ' - ',
  2190.                 trim(
  2191.                     strip_tags($eventDetails->getTitle())
  2192.                 )
  2193.             );
  2194.             $OIHData = array(
  2195.                 '@context' => array(
  2196.                     '@vocab' => 'https://schema.org/'
  2197.                 ),
  2198.                 "name" => $OIHTitle
  2199.             );
  2200.             if ($eventType
  2201.                 && $eventType->getIdEventtype() == 4
  2202.             ) {
  2203.                 $OIHData['@type'] = 'Course';
  2204.                 $OIHData['@id'] = 'https://oceanexpert.org/event/' $eventDetails->getIdEvent();
  2205.                 $OIHData['hasCourseInstance'] = array(
  2206.                     '@type' => 'CourseInstance',
  2207.                     "name" => $OIHTitle
  2208.                 );
  2209.                 if ($eventDetails->getStartOn() != '') {
  2210.                     $OIHData['hasCourseInstance']
  2211.                     ['startDate'] = $eventDetails->getStartOn()->format('Y-m-d');
  2212.                 }
  2213.                 if ($eventDetails->getEndOn() != '') {
  2214.                     $OIHData['hasCourseInstance']
  2215.                     ['endDate'] = $eventDetails->getEndOn()->format('Y-m-d');
  2216.                 }
  2217.                 if ($eventDetails->getAddress() != '') {
  2218.                     $OIHAddress preg_replace(
  2219.                         "/[\n\r\t]+/",
  2220.                         ' - ',
  2221.                         trim(
  2222.                             strip_tags($eventDetails->getAddress())
  2223.                         )
  2224.                     );
  2225.                     $OIHData['hasCourseInstance']
  2226.                     ['location'] = array(
  2227.                         '@type' => 'Place',
  2228.                         'name' => $OIHAddress,
  2229.                         'address' => $OIHAddress
  2230.                     );
  2231.                 }
  2232.                 //add the participants if we have any
  2233.                 $attendees = array();
  2234.                 if (count($participantlist)) {
  2235.                     foreach ($participantlist as  $oihParticipant) {
  2236.                         //this is the info we want to share
  2237.                         //OE id
  2238.                         $oihParticipantId $oihParticipant['id'];
  2239.                         //name
  2240.                         $oihParticipantName $oihParticipant['fname'] . ' ' $oihParticipant['sname'];
  2241.                         //title
  2242.                         $oihParticipantTitle $oihParticipant['title'];
  2243.                         $attendees[] = array(
  2244.                             '@type' => 'Person',
  2245.                             'name' => $oihParticipantName,
  2246.                             'jobTitle' => $oihParticipantTitle,
  2247.                             'identifier' => array(
  2248.                                 '@id' => 'ID_value_string',
  2249.                                 '@type' => 'PropertyValue',
  2250.                                 'propertyID' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2251.                                 'url' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2252.                                 'description' => 'UNESCO IOC IODE OceanExpert profile'
  2253.                             )
  2254.                         );
  2255.                     }
  2256.                 }
  2257.                 if (count($staff)) {
  2258.                     foreach ($staff as $oihStaff) {
  2259.                         //this is the info we want to share
  2260.                         //OE id
  2261.                         $oihParticipantId $oihStaff['id'];
  2262.                         //name
  2263.                         $oihParticipantName $oihStaff['fname'] . ' ' $oihStaff['sname'];
  2264.                         //title
  2265.                         $oihParticipantTitle $oihStaff['title'];
  2266.                         $attendees[] = array(
  2267.                             '@type' => 'Person',
  2268.                             'name' => $oihParticipantName,
  2269.                             'jobTitle' => $oihParticipantTitle,
  2270.                             'identifier' => array(
  2271.                                 '@id' => 'ID_value_string',
  2272.                                 '@type' => 'PropertyValue',
  2273.                                 'propertyID' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2274.                                 'url' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2275.                                 'description' => 'UNESCO IOC IODE OceanExpert profile'
  2276.                             )
  2277.                         );
  2278.                     }
  2279.                 }
  2280.                 if (count($organisers)) {
  2281.                     foreach ($organisers as $oihOrganiser) {
  2282.                         //this is the info we want to share
  2283.                         //OE id
  2284.                         $oihParticipantId $oihOrganiser['id'];
  2285.                         //name
  2286.                         $oihParticipantName $oihOrganiser['fname'] . ' ' $oihOrganiser['sname'];
  2287.                         //title
  2288.                         $oihParticipantTitle $oihOrganiser['title'];
  2289.                         $attendees[] = array(
  2290.                             '@type' => 'Person',
  2291.                             'name' => $oihParticipantName,
  2292.                             'jobTitle' => $oihParticipantTitle,
  2293.                             'identifier' => array(
  2294.                                 '@id' => 'ID_value_string',
  2295.                                 '@type' => 'PropertyValue',
  2296.                                 'propertyID' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2297.                                 'url' => 'https://oceanexpert.org/expert/' $oihParticipantId,
  2298.                                 'description' => 'UNESCO IOC IODE OceanExpert profile'
  2299.                             )
  2300.                         );
  2301.                     }
  2302.                 }
  2303.                 $OIHData['hasCourseInstance']
  2304.                 ['attendee'] = $attendees;
  2305.             } else {
  2306.                 $OIHData['@type'] = 'Event';
  2307.                 if ($eventDetails->getStartOn() != '') {
  2308.                     $OIHData['startDate'] = $eventDetails->getStartOn()->format('Y-m-d');
  2309.                 }
  2310.                 if ($eventDetails->getEndOn() != '') {
  2311.                     $OIHData['endDate'] = $eventDetails->getEndOn()->format('Y-m-d');
  2312.                 }
  2313.                 if ($eventDetails->getAddress() != '') {
  2314.                     $OIHAddress preg_replace(
  2315.                         "/[\n\r\t]+/",
  2316.                         ' - ',
  2317.                         trim(
  2318.                             strip_tags($eventDetails->getAddress())
  2319.                         )
  2320.                     );
  2321.                     $OIHData['location'] = array(
  2322.                         '@type' => 'Place',
  2323.                         'name' => $OIHAddress,
  2324.                         'address' => $OIHAddress
  2325.                     );
  2326.                 }
  2327.             }
  2328.             if ($eventDetails->getSummary() != '') {
  2329.                 $OIHSummary preg_replace(
  2330.                     "/[\n\r\t]+/",
  2331.                     ' - ',
  2332.                     trim(
  2333.                         strip_tags($eventDetails->getSummary())
  2334.                     )
  2335.                 );
  2336.                 $OIHData['description'] = $OIHSummary;
  2337.             }
  2338.             $OIHData json_encode(
  2339.                 $OIHData,
  2340.                 JSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES JSON_NUMERIC_CHECK
  2341.             );
  2342.             return $this->render('Event/event.html.twig',
  2343.                 array(
  2344.                     'data' => array(
  2345.                         'OIHData' => $OIHData,
  2346.                         'event' => array(
  2347.                             'eventImage' => $eventImage,
  2348.                             'details' => $eventDetails,
  2349.                             'type' => $eventType,
  2350.                             'people' => array(
  2351.                                 'organisers' => $organisers,
  2352.                                 'staff' => $staff,
  2353.                                 'participants' => $participantlist,
  2354.                                 'participantsByRole' => $participantsByRole,
  2355.                                 'numberOfParticipants' => $participant,
  2356.                                 'numberOfProvisional' => $provisional,
  2357.                                 'numberOfUnapproved' => $unapproved,
  2358.                                 'numberOfRejected' => $rejected,
  2359.                                 'numberOfDeclined' => $declined,
  2360.                                 'total' => $participant $provisional $unapproved count($staff) + count($organisers),
  2361.                             ),
  2362.                             'agenda' => $agenda,
  2363.                             'agendaDocuments' => $agendaDocuments,
  2364.                             'eventPresentations' => $eventPresentations,
  2365.                             'backgroundDocs' => $backgroundDocs,
  2366.                             'otherDocs' => $otherDocs,
  2367.                             'report' => $report,
  2368.                             'eventGroups' => $eventGroups,
  2369.                             'eventEdits' => $edits,
  2370.                             'eventLabels' => $labels
  2371.                         ),
  2372.                         'user' => $user,
  2373.                         'error' => $error
  2374.                     )
  2375.                 )
  2376.             );
  2377.         } else {
  2378.             return new RedirectResponse($this->generateUrl('event_calendar'));
  2379.         }
  2380.     }
  2381.     /**
  2382.      * @param int $event id of the event
  2383.      * @param string $order column to be used to order the results
  2384.      *
  2385.      * @return mixed
  2386.      */
  2387.     function getAgendaDocuments($event$order '')
  2388.     {
  2389.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2390.         $repository->add('select''a.idAgendaitem, d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
  2391.         $repository->add('from''OceanExpertBundle:AgendaitemDocuments a');
  2392.         $repository->leftJoin('OceanExpertBundle:Documents''d''WITH''d.idDoc = a.idDoc');
  2393.         $repository->where('a.idEvent = :eventId');
  2394.         $repository->setParameter('eventId'$event);
  2395.         if ($order == "date") {
  2396.             $repository->orderBy('d.updatedAt');
  2397.         } else {
  2398.             $repository->orderBy('a.idAgendaitem');
  2399.         }
  2400.         $agendaDocuments $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  2401.         return $agendaDocuments;
  2402.     }
  2403.     /**
  2404.      * get CSV file with information about the participants in a given event
  2405.      * is mainly used for, but not limited to, reporting for OTGA
  2406.      *
  2407.      * @param String $idEvent
  2408.      * @param Request $request
  2409.      *
  2410.      * @return Response
  2411.      */
  2412.     public function downloadEventParticipantsInfoAction(String $idEventRequest $request): Response
  2413.     {
  2414.         $participantsInfo $this->getPrintableParticipantsByRole($idEvent);
  2415.         $header = [];
  2416.         $return = [];
  2417.         //set this in the template as first line
  2418.         foreach($participantsInfo as $role => $participantInfo) {
  2419.             $returnRow = [];
  2420.             foreach ($participantInfo as $participant) {
  2421.                 $returnRow $participant;
  2422.                 //get rid of some info we do not want
  2423.                 unset($returnRow['idRole']);
  2424.                 unset($returnRow['status']);
  2425.                 //unset($returnRow['gender']);
  2426.                 unset($returnRow['tel']);
  2427.                 unset($returnRow['fax']);
  2428.                 unset($returnRow['ordering']);
  2429.                 //the complete address is already calculated
  2430.                 unset($returnRow['useInstAddr']);
  2431.                 unset($returnRow['addr1']);
  2432.                 unset($returnRow['addr2']);
  2433.                 unset($returnRow['state']);
  2434.                 unset($returnRow['city']);
  2435.                 unset($returnRow['postcode']);
  2436.                 unset($returnRow['countryCode']);
  2437.                 unset($returnRow['country']);
  2438.                 unset($returnRow['insAddr1']);
  2439.                 unset($returnRow['instAddr2']);
  2440.                 unset($returnRow['insCity']);
  2441.                 unset($returnRow['insState']);
  2442.                 unset($returnRow['insPostcode']);
  2443.                 unset($returnRow['insCountryCode']);
  2444.                 unset($returnRow['insCountry']);
  2445.                 //add some info we want
  2446.                 $returnRow['id'] = $returnRow['idInd'];
  2447.                 unset($returnRow['idInd']);
  2448.                 $returnRow['role'] = $role;
  2449.                 $returnRow['idEvent'] = $idEvent;
  2450.                 if (count($returnRow)) {
  2451.                     //make the header using the first correct row
  2452.                     if (!count($return)) {
  2453.                         $header array_keys($returnRow);
  2454.                         $header implode(';'$header);
  2455.                     }
  2456.                     $return[] = htmlspecialchars_decode(
  2457.                         strip_tags(
  2458.                             implode(
  2459.                                 ';',
  2460.                                 $returnRow
  2461.                             )
  2462.                         )
  2463.                     );
  2464.                 }
  2465.             }
  2466.         }
  2467.         $response $this->render(
  2468.             'Event/downloadEventParticipantsInfo.html.twig',
  2469.             array(
  2470.                 'header' => $header,
  2471.                 'data' => $return
  2472.             )
  2473.         );
  2474.         $response->headers->set(
  2475.             'Content-Type',
  2476.             'text/csv'
  2477.         );
  2478.         $response->headers->set(
  2479.             'Content-Disposition',
  2480.             'attachment; filename="eventParticipantsInfo' $idEvent '_' date('Ymd') . '.csv"'
  2481.         );
  2482.         return $response;
  2483.     }
  2484.     /**
  2485.      * @param $event
  2486.      * @return array
  2487.      */
  2488.     public function getParticipantsByRole($event)
  2489.     {
  2490.         $participants = array();
  2491.         $roles $this->getDoctrine()
  2492.             ->getRepository('OceanExpertBundle:EventParticipantroles')
  2493.             ->createQueryBuilder('e')
  2494.             ->select('e.role, e.idRole, e.pptOrdering')
  2495.             ->where('e.idEvent = :eventId')
  2496.             ->setParameter('eventId'$event)
  2497.             ->orderBy('e.ordering''asc')
  2498.             ->getQuery()
  2499.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  2500.         $roles[] = array(
  2501.             "role" => "Other",
  2502.             "idRole" => '',
  2503.             "pptOrdering" => '',
  2504.         );
  2505.         foreach ($roles as $role) {
  2506.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2507.             $repository->add(
  2508.                 'select',
  2509.                 'e.idRole, 
  2510.                 e.idInd, 
  2511.                 i.idInd as id, 
  2512.                 i.title, 
  2513.                 i.fname, 
  2514.                 i.sname, 
  2515.                 i.useInstAddr,
  2516.                 i.tel, 
  2517.                 r.role, 
  2518.                 c.country, 
  2519.                 r.role,
  2520.                 r.ordering, 
  2521.                 e.status, 
  2522.                 e.accommodation, 
  2523.                 i.tel'
  2524.             );
  2525.             $repository->add('from''OceanExpertBundle:EventParticipants e');
  2526.             $repository->leftJoin('OceanExpertBundle:Indiv''i''WITH''i.idInd = e.idInd');
  2527.             $repository->leftJoin('OceanExpertBundle:IndivInstitution''ii''WITH''ii.idInd = i.idInd');
  2528.             $repository->leftJoin('OceanExpertBundle:Institutions''ins''WITH''ins.idInst = ii.idInst');
  2529.             $repository->leftJoin('OceanExpertBundle:Countries''c''WITH''c.idCountry = i.countryCode');
  2530.             $repository->leftJoin('OceanExpertBundle:EventParticipantroles''r''WITH''e.idRole = r.idRole and e.idEvent = r.idEvent');
  2531.             $repository->where('e.idEvent = :eventId');
  2532.             if ($role['idRole'] != '') {
  2533.                 $repository->andwhere('e.idRole = :idRole');
  2534.                 $repository->setParameter('idRole'$role['idRole']);
  2535.             } else {
  2536.                 $repository->andwhere('e.idRole is NULL');
  2537.             }
  2538.             $repository->setParameter('eventId'$event);
  2539.             switch ($role['pptOrdering']) {
  2540.                 case 0:
  2541.                     $repository->addOrderBy('i.sname''asc');
  2542.                     break;
  2543.                 case 1:
  2544.                     $repository->addOrderBy('c.country''asc');
  2545.                     break;
  2546.                 case 2:
  2547.                     $repository->addOrderBy('ins.instName''asc');
  2548.                     break;
  2549.                 default:
  2550.                     $repository->addOrderBy('i.sname''asc');
  2551.                     break;
  2552.             }
  2553.             $participantsTmp $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  2554.             foreach ($participantsTmp as $key => $participant) {
  2555.                 //correct the country if the expert has choosen to use the institute address
  2556.                 if ($participant['useInstAddr'] === 1) {
  2557.                     //get the correct country, being the country of the institute
  2558.                     $participantsTmp[$key]['country'] = 'tbd';
  2559.                     $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2560.                     $repository->add(
  2561.                         'select',
  2562.                         'c.country'
  2563.                     );
  2564.                     $repository->add(
  2565.                         'from',
  2566.                         'OceanExpertBundle:Countries c'
  2567.                     );
  2568.                     $repository->leftJoin(
  2569.                         'OceanExpertBundle:Institutions',
  2570.                         'i',
  2571.                         'WITH',
  2572.                         'c.idCountry = i.countryCode'
  2573.                     );
  2574.                     $repository->leftJoin(
  2575.                         'OceanExpertBundle:IndivInstitution',
  2576.                         'ii',
  2577.                         'WITH',
  2578.                         'ii.idInst = i.idInst'
  2579.                     );
  2580.                     $repository->where('ii.idInd = :idInd');
  2581.                     $repository->setParameter('idInd'$participant['idInd']);
  2582.                     $country $repository->getQuery()->getResult();
  2583.                     if (isset($country[0])
  2584.                         && isset($country[0]['country'])
  2585.                         && $country[0]['country'] != ''
  2586.                     ) {
  2587.                         $participantsTmp[$key]['country'] = $country[0]['country'];
  2588.                     }
  2589.                 }
  2590.             }
  2591.             $participants[$role['role']] = $participantsTmp;
  2592.         }
  2593.         return $participants;
  2594.     }
  2595.     /**
  2596.      * @param $idEvent
  2597.      * @return array|EventGroups[]
  2598.      */
  2599.     private function getEventGroups($idEvent)
  2600.     {
  2601.         $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  2602.         $repository->add('select''eg.idGroup, g.groupname');
  2603.         $repository->add('from''OceanExpertBundle:EventGroups eg');
  2604.         $repository->leftJoin('OceanExpertBundle:Groups''g''WITH''g.idGroup = eg.idGroup');
  2605.         $repository->where('eg.idEvent =:idEvent');
  2606.         $repository->setParameter('idEvent'$idEvent);
  2607.         $repository->orderBy('g.groupname''asc');
  2608.         $eventGroups $repository->getQuery()->getResult();
  2609.         return $eventGroups;
  2610.     }
  2611.     /**
  2612.      * @param int $idEvent id of the event
  2613.      *
  2614.      * @return array
  2615.      */
  2616.     private function getEventEdits($idEvent)
  2617.     {
  2618.         $em $this->getDoctrine()->getManager();
  2619.         $event $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
  2620.         $lastEdit $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $event->getLastEditBy()));
  2621.         $created $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $event->getCreatedBy()));
  2622.         if ($lastEdit) {
  2623.             $edit['lastEditAt'] = $event->getUpdatedAt();
  2624.             $edit['lastEditBy'] = $lastEdit->getFname() . ' ' $lastEdit->getSname();
  2625.             $edit['lastEditId'] = $event->getLastEditBy();
  2626.         } else {
  2627.             $edit['lastEditAt'] = $event->getUpdatedAt();
  2628.             $edit['lastEditId'] = $event->getLastEditBy();
  2629.         }
  2630.         if ($created) {
  2631.             $edit['createdBy'] = $created->getFname() . ' ' $created->getSname();
  2632.             $edit['createdAt'] = $event->getCreatedAt();
  2633.             $edit['createdId'] = $event->getCreatedBy();
  2634.         } else {
  2635.             $edit['createdAt'] = $event->getCreatedAt();
  2636.             $edit['createdId'] = $event->getCreatedBy();
  2637.         }
  2638.         return $edit;
  2639.     }
  2640.     /**
  2641.      * @param $event
  2642.      * @return JsonResponse
  2643.      */
  2644.     public function eventImageUploadAction($event)
  2645.     {
  2646.         return new JsonResponse($_FILES);
  2647.     }
  2648.     /**
  2649.      * @param $idEvent
  2650.      * @param Request $request
  2651.      * @return JsonResponse
  2652.      */
  2653.     public function addAgendaItemAjaxAction($idEventRequest $request)
  2654.     {
  2655.         $data $request->request->all();
  2656.         $em $this->getDoctrine()->getManager();
  2657.         $agendaName = isset($data['agendaName']) ? $data['agendaName'] : '';
  2658.         $agendaNumber = isset($data['agendaNumber']) ? $data['agendaNumber'] : '';
  2659.         $agendaOrder 0;
  2660.         //the agenda item number should be unique for this event
  2661.         $em $this->getDoctrine()->getManager();
  2662.         $event $em->getRepository('OceanExpertBundle:EventAgendaitems')
  2663.             ->findOneBy(
  2664.                 array(
  2665.                     'idEvent' => $idEvent,
  2666.                     'idAgendaitem' => $agendaNumber
  2667.                 )
  2668.             );
  2669.         if ($event) {
  2670.             return new JsonResponse(
  2671.                 array(
  2672.                     'status' => 0,
  2673.                     'message' => 'Agenda item number already exists'
  2674.                 )
  2675.             );
  2676.         }
  2677.         if (isset($data['parentId']) && $data['parentId'] != "undefined") {
  2678.             $parentId $data['parentId'];
  2679.             $parent 0;
  2680.         } else {
  2681.             $parentId 0;
  2682.             $parent 1;
  2683.             $highest_id $em->createQueryBuilder()
  2684.                 ->select('MAX(e.agendaOrder)')
  2685.                 ->from('OceanExpertBundle:EventAgendaitems''e')
  2686.                 ->where('e.idEvent = :idEvent')
  2687.                 ->andWhere('e.parentIdevent = 0')
  2688.                 ->setParameter(':idEvent'$idEvent)
  2689.                 ->getQuery()
  2690.                 ->getSingleScalarResult();
  2691.             $agendaOrder $highest_id 1;
  2692.         }
  2693.         $agendaItem = new EventAgendaitems();
  2694.         $agendaItem->setIdEvent($idEvent);
  2695.         $agendaItem->setIdAgendaitem($agendaNumber);
  2696.         $agendaItem->setParentIdevent($parentId);
  2697.         $agendaItem->setTitle($agendaName);
  2698.         $agendaItem->setNotes('');
  2699.         $agendaItem->setRequiredActions('');
  2700.         $agendaItem->setAgendaOrder($agendaOrder);
  2701.         $em->persist($agendaItem);
  2702.         $em->flush();
  2703.         $this->updateEvent($idEvent);
  2704.         $id $agendaItem->getId();
  2705.         $agendaName $agendaItem->getTitle();
  2706.         return new JsonResponse(
  2707.             array(
  2708.                 'status' => 1,
  2709.                 'childGroup' => $id,
  2710.                 'groupName' => $agendaName,
  2711.                 'parent' => $parent
  2712.             )
  2713.         );
  2714.     }
  2715.     /**
  2716.      * @return boolean
  2717.      */
  2718.     public function updateEvent($idEvent)
  2719.     {
  2720.         //@todo this is not logic, normal user can copy an event but not edit it....
  2721.         if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')) {
  2722.             $em $this->getDoctrine()->getManager();
  2723.             $event $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
  2724.             $author $this->get('security.token_storage')->getToken()->getUser();
  2725.             $event->setLastEditBy($author->getId());
  2726.             $event->setUpdatedAt(new DateTime("now"));
  2727.             $em->persist($event);
  2728.             $em->flush();
  2729.         }
  2730.         return true;
  2731.     }
  2732.     /**
  2733.      * @param Request $request
  2734.      * @return JsonResponse
  2735.      */
  2736.     public function deleteAgendaItemAjaxAction(Request $request)
  2737.     {
  2738.         $idAgenda $request->request->get('agendaId');
  2739.         $idEvent $request->request->get('eventId');
  2740.         $em $this->getDoctrine()->getManager();
  2741.         $repository $em->getRepository('OceanExpertBundle:EventAgendaitems')->findById($idAgenda);
  2742.         if ($repository) {
  2743.             $agendaItems $em->getRepository('OceanExpertBundle:EventAgendaitems')->findOneBy(array('id' => $idAgenda));
  2744.             $id $agendaItems->getId();
  2745.             $em->remove($agendaItems);
  2746.             $em->flush();
  2747.             do {
  2748.                 $agendaItems $em->getRepository('OceanExpertBundle:EventAgendaitems')->findBy(array('parentIdevent' => $id));
  2749.                 if ($agendaItems) {
  2750.                     foreach ($agendaItems as $agendaItem) {
  2751.                         $id $agendaItem->getId();
  2752.                         $em->remove($agendaItem);
  2753.                     }
  2754.                     $em->flush();
  2755.                 } else {
  2756.                     $id 0;
  2757.                 }
  2758.             } while ($id != 0);
  2759.             $this->updateEvent($idEvent);
  2760.         }
  2761.         return new JsonResponse($idAgenda);
  2762.     }
  2763.     /**
  2764.      * @param Request $request
  2765.      * @return JsonResponse
  2766.      */
  2767.     public function updateAgendaItemAjaxAction(Request $request)
  2768.     {
  2769.         $idAgenda $request->request->get('idAgenda');
  2770.         $idEvent $request->request->get('idEvent');
  2771.         $action $request->request->get('action');
  2772.         $em $this->getDoctrine()->getManager();
  2773.         $agenda $em
  2774.             ->getRepository('OceanExpertBundle:EventAgendaitems')
  2775.             ->findOneBy(
  2776.                 array(
  2777.                     'id' => $idAgenda
  2778.                 )
  2779.             );
  2780.         if ($action == "edit") {
  2781.             $agendaName $request->request->get('agendaName');
  2782.             $agendaNumber $request->request->get('agendaNumber');
  2783.             $notes $request->request->get('notes');
  2784.             $actions $request->request->get('actions');
  2785.             $agenda->setIdAgendaitem($agendaNumber);
  2786.             $agenda->setTitle($agendaName);
  2787.             $agenda->setNotes($notes);
  2788.             $agenda->setRequiredActions($actions);
  2789.             $em->persist($agenda);
  2790.             $em->flush();
  2791.         }
  2792.         $this->updateEvent($idEvent);
  2793.         $agendaDetails = array(
  2794.             'idAgenda' => $agenda->getId(),
  2795.             'idAgendaItem' => $agenda->getIdAgendaitem(),
  2796.             'agendaTitle' => $agenda->getTitle(),
  2797.             'notes' => $agenda->getNotes(),
  2798.             'actions' => $agenda->getRequiredActions(),
  2799.             'status' => 1,
  2800.         );
  2801.         return new JsonResponse($agendaDetails);
  2802.     }
  2803.     /**
  2804.      * (self)register for an event
  2805.      *
  2806.      * @param int $idEvent id of the event
  2807.      *
  2808.      * @return RedirectResponse|Response|null
  2809.      */
  2810.     public function registerEventAction($idEventRequest $request)
  2811.     {
  2812.         //as we need the email address
  2813.         //check that the user is logged in
  2814.         //and has a complete profile
  2815.         if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  2816.             $user $this->get('security.token_storage')->getToken()->getUser();
  2817.             //let's check if the logged-in user has a 'real' profile
  2818.             //the mandatory profile fields are all filled and the expert is active
  2819.             $em $this->getDoctrine()->getManager();
  2820.             $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  2821.             if (!SecurityController::checkUserProfile($em$userId)) {
  2822.                 return $this->redirect(
  2823.                     $this->generateUrl(
  2824.                         'user_profile_edit'
  2825.                     )
  2826.                 );
  2827.             }
  2828.             $userEmail $user->getEmail();
  2829.         } else {
  2830.             //redirect to the login page
  2831.             return $this->redirect(
  2832.                 $this->generateUrl(
  2833.                     'fos_user_security_login',
  2834.                     array(
  2835.                     )
  2836.                 )
  2837.             );
  2838.         }
  2839.         $event $em
  2840.             ->getRepository('OceanExpertBundle:Events')
  2841.             ->findOneBy(
  2842.                 array(
  2843.                     'idEvent' => $idEvent
  2844.                 )
  2845.             );
  2846.         $eventCountry $em
  2847.             ->getRepository('OceanExpertBundle:Countries')
  2848.             ->findOneBy(
  2849.                 array(
  2850.                     'idCountry' => $event->getIdCountry()
  2851.                 )
  2852.             );
  2853.         if (!isset($eventCountry)
  2854.             || !($eventCountry->getCountry())
  2855.         ) {
  2856.             $eventCountry 'country not specified (yet)';
  2857.         } else {
  2858.             $eventCountry $eventCountry->getCountry();
  2859.         }
  2860.         $status = array();
  2861.         if ($request->isMethod('POST')) {
  2862.             //user wants to (self)register
  2863.             //even while we already checked the user's email address
  2864.             // and checked that the profile exists, we still need to check
  2865.             // if the user is active
  2866.             $query $this->getDoctrine()
  2867.                 ->getRepository('OceanExpertBundle:Indiv')
  2868.                 ->createQueryBuilder('i')
  2869.                 ->select('
  2870.                     i.idInd,
  2871.                     i.fname,
  2872.                     i.sname,
  2873.                     i.email1,
  2874.                     i.email2'
  2875.                 )
  2876.                 ->where('i.email1 = :email')
  2877.                 ->orWhere('i.email2 = :email')
  2878.                 ->andWhere('i.status = 1')
  2879.                 ->setParameter('email'$userEmail)
  2880.                 ->getQuery();
  2881.             $participant $query->getOneOrNullResult();
  2882.             if ($participant) {
  2883.                 $eventParticipants $em
  2884.                     ->getRepository('OceanExpertBundle:EventParticipants')
  2885.                     ->findOneBy(
  2886.                         array(
  2887.                             'idEvent' => $idEvent,
  2888.                             'idInd' => $participant['idInd']
  2889.                         )
  2890.                     );
  2891.                 if ($eventParticipants) {
  2892.                     //get some info about the user's status as participant
  2893.                     //skip the rest and show the register page with warning about status
  2894.                     $status = array(
  2895.                         'user' => $this->getExpertById($participant['idInd']),
  2896.                         'userEventStatus' => $eventParticipants->getStatus(),
  2897.                     );
  2898.                 } else {
  2899.                     $eventParticipants = new EventParticipants();
  2900.                     $eventParticipants->setIdEvent($idEvent);
  2901.                     $eventParticipants->setIdInd($participant['idInd']);
  2902.                     $eventParticipants->setStatus(2);
  2903.                     $eventParticipants->setArriveOn(
  2904.                         new DateTime(
  2905.                             date(
  2906.                                 'd-m-Y',
  2907.                                 strtotime($request->request->get('arriveOn'))
  2908.                             )
  2909.                         )
  2910.                     );
  2911.                     $eventParticipants->setLeaveOn(
  2912.                         new DateTime(
  2913.                             date(
  2914.                                 'd-m-Y',
  2915.                                 strtotime($request->request->get('leaveOn'))
  2916.                             )
  2917.                         )
  2918.                     );
  2919.                     $eventParticipants->setAccommodation(
  2920.                         $request->request->get('accomodation')
  2921.                     );
  2922.                     $eventParticipants->setContactTel(
  2923.                         $request->request->get('contact')
  2924.                     );
  2925.                     $eventParticipants->setStatusChangedAt(
  2926.                         new DateTime()
  2927.                     );
  2928.                     $em->persist($eventParticipants);
  2929.                     $em->flush();
  2930.                     $url $this->generateUrl(
  2931.                         'view_event',
  2932.                         array(
  2933.                             'event' => $idEvent
  2934.                         )
  2935.                     );
  2936.                     return $this->redirect(
  2937.                         sprintf(
  2938.                             '%s#%s',
  2939.                             $url,
  2940.                             'participants'
  2941.                         )
  2942.                     );
  2943.                 }
  2944.             } else {
  2945.                 $status = array(
  2946.                     'userStatus' => 'not active',
  2947.                     'user' => '',
  2948.                     'userEventStatus' => ''
  2949.                 );
  2950.             }
  2951.         }
  2952.         $data = array(
  2953.             'event' => $event,
  2954.             'eventCountry' => $eventCountry,
  2955.             'status' => $status,
  2956.             'email' => $userEmail
  2957.         );
  2958.         return $this->render(
  2959.             'Event/registerEvent.html.twig',
  2960.             array(
  2961.                 'data' => $data
  2962.             )
  2963.         );
  2964.     }
  2965.     /**
  2966.      * @param int $idInd id of the expert
  2967.      *
  2968.      * @return mixed
  2969.      */
  2970.     private function getExpertById($idInd)
  2971.     {
  2972.         $query $this->getDoctrine()
  2973.             ->getRepository('OceanExpertBundle:Indiv')
  2974.             ->createQueryBuilder('i')
  2975.             ->select('i.idInd, i.title, i.fname, i.sname, i.email1, i.email2')
  2976.             ->where('i.idInd = :idInd')
  2977.             ->setParameter('idInd'$idInd)
  2978.             ->getQuery();
  2979.         return $query->getOneOrNullResult();
  2980.     }
  2981.     /**
  2982.      * @param $eventId
  2983.      */
  2984.     public function updateEventAgenda($eventId)
  2985.     {
  2986.         //@todo there is a function to get the agenda items
  2987.         $agendaItems $this->getDoctrine()->getManager()
  2988.             ->getRepository('OceanExpertBundle:EventAgendaitems')
  2989.             ->findBy(array('idEvent' => $eventId));
  2990.         $em $this->getDoctrine()->getManager();
  2991.         foreach ($agendaItems as $agendaItem) {
  2992.             $items explode('.'$agendaItem->getIdAgendaitem());
  2993.             $parentId 0;
  2994.             if (count($items) > 1) {
  2995.                 $parentArr array_slice($items0, -1);
  2996.                 $parent implode("."$parentArr);
  2997.                 $parentItem $this->getDoctrine()->getManager()
  2998.                     ->getRepository('OceanExpertBundle:EventAgendaitems')
  2999.                     ->findOneBy(
  3000.                         array(
  3001.                             'idEvent' => $eventId,
  3002.                             'idAgendaitem' => $parent
  3003.                         )
  3004.                     );
  3005.                 $parentId $parentItem->getId();
  3006.             }
  3007.             $agendaItem->setParentIdevent($parentId);
  3008.             $em->persist($agendaItem);
  3009.             $em->flush();
  3010.         }
  3011.         $this->updateEvent($eventId);
  3012.     }
  3013.     /**
  3014.      * add a participant to the list of participant for a given event
  3015.      *
  3016.      * @return JsonResponse
  3017.      */
  3018.     public function addEventMemberAction(Request $requestTokenGeneratorInterface $fosTokenGeneratorUserManagerInterface $fosUserManager)
  3019.     {
  3020.         $idInd $request->request->get('idInd');
  3021.         $idEvent $request->request->get('idEvent');
  3022.         $membertype $request->request->get('membertype');
  3023.         $name $request->request->get('name');
  3024.         $em $this->getDoctrine()->getManager();
  3025.         $participantRoles = array();
  3026.         $status 0;
  3027.         //why did the status not change to 1
  3028.         $reason '';
  3029.         //get the correct email address of the user
  3030.         $user $this->getDoctrine()->getManager()
  3031.             ->getRepository('OceanExpertBundle:Indiv')
  3032.             ->findOneBy(
  3033.                 array(
  3034.                     'idInd' => $idInd
  3035.                 )
  3036.             );
  3037.         if ($user) {
  3038.             $email1 $user->getEmail1();
  3039.             $email2 $user->getEmail2();
  3040.             if ($email2 != '') {
  3041.                 $email $email2;
  3042.             } elseif ($email1 != '') {
  3043.                 $email $email1;
  3044.             } else {
  3045.                 $email 'info@oceanexpert.org';
  3046.             }
  3047.         } else {
  3048.             $reason 'user not found';
  3049.         }
  3050.         //get the info about the event
  3051.         $eventInfo $this->getDoctrine()->getManager()
  3052.             ->getRepository('OceanExpertBundle:Events')
  3053.             ->findOneBy(
  3054.                 array(
  3055.                     'idEvent' => $idEvent
  3056.                 )
  3057.             );
  3058.         if (!$eventInfo) {
  3059.             $reason 'event not found';
  3060.         } else {
  3061.             if ($membertype == 1) {
  3062.                 $participantType 'event organiser';
  3063.                 $eventStaff $this->getDoctrine()->getManager()
  3064.                     ->getRepository('OceanExpertBundle:EventContacts')
  3065.                     ->findBy(
  3066.                         array(
  3067.                             'idEvent' => $idEvent,
  3068.                             'idInd' => $idInd
  3069.                         )
  3070.                     );
  3071.                 if (!$eventStaff) {
  3072.                     $eventContact = new EventContacts();
  3073.                     $eventContact->setIdEvent($idEvent);
  3074.                     $eventContact->setIdInd($idInd);
  3075.                     $eventContact->setContactFor('');
  3076.                     $em->persist($eventContact);
  3077.                     $em->flush();
  3078.                     $status 1;
  3079.                 } else {
  3080.                     $reason 'already in event contacts';
  3081.                 }
  3082.             } elseif ($membertype == 2) {
  3083.                 $participantType 'event staff member';
  3084.                 $eventStaff $this->getDoctrine()->getManager()
  3085.                     ->getRepository('OceanExpertBundle:EventStaff')
  3086.                     ->findBy(
  3087.                         array(
  3088.                             'idEvent' => $idEvent,
  3089.                             'idInd' => $idInd
  3090.                         )
  3091.                     );
  3092.                 if (!$eventStaff) {
  3093.                     $eventStaff = new EventStaff();
  3094.                     $eventStaff->setIdEvent($idEvent);
  3095.                     $eventStaff->setIdInd($idInd);
  3096.                     $em->persist($eventStaff);
  3097.                     $em->flush();
  3098.                     $status 1;
  3099.                 } else {
  3100.                     $reason 'is already in the event staff';
  3101.                 }
  3102.             } elseif ($membertype == 3) {
  3103.                 $participantType 'event participant';
  3104.                 $eventParticipant $this->getDoctrine()->getManager()
  3105.                     ->getRepository('OceanExpertBundle:EventParticipants')
  3106.                     ->findBy(
  3107.                         array(
  3108.                             'idEvent' => $idEvent,
  3109.                             'idInd' => $idInd
  3110.                         )
  3111.                     );
  3112.                 if (!$eventParticipant) {
  3113.                     $eventParticipant = new EventParticipants();
  3114.                     $eventParticipant->setIdEvent($idEvent);
  3115.                     $eventParticipant->setStatus(1);
  3116.                     $eventParticipant->setIdInd($idInd);
  3117.                     $em->persist($eventParticipant);
  3118.                     $em->flush();
  3119.                     $status 1;
  3120.                 } else {
  3121.                     $reason 'already in event participants';
  3122.                 }
  3123.                 $participantRoles $this->getDoctrine()
  3124.                     ->getRepository('OceanExpertBundle:EventParticipantroles')
  3125.                     ->createQueryBuilder('e')
  3126.                     ->select('e.idRole,e.role')
  3127.                     ->where('e.idEvent = :eventId')
  3128.                     ->setParameter('eventId'$idEvent)
  3129.                     ->getQuery()
  3130.                     ->getResult(AbstractQuery::HYDRATE_ARRAY);
  3131.             } elseif ($membertype == 4) {
  3132.                 $participantType 'event observer';
  3133.                 $eventInfo->setIdContact($idInd);
  3134.                 $em->persist($eventInfo);
  3135.                 $em->flush();
  3136.                 $status 1;
  3137.             }
  3138.             $this->updateEvent($idEvent);
  3139.         }
  3140.         if ($reason === '') {
  3141.             $participantCountry $this->getDoctrine()
  3142.                 ->getRepository('OceanExpertBundle:Indiv')
  3143.                 ->createQueryBuilder('i')
  3144.                 ->leftJoin('OceanExpertBundle:Countries''c''WITH''i.countryCode = c.idCountry')
  3145.                 ->select('c.country')
  3146.                 ->where('i.idInd = :idInd')
  3147.                 ->setParameter('idInd'$idInd)
  3148.                 ->getQuery()
  3149.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  3150.         } else {
  3151.             $participantCountry = array();
  3152.             $participantCountry[0]['country'] = '';
  3153.         }
  3154.         $data = array(
  3155.             'idInd' => $idInd,
  3156.             'name' => $name,
  3157.             'participantRoles' => $participantRoles,
  3158.             'participantCountry' => $participantCountry[0]['country'],
  3159.             'memberType' => $membertype,
  3160.         );
  3161.         $event = array(
  3162.             'idEvent' => $idEvent,
  3163.             'title' => $eventInfo->getTitle(),
  3164.             'eventPeriod' => $eventInfo->getStartOn()->format('d-m-Y') . ' to ' $eventInfo->getEndOn()->format('d-m-Y'),
  3165.             'eventAddress' => $eventInfo->getAddress(),
  3166.             'eventUrl' => $this->generateUrl(
  3167.                 'view_event',
  3168.                 array(
  3169.                     'event' => $idEvent
  3170.                 ),
  3171.                 UrlGeneratorInterface::ABSOLUTE_URL
  3172.             )
  3173.         );
  3174.         //send an email to the user to let them know they have been added to the event
  3175.         if ($eventInfo->getEmailPeople()
  3176.             && $reason === ''
  3177.         ) {
  3178.             //who is sending this mail
  3179.             $sendUser $this->getDoctrine()->getManager()
  3180.                 ->getRepository('OceanExpertBundle:Indiv')
  3181.                 ->findOneBy(
  3182.                     array(
  3183.                         'idInd' => $eventInfo->getIdContact()
  3184.                     )
  3185.                 );
  3186.             if ($sendUser) {
  3187.                 $firstName $sendUser->getFName();
  3188.                 $lastName $sendUser->getSName();
  3189.                 if ($firstName != '' && $lastName != '') {
  3190.                     $fromEmail = array(
  3191.                         'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' $firstName ' ' $lastName
  3192.                     );
  3193.                 } else {
  3194.                     $fromEmail = array(
  3195.                         'info@oceanexpert.org' => 'OceanExpert Team'
  3196.                     );
  3197.                 }
  3198.             } else {
  3199.                 $fromEmail =array(
  3200.                     'info@oceanexpert.org' => 'OceanExpert Team'
  3201.                 );
  3202.             }
  3203.             $message = new Swift_Message(
  3204.                 'Participation in an event',
  3205.                 $this->renderView(
  3206.                     'Email/eventAddParticipant.html.twig',
  3207.                     array(
  3208.                         'data' => $data,
  3209.                         'event' => $event,
  3210.                         'participantType' => $participantType
  3211.                     )
  3212.                 ),
  3213.                 'text/html'
  3214.             );
  3215.             $message->setFrom(
  3216.                 $fromEmail
  3217.             );
  3218.             $message->setTo(
  3219.                 array(
  3220.                     $email => $name
  3221.                 )
  3222.             );
  3223.             $this->get('mailer')->send($message);
  3224.             $comment 'sent mail to ' $email;
  3225.         } elseif (!$eventInfo->getEmailPeople()) {
  3226.             $comment 'no mail sent as this option is not set';
  3227.         }
  3228.         $return = array(
  3229.             'data' => $data,
  3230.             'status' => $status
  3231.         );
  3232.         if ($reason !== '') {
  3233.             $return['reason'] = $reason;
  3234.         }
  3235.         //add some comment if any
  3236.         if ($comment !== '') {
  3237.             $return['comment'] = $comment;
  3238.         }
  3239.         return new JsonResponse(
  3240.             $return
  3241.         );
  3242.     }
  3243.     /**
  3244.      * @return JsonResponse
  3245.      */
  3246.     public function deleteEventMemberAction(Request $request)
  3247.     {
  3248.         $idInd $request->request->get('idInd');
  3249.         $idEvent $request->request->get('idEvent');
  3250.         $membertype $request->request->get('membertype');
  3251.         $comment '';
  3252.         $em $this->getDoctrine()->getManager();
  3253.         switch ($membertype) {
  3254.             case 1:
  3255.                 $eventContact $this->getDoctrine()->getManager()
  3256.                     ->getRepository('OceanExpertBundle:EventContacts')
  3257.                     ->findOneBy(
  3258.                         array(
  3259.                             'idEvent' => $idEvent,
  3260.                             'idInd' => $idInd
  3261.                         )
  3262.                     );
  3263.                 if ($eventContact) {
  3264.                     $em->remove($eventContact);
  3265.                     $em->flush();
  3266.                 }
  3267.                 break;
  3268.             case 2:
  3269.                 $eventStaff $this->getDoctrine()->getManager()
  3270.                     ->getRepository('OceanExpertBundle:EventStaff')
  3271.                     ->findOneBy(
  3272.                         array(
  3273.                             'idEvent' => $idEvent,
  3274.                             'idInd' => $idInd
  3275.                         )
  3276.                     );
  3277.                 if ($eventStaff) {
  3278.                     $em->remove($eventStaff);
  3279.                     $em->flush();
  3280.                 }
  3281.                 break;
  3282.             case 3:
  3283.                 $eventParticipant $this->getDoctrine()->getManager()
  3284.                     ->getRepository('OceanExpertBundle:EventParticipants')
  3285.                     ->findOneBy(
  3286.                         array(
  3287.                             'idEvent' => $idEvent,
  3288.                             'idInd' => $idInd
  3289.                         )
  3290.                     );
  3291.                 if ($eventParticipant) {
  3292.                     $em->remove($eventParticipant);
  3293.                     $em->flush();
  3294.                 }
  3295.                 break;
  3296.         }
  3297.         //send an email to the user to let them know they have been removed from the event
  3298.         $eventInfo $this->getDoctrine()->getManager()
  3299.             ->getRepository('OceanExpertBundle:Events')
  3300.             ->findOneBy(
  3301.                 array(
  3302.                     'idEvent' => $idEvent
  3303.                 )
  3304.             );
  3305.         if ($eventInfo->getEmailPeople()) {
  3306.             //get the name and email of the participant
  3307.             $participant $this->getDoctrine()->getManager()
  3308.                 ->getRepository('OceanExpertBundle:Indiv')
  3309.                 ->findOneBy(
  3310.                     array(
  3311.                         'idInd' => $idInd
  3312.                     )
  3313.                 );
  3314.             //strange construction to keep this compatible with the other send mail code
  3315.             //this will make it easier to refactor this later
  3316.             $data['name'] = $participant->getTitle() . ' ' $participant->getFName() . ' ' $participant->getSName();
  3317.             $participantEmail1 $participant->getEmail1();
  3318.             $participantEmail2 $participant->getEmail2();
  3319.             if ($participantEmail2 != '') {
  3320.                 $email $participantEmail2;
  3321.             } elseif ($participantEmail1 != '') {
  3322.                 $email $participantEmail1;
  3323.             }
  3324.             //who is sending this mail
  3325.             $sendUser $this->getDoctrine()->getManager()
  3326.                 ->getRepository('OceanExpertBundle:Indiv')
  3327.                 ->findOneBy(
  3328.                     array(
  3329.                         'idInd' => $eventInfo->getIdContact()
  3330.                     )
  3331.                 );
  3332.             if ($sendUser) {
  3333.                 $firstName $sendUser->getFName();
  3334.                 $lastName $sendUser->getSName();
  3335.                 if ($firstName != '' && $lastName != '') {
  3336.                     $fromEmail = array(
  3337.                         'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' $firstName ' ' $lastName
  3338.                     );
  3339.                 } else {
  3340.                     $fromEmail = array(
  3341.                         'info@oceanexpert.org' => 'OceanExpert Team'
  3342.                     );
  3343.                 }
  3344.             } else {
  3345.                 $fromEmail =array(
  3346.                     'info@oceanexpert.org' => 'OceanExpert Team'
  3347.                 );
  3348.             }
  3349.             $event['title'] = $eventInfo->getTitle();
  3350.             $event['eventAddress'] = $eventInfo->getAddress();
  3351.             $event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' $eventInfo->getEndOn()->format('d-m-Y');
  3352.             $event['eventUrl'] = $this->generateUrl(
  3353.                 'view_event',
  3354.                 array(
  3355.                     'event' => $idEvent
  3356.                 ),
  3357.                 UrlGeneratorInterface::ABSOLUTE_URL
  3358.             );
  3359.             $message = new Swift_Message(
  3360.                 'Participation in an event',
  3361.                 $this->renderView(
  3362.                     'Email/eventDeleteParticipant.html.twig',
  3363.                     array(
  3364.                         'data' => $data,
  3365.                         'event' => $event
  3366.                     )
  3367.                 ),
  3368.                 'text/html'
  3369.             );
  3370.             $message->setFrom(
  3371.                 $fromEmail
  3372.             );
  3373.             $message->setTo(
  3374.                 array(
  3375.                     $email => $data['name']
  3376.                 )
  3377.             );
  3378.             $this->get('mailer')->send($message);
  3379.             $comment 'sent mail to ' $email;
  3380.         } elseif (!$eventInfo->getEmailPeople()) {
  3381.             $comment 'no mail sent as this option is not set';
  3382.         }
  3383.         return new JsonResponse(
  3384.             array(
  3385.                 'status' => 1,
  3386.                 'id' => $membertype,
  3387.                 'comment' => $comment
  3388.             )
  3389.         );
  3390.     }
  3391.     /**
  3392.      * change some settings of a event participant
  3393.      * this is called by AJAX when either
  3394.      * - changing the role
  3395.      * - changing the status
  3396.      * - changing the comments
  3397.      * this is not the same as editParticipantAction()
  3398.      *
  3399.      * @return JsonResponse
  3400.      */
  3401.     public function editEventMemberAction(Request $request)
  3402.     {
  3403.         $data $request->request->all();
  3404.         $idEvent $data['idEvent'];
  3405.         $idInd $data['idInd'];
  3406.         $em $this->getDoctrine()->getManager();
  3407.         $eventParticipant $em
  3408.             ->getRepository('OceanExpertBundle:EventParticipants')
  3409.             ->findOneBy(
  3410.                 array(
  3411.                     'idEvent' => $idEvent,
  3412.                     'idInd' => $idInd
  3413.                 )
  3414.             );
  3415.         if (isset($data['idRole'])) {
  3416.             $idRole $data['idRole'];
  3417.             //get information about the old role
  3418.             $oldRoleId $eventParticipant->getIdRole();
  3419.             $oldRole $this->getDoctrine()->getManager()
  3420.                 ->getRepository('OceanExpertBundle:EventParticipantroles')
  3421.                 ->findOneBy(
  3422.                     array(
  3423.                         'idRole' => $oldRoleId,
  3424.                         'idEvent' => $idEvent
  3425.                     )
  3426.                 );
  3427.             if ($oldRole) {
  3428.                 $oldRole $oldRole->getRole();
  3429.             } else {
  3430.                 $oldRole 'no role';
  3431.             }
  3432.             //set the new roleid
  3433.             $eventParticipant->setIdRole($idRole);
  3434.             //get info about the new role
  3435.             $role $this->getDoctrine()->getManager()
  3436.                 ->getRepository('OceanExpertBundle:EventParticipantroles')
  3437.                 ->findOneBy(
  3438.                     array(
  3439.                         'idRole' => $idRole,
  3440.                         'idEvent' => $idEvent
  3441.                     )
  3442.                 );
  3443.             $role $role->getRole();
  3444.             $mailContent "role changed from '$oldRole' to '$role'";
  3445.         } elseif (isset($data['comments'])) {
  3446.             $oldComments $eventParticipant->getAccommodation();
  3447.             $eventParticipant->setAccommodation($data['comments']);
  3448.             $mailContent "comments changed from '$oldComments' to '" $data['comments'] . '"';
  3449.         } elseif (isset($data['status'])) {
  3450.             $oldStatus $this->participantStatus[$eventParticipant->getStatus()];
  3451.             $status $this->participantStatus[$data['status']];
  3452.             $eventParticipant->setStatus($data['status']);
  3453.             $mailContent "status changed from '$oldStatus' to '$status'";
  3454.         }
  3455.         $em->persist($eventParticipant);
  3456.         $em->flush();
  3457.         $this->updateEvent($data['idEvent']);
  3458.         //send an email to the user to warn that something has changed
  3459.         $eventInfo $this->getDoctrine()->getManager()
  3460.             ->getRepository('OceanExpertBundle:Events')
  3461.             ->findOneBy(
  3462.                 array(
  3463.                     'idEvent' => $idEvent
  3464.                 )
  3465.             );
  3466.         if ($eventInfo->getEmailPeople()) {
  3467.             //get the name and email of the participant
  3468.             $participant $this->getDoctrine()->getManager()
  3469.                 ->getRepository('OceanExpertBundle:Indiv')
  3470.                 ->findOneBy(
  3471.                     array(
  3472.                         'idInd' => $idInd
  3473.                     )
  3474.                 );
  3475.             //strange construction to keep this compatible with the other send mail code
  3476.             //this will make it easier to refactor this later
  3477.             $data['name'] = $participant->getTitle() . ' ' $participant->getFName() . ' ' $participant->getSName();
  3478.             $participantEmail1 $participant->getEmail1();
  3479.             $participantEmail2 $participant->getEmail2();
  3480.             if ($participantEmail2 != '') {
  3481.                 $email $participantEmail2;
  3482.             } elseif ($participantEmail1 != '') {
  3483.                 $email $participantEmail1;
  3484.             }
  3485.             //who is sending this mail
  3486.             $sendUser $this->getDoctrine()->getManager()
  3487.                 ->getRepository('OceanExpertBundle:Indiv')
  3488.                 ->findOneBy(
  3489.                     array(
  3490.                         'idInd' => $eventInfo->getIdContact()
  3491.                     )
  3492.                 );
  3493.             if ($sendUser) {
  3494.                 $firstName $sendUser->getFName();
  3495.                 $lastName $sendUser->getSName();
  3496.                 if ($firstName != '' && $lastName != '') {
  3497.                     $fromEmail = array(
  3498.                         'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' $firstName ' ' $lastName
  3499.                     );
  3500.                 } else {
  3501.                     $fromEmail = array(
  3502.                         'info@oceanexpert.org' => 'OceanExpert Team'
  3503.                     );
  3504.                 }
  3505.             } else {
  3506.                 $fromEmail =array(
  3507.                     'info@oceanexpert.org' => 'OceanExpert Team'
  3508.                 );
  3509.             }
  3510.             $event['title'] = $eventInfo->getTitle();
  3511.             $event['eventAddress'] = $eventInfo->getAddress();
  3512.             $event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' $eventInfo->getEndOn()->format('d-m-Y');
  3513.             $event['eventUrl'] = $this->generateUrl(
  3514.                 'view_event',
  3515.                 array(
  3516.                     'event' => $idEvent
  3517.                 ),
  3518.                 UrlGeneratorInterface::ABSOLUTE_URL
  3519.             );
  3520.             $message = new Swift_Message(
  3521.                 'Participation in an event',
  3522.                 $this->renderView(
  3523.                     'Email/eventEditParticipant.html.twig',
  3524.                     array(
  3525.                         'data' => $data,
  3526.                         'event' => $event,
  3527.                         'mailContent' => $mailContent
  3528.                     )
  3529.                 ),
  3530.                 'text/html'
  3531.             );
  3532.             $message->setFrom(
  3533.                 $fromEmail
  3534.             );
  3535.             $message->setTo(
  3536.                 array(
  3537.                     $email => $data['name']
  3538.                 )
  3539.             );
  3540.             $this->get('mailer')->send($message);
  3541.             $comment 'sent mail to ' $email;
  3542.         } elseif (!$eventInfo->getEmailPeople()) {
  3543.             $comment 'no mail sent as this option is not set';
  3544.         }
  3545.         return new JsonResponse(
  3546.             array(
  3547.                 'status' => 1,
  3548.                 'paricipant' => $eventParticipant,
  3549.                 'comment' => $comment,
  3550.                 'mailContent' => $mailContent
  3551.             )
  3552.         );
  3553.     }
  3554.     /**
  3555.      * change the info linked to a event contact/organiser
  3556.      * this is called by AJAX
  3557.      *
  3558.      * @return JsonResponse
  3559.      */
  3560.     public function editEventContactsAction(Request $request)
  3561.     {
  3562.         $idInd $request->request->get('idInd');
  3563.         $idEvent $request->request->get('idEvent');
  3564.         $contactfor $request->request->get('contactfor');
  3565.         $em $this->getDoctrine()->getManager();
  3566.         $eventContact $em
  3567.             ->getRepository('OceanExpertBundle:EventContacts')
  3568.             ->findOneBy(
  3569.                 array(
  3570.                     'idEvent' => $idEvent,
  3571.                     'idInd' => $idInd
  3572.                 )
  3573.             );
  3574.         //get the old contactfor value
  3575.         $oldContactFor $eventContact->getContactFor();
  3576.         $mailContent "'contact for' changed from '$oldContactFor' to '$contactfor'";
  3577.         $eventContact->setContactFor($contactfor);
  3578.         $em->persist($eventContact);
  3579.         $em->flush();
  3580.         $this->updateEvent($idEvent);
  3581.         //send an email to the user to warn that something has changed
  3582.         $eventInfo $this->getDoctrine()->getManager()
  3583.             ->getRepository('OceanExpertBundle:Events')
  3584.             ->findOneBy(
  3585.                 array(
  3586.                     'idEvent' => $idEvent
  3587.                 )
  3588.             );
  3589.         if ($eventInfo->getEmailPeople()) {
  3590.             //get the name and email of the participant
  3591.             $participant $this->getDoctrine()->getManager()
  3592.                 ->getRepository('OceanExpertBundle:Indiv')
  3593.                 ->findOneBy(
  3594.                     array(
  3595.                         'idInd' => $idInd
  3596.                     )
  3597.                 );
  3598.             //strange construction to keep this compatible with the other send mail code
  3599.             //this will make it easier to refactor this later
  3600.             $data['name'] = $participant->getTitle() . ' ' $participant->getFName() . ' ' $participant->getSName();
  3601.             $participantEmail1 $participant->getEmail1();
  3602.             $participantEmail2 $participant->getEmail2();
  3603.             if ($participantEmail2 != '') {
  3604.                 $email $participantEmail2;
  3605.             } elseif ($participantEmail1 != '') {
  3606.                 $email $participantEmail1;
  3607.             }
  3608.             //who is sending this mail
  3609.             $sendUser $this->getDoctrine()->getManager()
  3610.                 ->getRepository('OceanExpertBundle:Indiv')
  3611.                 ->findOneBy(
  3612.                     array(
  3613.                         'idInd' => $eventInfo->getIdContact()
  3614.                     )
  3615.                 );
  3616.             if ($sendUser) {
  3617.                 $firstName $sendUser->getFName();
  3618.                 $lastName $sendUser->getSName();
  3619.                 if ($firstName != '' && $lastName != '') {
  3620.                     $fromEmail = array(
  3621.                         'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' $firstName ' ' $lastName
  3622.                     );
  3623.                 } else {
  3624.                     $fromEmail = array(
  3625.                         'info@oceanexpert.org' => 'OceanExpert Team'
  3626.                     );
  3627.                 }
  3628.             } else {
  3629.                 $fromEmail =array(
  3630.                     'info@oceanexpert.org' => 'OceanExpert Team'
  3631.                 );
  3632.             }
  3633.             $event['title'] = $eventInfo->getTitle();
  3634.             $event['eventAddress'] = $eventInfo->getAddress();
  3635.             $event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' $eventInfo->getEndOn()->format('d-m-Y');
  3636.             $event['eventUrl'] = $this->generateUrl(
  3637.                 'view_event',
  3638.                 array(
  3639.                     'event' => $idEvent
  3640.                 ),
  3641.                 UrlGeneratorInterface::ABSOLUTE_URL
  3642.             );
  3643.             $message = new Swift_Message(
  3644.                 'Participation in an event',
  3645.                 $this->renderView(
  3646.                     'Email/eventEditParticipant.html.twig',
  3647.                     array(
  3648.                         'data' => $data,
  3649.                         'event' => $event,
  3650.                         'mailContent' => $mailContent
  3651.                     )
  3652.                 ),
  3653.                 'text/html'
  3654.             );
  3655.             $message->setFrom(
  3656.                 $fromEmail
  3657.             );
  3658.             $message->setTo(
  3659.                 array(
  3660.                     $email => $data['name']
  3661.                 )
  3662.             );
  3663.             $this->get('mailer')->send($message);
  3664.             $comment 'sent mail to ' $email;
  3665.         } elseif (!$eventInfo->getEmailPeople()) {
  3666.             $comment 'no mail sent as this option is not set';
  3667.         }
  3668.         return new JsonResponse(
  3669.             array(
  3670.                 'status' => 1,
  3671.                 'comment' => $comment,
  3672.                 'mailContent' => $mailContent
  3673.             )
  3674.         );
  3675.     }
  3676.     /**
  3677.      * @return JsonResponse
  3678.      */
  3679.     public function eventClearContactAction(Request $request)
  3680.     {
  3681.         $idEvent $request->request->get('idEvent');
  3682.         $em $this->getDoctrine()->getManager();
  3683.         $event $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
  3684.         $event->setIdContact('');
  3685.         $em->persist($event);
  3686.         $em->flush();
  3687.         $this->updateEvent($idEvent);
  3688.         return new JsonResponse(array('status' => 1));
  3689.     }
  3690.     /**
  3691.      * @param Request $request
  3692.      *
  3693.      * @return JsonResponse
  3694.      */
  3695.     public function addEventDocumentAction(Request $request)
  3696.     {
  3697.         $documentType $request->request->get('doctype');
  3698.         $idEvent $request->request->get('idEvent');
  3699.         $idDoc $request->request->get('idDoc');
  3700.         if (null != $request->request->get('idAgenda')) {
  3701.             $idAgenda $request->request->get('idAgenda');
  3702.         }
  3703.         $em $this->getDoctrine()->getManager();
  3704.         $idAgendaItem '';
  3705.         //see doctypes in the database
  3706.         switch ($documentType) {
  3707.             case "1":
  3708.                 $report $em->getRepository('OceanExpertBundle:EventReports')
  3709.                     ->findOneBy(
  3710.                         array(
  3711.                             'idEvent' => $idEvent
  3712.                         )
  3713.                     );
  3714.                 if ($report) {
  3715.                     $em->remove($report);
  3716.                     $em->flush();
  3717.                 }
  3718.                 $report = new EventReports();
  3719.                 $report->setIdEvent($idEvent);
  3720.                 $report->setIdDoc($idDoc);
  3721.                 $em->persist($report);
  3722.                 $em->flush();
  3723.                 break;
  3724.             case "2":
  3725.                 $presentation $em->getRepository('OceanExpertBundle:EventPresentations')
  3726.                     ->findOneBy(
  3727.                         array(
  3728.                             'idEvent' => $idEvent,
  3729.                             'idDoc' => $idDoc
  3730.                         )
  3731.                     );
  3732.                 if ($presentation) {
  3733.                     $em->remove($presentation);
  3734.                     $em->flush();
  3735.                 }
  3736.                 $presentation = new EventPresentations();
  3737.                 $presentation->setIdDoc($idDoc);
  3738.                 $presentation->setIdEvent($idEvent);
  3739.                 $em->persist($presentation);
  3740.                 $em->flush();
  3741.                 break;
  3742.             case "3":
  3743.                 $backgroundDocs $em->getRepository('OceanExpertBundle:EventBackgrounddocs')
  3744.                     ->findOneBy(
  3745.                         array(
  3746.                             'idEvent' => $idEvent,
  3747.                             'idDoc' => $idDoc
  3748.                         )
  3749.                     );
  3750.                 if ($backgroundDocs) {
  3751.                     $em->remove($backgroundDocs);
  3752.                     $em->flush();
  3753.                 }
  3754.                 $backgroundDocs = new EventBackgrounddocs();
  3755.                 $backgroundDocs->setIdDoc($idDoc);
  3756.                 $backgroundDocs->setIdEvent($idEvent);
  3757.                 $em->persist($backgroundDocs);
  3758.                 $em->flush();
  3759.                 break;
  3760.             case "4":
  3761.                 $otherDocs $em->getRepository('OceanExpertBundle:EventOtherdocs')
  3762.                     ->findOneBy(
  3763.                         array(
  3764.                             'idEvent' => $idEvent,
  3765.                             'idDoc' => $idDoc
  3766.                         )
  3767.                     );
  3768.                 if ($otherDocs) {
  3769.                     $em->remove($otherDocs);
  3770.                     $em->flush();
  3771.                 }
  3772.                 $otherDocs = new EventOtherdocs();
  3773.                 $otherDocs->setIdDoc($idDoc);
  3774.                 $otherDocs->setIdEvent($idEvent);
  3775.                 $em->persist($otherDocs);
  3776.                 $em->flush();
  3777.                 break;
  3778.             case "5":
  3779.                 if ($idAgenda != '') {
  3780.                     $agendaDetails $em->getRepository('OceanExpertBundle:EventAgendaitems')
  3781.                         ->findOneBy(
  3782.                             array(
  3783.                                 'id' => $idAgenda
  3784.                             )
  3785.                         );
  3786.                     if ($agendaDetails) {
  3787.                         $idAgendaItem $agendaDetails->getIdAgendaitem();
  3788.                         $agendaDocs $em->getRepository('OceanExpertBundle:AgendaitemDocuments')
  3789.                             ->findOneBy(
  3790.                                 array(
  3791.                                     'idEvent' => $idEvent,
  3792.                                     'idDoc' => $idDoc,
  3793.                                     'idAgendaitem' => $agendaDetails->getIdAgendaitem()
  3794.                                 )
  3795.                             );
  3796.                         if ($agendaDocs) {
  3797.                             $em->remove($agendaDocs);
  3798.                             $em->flush();
  3799.                         }
  3800.                         $conn $this->getDoctrine()->getConnection();
  3801.                         $stmt $conn->prepare('INSERT INTO agendaitem_documents (id_event, id_agendaitem, id_doc) VALUES (?, ?, ?)');
  3802.                         $stmt->bindValue(1$idEvent);
  3803.                         $stmt->bindValue(2$idAgendaItem);
  3804.                         $stmt->bindValue(3$idDoc);
  3805.                         $stmt->execute();
  3806.                     }
  3807.                 }
  3808.                 break;
  3809.         }
  3810.         $data = array(
  3811.             'status' => 1,
  3812.             $request->request->all(),
  3813.             'idAgendaItem' => $idAgendaItem
  3814.         );
  3815.         return new JsonResponse($data);
  3816.     }
  3817.     /**
  3818.      * @return JsonResponse
  3819.      */
  3820.     public function saveAgendaOrderAction(Request $request): JsonResponse
  3821.     {
  3822.         $order $request->request->get('order');
  3823.         $agendaOrders json_decode($order);
  3824.         $i 0;
  3825.         foreach ($agendaOrders->groups as $agendaData) {
  3826.             $agenda $this->getDoctrine()
  3827.                 ->getRepository('OceanExpertBundle:EventAgendaitems')
  3828.                 ->findOneBy(
  3829.                     array(
  3830.                         'id' => $agendaData->agendaId
  3831.                     )
  3832.                 );
  3833.             $em $this->getDoctrine()->getManager();
  3834.             if ($agenda) {
  3835.                 $agenda->setParentIdevent($agendaData->parentId);
  3836.                 $agenda->setAgendaOrder($i);
  3837.                 $em->persist($agenda);
  3838.                 $em->flush();
  3839.                 $this->updateEvent($agenda->getIdEvent());
  3840.             }
  3841.             $i++;
  3842.         }
  3843.         return new JsonResponse($order);
  3844.     }
  3845.     /**
  3846.      * @return Response
  3847.      */
  3848.     function updatePresentationAgendaAction(Request $request)
  3849.     {
  3850.         $idDoc $request->request->get('idDoc');
  3851.         $idEvent $request->request->get('idEvent');
  3852.         $agendaItem $request->request->get('agendaItem');
  3853.         $em $this->getDoctrine()->getManager();
  3854.         $eventPresentation $em->getRepository('OceanExpertBundle:EventPresentations')
  3855.             ->findOneBy(
  3856.                 array(
  3857.                     'idEvent' => $idEvent,
  3858.                     'idDoc' => $idDoc
  3859.                 )
  3860.             );
  3861.         if ($eventPresentation) {
  3862.             $eventPresentation->setIdAgendaitem($agendaItem);
  3863.             $em->persist($eventPresentation);
  3864.             $em->flush();
  3865.             $this->updateEvent($idEvent);
  3866.         }
  3867.         return new JsonResponse(array('status' => 1));
  3868.     }
  3869.     /**
  3870.      * send an invitation to the participants that have been added to this event
  3871.      *
  3872.      * @return Response
  3873.      */
  3874.     public function sendInvitesEventParticipantsAction(Request $request)
  3875.     {
  3876.         //what is our environment?
  3877.         $env $this->container->get('kernel')->getEnvironment();
  3878.         $idEvent $request
  3879.             ->request
  3880.             ->get('idEvent');
  3881.         $em $this
  3882.             ->getDoctrine()
  3883.             ->getManager();
  3884.         $event $em
  3885.             ->getRepository('OceanExpertBundle:Events')
  3886.             ->findOneBy(
  3887.                 array(
  3888.                     'idEvent' => $idEvent
  3889.                 )
  3890.             );
  3891.         $sender $this->fosUserManager->findUserBy(
  3892.             array(
  3893.                 'id' => $event->getIdContact()
  3894.             )
  3895.         );
  3896.         $data = array(
  3897.             'userid' => $event->getIdContact(),
  3898.             'eventInvitation' => $event->getIdEvent(),
  3899.             'selfMail' => "false",
  3900.             'email' => $sender->getEmail()
  3901.         );
  3902.         $filename uniqid() . '.json';
  3903.         $filePath '/tmp/emailqueue';
  3904.         if ($env !== 'prod') {
  3905.             $filePath .= "_$env";
  3906.         }
  3907.         if (!file_exists($filePath '/')) {
  3908.             mkdir(
  3909.                 $filePath,
  3910.                 0777
  3911.             );
  3912.         }
  3913.         $fp fopen(
  3914.             $filePath '/' $filename,
  3915.             'w'
  3916.         );
  3917.         fwrite($fpjson_encode($data));
  3918.         fclose($fp);
  3919.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  3920.         $eventUrl $baseurl $this->generateUrl('view_event', array('event' => $idEvent));
  3921.         $message = new Messages();
  3922.         $message->setIdSender($event->getIdContact());
  3923.         $message->setSearchstring($eventUrl);
  3924.         $message->setSubject("Event Invitation Mail");
  3925.         $message->setMessage("Event Invitation email for all participants for event " $event->getTitle());
  3926.         $message->setIgnoreprefs(1);
  3927.         $message->setApproved(2);
  3928.         $message->setDateentered(new DateTime("now"));
  3929.         $message->setDatequeued(new DateTime("now"));
  3930.         $em->persist($message);
  3931.         $em->flush();
  3932.         $mailQueue = new MailQueueFiles();
  3933.         $mailQueue->setIdInd($event->getIdContact());
  3934.         $mailQueue->setFileName($filename);
  3935.         $mailQueue->setCreatedAt(new DateTime("now"));
  3936.         $mailQueue->setProcessedAt(null);
  3937.         $mailQueue->setProcessed(0);
  3938.         $mailQueue->setIdMessage($message->getIdMsg());
  3939.         $mailQueue->setApproved(1);
  3940.         $em->persist($mailQueue);
  3941.         $em->flush();
  3942.         return new JsonResponse(
  3943.             array(
  3944.                 'status' => 1
  3945.             )
  3946.         );
  3947.     }
  3948.     /**
  3949.      * store the confirmation of a participant to an event
  3950.      *
  3951.      * @param int     $idEvent id of the event
  3952.      * @param string  $hash    the confirmation check hash
  3953.      * @param Request $request the request object
  3954.      *
  3955.      * @return Response
  3956.      *
  3957.      * @throws \Exception
  3958.      */
  3959.     public function confirmEventParticipationAction(int $idEventstring $hashRequest $request): Response
  3960.     {
  3961.         $em $this->getDoctrine()->getManager();
  3962.         $participants $em->getRepository('OceanExpertBundle:EventParticipants')
  3963.             ->findOneBy(
  3964.                 array(
  3965.                     'idEvent' => $idEvent,
  3966.                     'hash' => $hash
  3967.                 )
  3968.             );
  3969.         $event $em->getRepository('OceanExpertBundle:Events')
  3970.             ->findOneBy(
  3971.                 array(
  3972.                     'idEvent' => $idEvent
  3973.                 )
  3974.             );
  3975.         $eventCountry $em->getRepository('OceanExpertBundle:Countries')
  3976.             ->findOneBy(
  3977.                 array(
  3978.                     'idCountry' => $event->getIdCountry()
  3979.                 )
  3980.             );
  3981.         if ($participants) {
  3982.             if ($participants->getStatus() == 1) {
  3983.                 $message = array(
  3984.                     'status' => 1,
  3985.                     'message' => '',
  3986.                 );
  3987.             } else {
  3988.                 $message = array(
  3989.                     'status' => 0,
  3990.                     'message' => "Your participation in this event has already been confirmed.",
  3991.                 );
  3992.             }
  3993.             $expert $this->getExpertById($participants->getIdInd());
  3994.         } else {
  3995.             $message = array(
  3996.                 'status' => 0,
  3997.                 'message' => "The link you are trying to use to confirm your participation is (no longer) valid.",
  3998.             );
  3999.             $expert '';
  4000.         }
  4001.         if (null != ($request->request->get('decision'))
  4002.             && $request->request->get('decision') != ''
  4003.             && null != $participants
  4004.         ) {
  4005.             $decision $request->request->get('decision');
  4006.             $reason '';
  4007.             if ($event->getIdContact() != '') {
  4008.                 $contact $this->getExpertById($event->getIdContact());
  4009.             } else {
  4010.                 $contact $this->getExpertById($event->getCreatedBy());
  4011.             }
  4012.             $fromName ucwords($contact['fname']) . ' ' ucwords($contact['sname']);
  4013.             $participantName ucwords($expert['fname']) . ' ' ucwords($expert['sname']);
  4014.             $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  4015.             $eventUrl $baseurl $this->generateUrl('view_event', array('event' => $idEvent));
  4016.             if (null != ($request->request->get('reason'))) {
  4017.                 $reason $request->request->get('reason');
  4018.             }
  4019.             if ($decision == 1) {
  4020.                 $participants->setStatus(0);
  4021.                 if (null != ($request->request->get('arriveOn'))) {
  4022.                     $arriveOn $request->request->get('arriveOn');
  4023.                     $participants->setArriveOn(
  4024.                         new DateTime(date(
  4025.                             'd-m-Y',
  4026.                             strtotime($arriveOn)
  4027.                         )
  4028.                         )
  4029.                     );
  4030.                 }
  4031.                 if (null != ($request->request->get('leaveOn'))) {
  4032.                     $leaveOn $request->request->get('leaveOn');
  4033.                     $participants->setLeaveOn(
  4034.                         new DateTime(date(
  4035.                             'd-m-Y',
  4036.                             strtotime($leaveOn)
  4037.                         )
  4038.                         )
  4039.                     );
  4040.                 }
  4041.                 if (null != ($request->request->get('contact'))) {
  4042.                     $contactTel $request->request->get('contact');
  4043.                     $participants->setContactTel($contactTel);
  4044.                 }
  4045.                 $action 'Thank you, your acceptance has been noted and a confirmation has been sent to you by email.';
  4046.                 $subject 'Confirmation of Participation in "' $event->getTitle() . '"';
  4047.                 $msg '<p>Dear ' $expert['title'] . ' ' ucwords($expert['fname']) . ' ' ucwords($expert['sname']) . ',</p>';
  4048.                 $msg .= '<p>Thank you for confirming your participation in the event "' $event->getTitle() . '". </p>';
  4049.                 $msg .= '<p>All information on this event can be found at:</p>';
  4050.                 $msg .= '<p><a href="' $eventUrl '">' $eventUrl '</a></p>';
  4051.                 $msg .= 'Regards,<br/>';
  4052.                 $msg .= $fromName;
  4053.                 if (trim($expert['email2']) != '') {
  4054.                     $recipient $expert['email2'];
  4055.                 } else {
  4056.                     $recipient $expert['email1'];
  4057.                 }
  4058.                 if (trim($contact['email2']) != '') {
  4059.                     $sender $contact['email2'];
  4060.                 } else {
  4061.                     $sender $contact['email1'];
  4062.                 }
  4063.                 $this->sendEmail(
  4064.                     $recipient,
  4065.                     $sender,
  4066.                     $subject,
  4067.                     $msg,
  4068.                     $contact['idInd']
  4069.                 );
  4070.             } else {
  4071.                 $participants->setStatus(3);
  4072.                 $action "Thank you, your response has been noted. Thanks for replying to our invitation.";
  4073.                 $subject ucwords($participantName) . " has Declined an Event Invitation";
  4074.                 $msg "<p>Dear " ucwords($fromName) . ",</p>";
  4075.                 $msg .= "<p>This is an email to let you know that " ucwords($participantName) . ' ';
  4076.                 $msg .= "has declined an invitation to take part in '" $event->getTitle() . "'.</p>";
  4077.                 if ($reason) {
  4078.                     $msg .= "<p>They gave the following reason:</p>";
  4079.                     $msg .= "<p>'" $reason "'</p>";
  4080.                 }
  4081.                 $msg .= "<p>You can view the status of all of the participants for this event at</p>";
  4082.                 $msg .= "<p><a href='" $eventUrl "#participants'>$eventUrl#participants</a>" "</p>";
  4083.                 $msg .= "Regards,<br/>";
  4084.                 $msg .= "OceanExpert Team";
  4085.                 if (trim($contact['email2']) != '') {
  4086.                     $recipient $contact['email2'];
  4087.                 } else {
  4088.                     $recipient $contact['email1'];
  4089.                 }
  4090.                 $this->sendEmail(
  4091.                     $recipient,
  4092.                     "info@oceanexpert.org",
  4093.                     $subject,
  4094.                     $msg,
  4095.                     $contact['idInd']
  4096.                 );
  4097.             }
  4098.             $participants->setStatusChangedAt(new DateTime('now'));
  4099.             $em->persist($participants);
  4100.             $em->flush();
  4101.             $message = array(
  4102.                 'status' => 2,
  4103.                 'message' => $action,
  4104.             );
  4105.         }
  4106.         if (!isset($eventCountry)
  4107.             || !($eventCountry->getCountry())
  4108.         ) {
  4109.             $eventCountry 'not specified (yet)';
  4110.         } else {
  4111.             $eventCountry $eventCountry->getCountry();
  4112.         }
  4113.         $data = array(
  4114.             'event' => $event,
  4115.             'response' => $message,
  4116.             'expert' => $expert,
  4117.             'eventCountry' => $eventCountry,
  4118.         );
  4119.         return $this->render(
  4120.             'Event/eventConfirmation.html.twig',
  4121.             array(
  4122.                 'data' => $data
  4123.             )
  4124.         );
  4125.     }
  4126.     /**
  4127.      * @param $to
  4128.      * @param $from
  4129.      * @param $subject
  4130.      * @param $message
  4131.      * @param $idInd
  4132.      */
  4133.     private function sendEmail($to$from$subject$message$idInd)
  4134.     {
  4135.         $em $this->getDoctrine()->getManager();
  4136.         $headers "MIME-Version: 1.0\r\n";
  4137.         $headers .= "Content-type:text/html;charset=UTF-8\r\n";
  4138.         $now = new DateTime('now');
  4139.         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  4140.             $ip $_SERVER['HTTP_CLIENT_IP'];
  4141.         } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  4142.             $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
  4143.         } else {
  4144.             $ip $_SERVER['REMOTE_ADDR'];
  4145.         }
  4146.         $template $this->get('twig')
  4147.             ->render(
  4148.                 'Email/generalEventTemplate.html.twig',
  4149.                 array(
  4150.                     'message' => $message
  4151.                 )
  4152.             );
  4153.         $mail = new Mails();
  4154.         $mail->setCreateTime($now);
  4155.         $mail->setTimeToSend($now);
  4156.         $mail->setIdUser($idInd);
  4157.         $mail->setIp($ip);
  4158.         $mail->setSender($from);
  4159.         $mail->setRecipient($to);
  4160.         $mail->setHeaders($headers);
  4161.         $mail->setSubject($subject);
  4162.         $mail->setBody(
  4163.             trim(
  4164.                 preg_replace(
  4165.                     '/\s\s+/',
  4166.                     ' ',
  4167.                     $template
  4168.                 )
  4169.             )
  4170.         );
  4171.         $mail->setAttachments('');
  4172.         $mail->setTrySent(0);
  4173.         $mail->setDeleteAfterSend(1);
  4174.         $mail->setMandrilId(null);
  4175.         $em->persist($mail);
  4176.         $em->flush();
  4177.     }
  4178.     /**
  4179.      * @param $idEvent
  4180.      * @return Response
  4181.      */
  4182.     public function viewPrintableParticipantsAction($idEvent)
  4183.     {
  4184.         if ($idEvent == 0) {
  4185.             return new Response('No event id provided.');
  4186.         }
  4187.         $em $this->getDoctrine()->getManager();
  4188.         $event $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
  4189.         $data = array(
  4190.             'event' => $event,
  4191.             'participants' => $this->getPrintableParticipantsByRole($idEvent)
  4192.         );
  4193.         return $this->render('Event/printableParticipants.html.twig', array('data' => $data));
  4194.     }
  4195.     /**
  4196.      * get the participants by role for the given event
  4197.      *
  4198.      * @param int idEvent
  4199.      *
  4200.      * @return array | Response
  4201.      */
  4202.     private function getPrintableParticipantsByRole($idEvent)
  4203.     {
  4204.         $participants = array();
  4205.         $roles $this->getDoctrine()
  4206.             ->getRepository('OceanExpertBundle:EventParticipantroles')
  4207.             ->createQueryBuilder('e')
  4208.             ->select('e.role,e.idRole,e.pptOrdering')
  4209.             ->where('e.idEvent = :eventId')
  4210.             ->setParameter('eventId'$idEvent)
  4211.             ->orderBy('e.ordering''asc')
  4212.             ->getQuery()
  4213.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  4214.         $roles[] = array(
  4215.             "role" => "Other",
  4216.             "idRole" => '',
  4217.             "pptOrdering" => '',
  4218.         );
  4219.         $addressFormatRepository = new AddressFormatRepository();
  4220.         $countryRepository = new CountryRepository();
  4221.         $subdivisionRepository = new SubdivisionRepository();
  4222.         $formatter = new DefaultFormatter($addressFormatRepository$countryRepository$subdivisionRepository);
  4223.         $address = new Address();
  4224.         foreach ($roles as $role) {
  4225.             $repository $this->getDoctrine()->getManager()->createQueryBuilder();
  4226.             if ($this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
  4227.                 //let's check if the logged-in user has a 'real' profile
  4228.                 //the mandatory profile fields are all filled and the expert is active
  4229.                 $em $this->getDoctrine()->getManager();
  4230.                 $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  4231.                 if (!SecurityController::checkUserProfile($em$userId)) {
  4232.                     return $this->render(
  4233.                         'Exception/error.html.twig',
  4234.                         array(
  4235.                             'message' => 'seems your profile is not complete yet or has not been approved yet. Please complete your profile first.',
  4236.                         )
  4237.                     );
  4238.                 }
  4239.                 $repository->add(
  4240.                     'select',
  4241.                     'e.idRole, 
  4242.                     e.idInd, 
  4243.                     e.status, 
  4244.                     i.title, 
  4245.                     i.fname, 
  4246.                     i.sname, 
  4247.                     i.gender, 
  4248.                     i.useInstAddr, 
  4249.                     i.tel, 
  4250.                     i.fax, 
  4251.                     i.addr1, 
  4252.                     i.addr2, 
  4253.                     i.city, 
  4254.                     i.state, 
  4255.                     i.postcode, 
  4256.                     i.jobtitle, 
  4257.                     i.email1,
  4258.                     i.email2, 
  4259.                     c.countryCode, 
  4260.                     c.country, 
  4261.                     ins.instName, 
  4262.                     ins.instNameEng, 
  4263.                     i.dept, 
  4264.                     ins.instAddress insAddr1, 
  4265.                     ins.addr2 as instAddr2, 
  4266.                     ins.city as insCity, 
  4267.                     ins.state as insState, 
  4268.                     ins.postcode as insPostcode, 
  4269.                     ci.countryCode as insCountryCode, 
  4270.                     ci.country as insCountry, 
  4271.                     r.role,
  4272.                     r.ordering'
  4273.                 );
  4274.             } else {
  4275.                 $repository->add(
  4276.                     'select',
  4277.                     'e.idRole, 
  4278.                     e.idInd, 
  4279.                     e.status, 
  4280.                     i.title, 
  4281.                     i.fname, 
  4282.                     i.sname, 
  4283.                     i.useInstAddr, 
  4284.                     i.tel, 
  4285.                     i.fax, 
  4286.                     i.addr1, 
  4287.                     i.addr2, 
  4288.                     i.city, 
  4289.                     i.state, 
  4290.                     i.postcode, 
  4291.                     i.jobtitle, 
  4292.                     i.email1,
  4293.                     i.email2, 
  4294.                     c.countryCode, 
  4295.                     c.country, 
  4296.                     ins.instName, 
  4297.                     ins.instNameEng, 
  4298.                     i.dept, 
  4299.                     ins.instAddress as insAddr1, 
  4300.                     ins.addr2 as instAddr2, 
  4301.                     ins.city as insCity, 
  4302.                     ins.state as insState, 
  4303.                     ins.postcode as insPostcode, 
  4304.                     ci.countryCode as insCountryCode, 
  4305.                     ci.country as insCountry,
  4306.                     r.role,
  4307.                     r.ordering'
  4308.                 );
  4309.             }
  4310.             $repository->add(
  4311.                 'from',
  4312.                 'OceanExpertBundle:EventParticipants e'
  4313.             );
  4314.             $repository->leftJoin(
  4315.                 'OceanExpertBundle:Indiv',
  4316.                 'i',
  4317.                 'WITH',
  4318.                 'i.idInd = e.idInd'
  4319.             );
  4320.             $repository->leftJoin(
  4321.                 'OceanExpertBundle:IndivInstitution',
  4322.                 'ii',
  4323.                 'WITH',
  4324.                 'ii.idInd = i.idInd'
  4325.             );
  4326.             $repository->leftJoin(
  4327.                 'OceanExpertBundle:Countries',
  4328.                 'c',
  4329.                 'WITH',
  4330.                 'c.idCountry = i.countryCode'
  4331.             );
  4332.             $repository->leftJoin(
  4333.                 'OceanExpertBundle:Institutions',
  4334.                 'ins',
  4335.                 'WITH',
  4336.                 'ins.idInst = ii.idInst'
  4337.             );
  4338.             $repository->leftJoin(
  4339.                 'OceanExpertBundle:Countries',
  4340.                 'ci',
  4341.                 'WITH',
  4342.                 'ci.idCountry = ins.countryCode'
  4343.             );
  4344.             $repository->leftJoin(
  4345.                 'OceanExpertBundle:EventParticipantroles',
  4346.                 'r',
  4347.                 'WITH',
  4348.                 'e.idRole = r.idRole and e.idEvent = r.idEvent'
  4349.             );
  4350.             $repository->where('e.idEvent = :eventId');
  4351.             $repository->andWhere('e.status in (0,1)');
  4352.             if ($role['idRole'] != '') {
  4353.                 $repository->andwhere('e.idRole = :idRole');
  4354.                 $repository->setParameter('idRole'$role['idRole']);
  4355.             } else {
  4356.                 $repository->andwhere('e.idRole is NULL');
  4357.             }
  4358.             $repository->setParameter('eventId'$idEvent);
  4359.             $repository->addOrderBy('i.sname''asc');
  4360.             $participantsResult $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  4361.             foreach ($participantsResult as $key => $participant) {
  4362.                 if ($participant['useInstAddr'] == 1) {
  4363.                     $address $address
  4364.                         ->withCountryCode($participant['insCountryCode'])
  4365.                         ->withAdministrativeArea($participant['insState'])
  4366.                         ->withLocality($participant['insCity'])
  4367.                         ->withPostalCode($participant['insPostcode'])
  4368.                         ->withAddressLine1($participant['insAddr1'])
  4369.                         ->withAddressLine2($participant['instAddr2']);
  4370.                 } else {
  4371.                     $address $address
  4372.                         ->withCountryCode($participant['countryCode'])
  4373.                         ->withAdministrativeArea($participant['state'])
  4374.                         ->withLocality($participant['city'])
  4375.                         ->withPostalCode($participant['postcode'])
  4376.                         ->withAddressLine1($participant['addr1'])
  4377.                         ->withAddressLine2($participant['addr2']);
  4378.                 }
  4379.                 try {
  4380.                     $participantsResult[$key]['address'] = $formatter->format($address);
  4381.                 } catch (ErrorException $e) {
  4382.                     $participantsResult[$key]['address'] = 'incorrect address';
  4383.                 }
  4384.             }
  4385.             if (count($participantsResult) > 0) {
  4386.                 $participants[$role['role']] = $participantsResult;
  4387.             }
  4388.         }
  4389.         //remove as much as possible all stupid chars that people enter in their profiles....
  4390.         //or stuff we put there....
  4391.         //put all in one string
  4392.         $participants json_encode($participants);
  4393.         //these lines may look weird
  4394.         // but this is the only way to get rid of ALL strange things people put in their profiles
  4395.         $participants preg_replace('/&amp;/s''and '$participants);
  4396.         $participants preg_replace('/amp;/s'''$participants);
  4397.         $participants preg_replace('/&quot;/s''and '$participants);
  4398.         $participants preg_replace('/quot;/s'''$participants);
  4399.         $participants preg_replace('/&/s''and '$participants);
  4400.         $participants preg_replace('/\\\"/s'''$participants);
  4401.         $participants html_entity_decode($participants);
  4402.         $participants htmlspecialchars_decode($participants);
  4403.         $participants preg_replace('/<br\s?\/?>/s'' '$participants);
  4404.         $participants preg_replace('/<\/?p>/s'' '$participants);
  4405.         $participants strip_tags($participants);
  4406.         $participants preg_replace('/\\\\r\\\\n/s'' '$participants);
  4407.         $participants preg_replace('/\n/'''$participants);
  4408.         $participants preg_replace('/\\\\n/'''$participants);
  4409.         $participants preg_replace('/\s+/'' '$participants);
  4410.         //make it an associative array again
  4411.         return json_decode($participantstrue);
  4412.     }
  4413.     /**
  4414.      * @param $idEvent
  4415.      * @return Response
  4416.      */
  4417.     public function viewAgendaPrintableAction($idEvent)
  4418.     {
  4419.         $data $this->getPrintableAgendaData($idEvent);
  4420.         return $this->render(
  4421.             'Event/agendaPrintable.html.twig',
  4422.             array(
  4423.                 'data' => $data
  4424.             )
  4425.         );
  4426.     }
  4427.     /**
  4428.      * get the agenda items for this event
  4429.      * sort the data by agendaOrder in a natural order
  4430.      *
  4431.      * @param int $idEvent
  4432.      *
  4433.      * @return array|Response
  4434.      */
  4435.     private function getPrintableAgendaData(int $idEvent)
  4436.     {
  4437.         if ($idEvent == 0) {
  4438.             return new Response('No event id provided.');
  4439.         }
  4440.         $em $this->getDoctrine()->getManager();
  4441.         $event $em->getRepository('OceanExpertBundle:Events')
  4442.             ->findOneBy(
  4443.                 array(
  4444.                     'idEvent' => $idEvent
  4445.                 )
  4446.             );
  4447.         $country $em->getRepository('OceanExpertBundle:Countries')
  4448.             ->findOneBy(
  4449.                 array(
  4450.                     'idCountry' => $event->getIdCountry()
  4451.                 )
  4452.             );
  4453.         $tmpAgendaItems $this->getDoctrine()
  4454.             ->getRepository('OceanExpertBundle:EventAgendaitems')
  4455.             ->createQueryBuilder('e')
  4456.             ->select('e.idAgendaitem, e.id, e.title, e.parentIdevent, e.agendaOrder, e.notes, e.requiredActions')
  4457.             ->where('e.idEvent = :eventId')
  4458.             ->setParameter(':eventId'$event)
  4459.             ->addOrderBy('e.idAgendaitem + 0''ASC')
  4460.             ->addOrderBy('e.agendaOrder''ASC')
  4461.             ->getQuery()
  4462.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  4463.         foreach ($tmpAgendaItems as $key => $tmpAgendaItem) {
  4464.             $agendaItems[$tmpAgendaItem['idAgendaitem']] = $tmpAgendaItem;
  4465.         }
  4466.         ksort($agendaItemsSORT_NATURAL);
  4467.         $addressFormatRepository = new AddressFormatRepository();
  4468.         $countryRepository = new CountryRepository();
  4469.         $subdivisionRepository = new SubdivisionRepository();
  4470.         $formatter = new DefaultFormatter(
  4471.             $addressFormatRepository,
  4472.             $countryRepository,
  4473.             $subdivisionRepository
  4474.         );
  4475.         if (isset($country)) {
  4476.             $address = new Address();
  4477.             $address $address
  4478.                 ->withCountryCode($country->getCountryCode())
  4479.                 ->withAdministrativeArea($event->getState())
  4480.                 ->withLocality($event->getCity())
  4481.                 ->withPostalCode($event->getPostcode())
  4482.                 ->withAddressLine1($event->getAddress());
  4483.             $address $formatter->format($address);
  4484.         } else {
  4485.             $address 'no location specified or online event';
  4486.         }
  4487.         return array(
  4488.             'event' => $event,
  4489.             'address' => $address,
  4490.             'agenda' => $agendaItems
  4491.         );
  4492.     }
  4493.     /**
  4494.      * @param $idEvent
  4495.      * @return Response
  4496.      */
  4497.     public function viewAnnonatedAgendaPrintableAction($idEvent)
  4498.     {
  4499.         $data $this->getPrintableAgendaData($idEvent);
  4500.         return $this->render('Event/agendaAnnonated.html.twig', array('data' => $data));
  4501.     }
  4502.     /**
  4503.      * @return JsonResponse
  4504.      */
  4505.     public function updateEventStatusAction(Request $request)
  4506.     {
  4507.         $idEvent $request->request->get('idEvent');
  4508.         $eventStatus $request->request->get('eventStatus');
  4509.         $status 0;
  4510.         $message '';
  4511.         if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')) {
  4512.             $author $this->get('security.token_storage')->getToken()->getUser();
  4513.             $em $this->getDoctrine()->getManager();
  4514.             $event $em->getRepository('OceanExpertBundle:Events')
  4515.                 ->findOneBy(
  4516.                     array(
  4517.                         'idEvent' => $idEvent
  4518.                     )
  4519.                 );
  4520.             if (isset($eventStatus)
  4521.                 && $eventStatus != ''
  4522.             ) {
  4523.                 $event->setStatus($eventStatus);
  4524.                 $event->setLastEditBy($author->getId());
  4525.                 $event->setUpdatedAt(new DateTime("now"));
  4526.                 $em->persist($event);
  4527.                 $em->flush();
  4528.                 $status 1;
  4529.             }
  4530.         } else {
  4531.             $status 0;
  4532.             $message 'you have no rights to do this';
  4533.         }
  4534.         return new JsonResponse(
  4535.             array(
  4536.                 'status' => $status,
  4537.                 'eStatus' => $eventStatus,
  4538.                 'message' => $message
  4539.             )
  4540.         );
  4541.     }
  4542.     /**
  4543.      * @param $idEvent
  4544.      * @param $idFile
  4545.      * @param Request $request
  4546.      *
  4547.      * @return Response|RedirectResponse
  4548.      */
  4549.     public function importParticipantsAction($idEvent$idFileRequest $request)
  4550.     {
  4551.         $userId $this->get('security.token_storage')->getToken()->getUser()->getId();
  4552.         $eventDetails $this->getDoctrine()->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
  4553.         $eventParticipants = array();
  4554.         $idfile '';
  4555.         $importFile = array();
  4556.         $error '';
  4557.         $em $this->getDoctrine()->getManager();
  4558.         if ($idFile != 0) {
  4559.             $eventParticipants $this->getImportdata($idFile);
  4560.             $importFile $em->getRepository('OceanExpertBundle:EventParticipantImportFiles')->findOneBy(array('id' => $idFile'idEvent' => $idEvent));
  4561.             if (!$importFile) {
  4562.                 return $this->redirect($this->generateUrl('import_event_participants', array('idEvent' => $idEvent)));
  4563.             }
  4564.         }
  4565.         if ($request->isMethod('POST')) {
  4566.             $file $request->files->get('importfile');
  4567.             $filedata = array(
  4568.                 'id' => $idEvent,
  4569.                 'file' => $file,
  4570.                 'filename' => $file->getClientOriginalName(),
  4571.                 'type' => 'image',
  4572.                 'path' => "uploads/events/" $idEvent "/uploadParticipantsFiles/",
  4573.                 'user' => $userId,
  4574.                 'dbEntry' => 0
  4575.             );
  4576.             if ($file->getClientSize() > 33554432) {
  4577.                 $error "File size is too big (> 32MB)";
  4578.             }
  4579.             $mimetypes = array(
  4580.                 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  4581.                 'application/vnd.ms-excel'
  4582.             );
  4583.             if (!in_array($file->getClientMimetype(), $mimetypes)) {
  4584.                 $error "Not an excel file. Please save the file in microsoft Excel format and upload again.";
  4585.             }
  4586.             $file $filedata['path'] . $filedata['filename'];
  4587.             $types = array('Xlsx''Xls');
  4588.             if ($error == '') {
  4589.                 $this->uploadFile($filedata);
  4590.                 $importFile = new EventParticipantImportFiles();
  4591.                 $importFile->setIdEvent($idEvent);
  4592.                 $importFile->setFilename($filedata['filename']);
  4593.                 $importFile->setPath($filedata['path']);
  4594.                 $importFile->setUploadedBy($userId);
  4595.                 $importFile->setUploadedAt(new DateTime());
  4596.                 $em->persist($importFile);
  4597.                 $em->flush();
  4598.                 $idfile $importFile->getId();
  4599.                 foreach ($types as $type) {
  4600.                     try {
  4601.                         $reader IOFactory::createReader($type);
  4602.                     } catch (Exception $e) {
  4603.                         $error "File cannot be read.";
  4604.                     }
  4605.                     if ($reader->canRead($file)) {
  4606.                         break;
  4607.                     } else {
  4608.                         $error "Not an excel file. Please save the file in microsoft Excel format and upload again.";
  4609.                     }
  4610.                 }
  4611.                 if (file_exists($file)) {
  4612.                     $objPHPExcel IOFactory::load($file);
  4613.                     foreach ($objPHPExcel->getWorksheetIterator() as $sheet) {
  4614.                         $highestRow $sheet->getHighestRow();
  4615.                         $highestColumn $sheet->getHighestColumn();
  4616.                         if ($highestRow 1) {
  4617.                             if ($highestColumn == "W") {
  4618.                                 $headings $sheet->rangeToArray('A2:' $highestColumn 2,
  4619.                                     NULL,
  4620.                                     TRUE,
  4621.                                     FALSE)[0];
  4622.                                 for ($row 2$row <= $highestRow$row++) {
  4623.                                     $rowData $sheet->rangeToArray('A' $row ':' $highestColumn $row,
  4624.                                         NULL,
  4625.                                         TRUE,
  4626.                                         FALSE)[0];
  4627.                                     $eventParticipant = new EventParticipantUpload();
  4628.                                     $eventParticipant->setEmail($rowData[0]);
  4629.                                     $eventParticipant->setFname($this->makeTitle($rowData[1]));
  4630.                                     $eventParticipant->setSname(strtoupper($rowData[2]));
  4631.                                     $eventParticipant->setGender($this->makeTitle($rowData[3]));
  4632.                                     $eventParticipant->setNationality($this->makeTitle($rowData[4]));
  4633.                                     $eventParticipant->setPhone($rowData[5]);
  4634.                                     $eventParticipant->setAddressLine1($this->makeTitle($rowData[6]));
  4635.                                     $eventParticipant->setAddressLine2($this->makeTitle($rowData[7]));
  4636.                                     $eventParticipant->setCity($this->makeTitle($rowData[8]));
  4637.                                     $eventParticipant->setState($this->makeTitle($rowData[9]));
  4638.                                     $eventParticipant->setZipCode($rowData[10]);
  4639.                                     $eventParticipant->setCountry($this->makeTitle($rowData[11]));
  4640.                                     $eventParticipant->setInstitution($this->makeTitle($rowData[12]));
  4641.                                     $eventParticipant->setInstAddrLine1($this->makeTitle($rowData[13]));
  4642.                                     $eventParticipant->setInstAddrLine2($this->makeTitle($rowData[14]));
  4643.                                     $eventParticipant->setInstCity($this->makeTitle($rowData[15]));
  4644.                                     $eventParticipant->setInstState($this->makeTitle($rowData[16]));
  4645.                                     $eventParticipant->setInstZipCode($rowData[17]);
  4646.                                     $eventParticipant->setInstCountry($this->makeTitle($rowData[18]));
  4647.                                     $eventParticipant->setInstEmail($rowData[19]);
  4648.                                     $eventParticipant->setJobTitle(ucfirst($rowData[20]));
  4649.                                     $eventParticipant->setJobDescription(ucfirst($rowData[21]));
  4650.                                     $eventParticipant->setoceanexpertProfile($rowData[22]);
  4651.                                     $eventParticipant->setIdFile($idfile);
  4652.                                     $em->persist($eventParticipant);
  4653.                                     $em->flush();
  4654.                                 }
  4655.                             } else {
  4656.                                 $error "Invalid column count in the file. The number of columns should be 23.";
  4657.                                 unlink($file);
  4658.                                 if ($importFile) {
  4659.                                     $em->remove($importFile);
  4660.                                     $em->flush();
  4661.                                 }
  4662.                             }
  4663.                         } else {
  4664.                             $error "No import data present in the file.";
  4665.                             unlink($file);
  4666.                             if ($importFile) {
  4667.                                 $em->remove($importFile);
  4668.                                 $em->flush();
  4669.                             }
  4670.                         }
  4671.                     }
  4672.                 }
  4673.                 if ($error == '') {
  4674.                     return $this->redirect(
  4675.                         $this->generateUrl(
  4676.                             'import_event_participants',
  4677.                             array(
  4678.                                 'idEvent' => $idEvent,
  4679.                                 'idFile' => $idfile
  4680.                             )
  4681.                         )
  4682.                     );
  4683.                 } else {
  4684.                     return $this->render(
  4685.                         'Event/importEventParticipants.html.twig',
  4686.                         array(
  4687.                             'data' => array(
  4688.                                 'event' => $eventDetails,
  4689.                                 'participants' => $eventParticipants,
  4690.                                 'idFile' => $idfile,
  4691.                                 'importFile' => $importFile,
  4692.                                 'fileerror' => $error
  4693.                             )
  4694.                         )
  4695.                     );
  4696.                 }
  4697.             }
  4698.         }
  4699.         return $this->render(
  4700.             'Event/importEventParticipants.html.twig',
  4701.             array(
  4702.                 'data' => array(
  4703.                     'event' => $eventDetails,
  4704.                     'participants' => $eventParticipants,
  4705.                     'idFile' => $idfile,
  4706.                     'importFile' => $importFile,
  4707.                     'fileerror' => $error
  4708.                 )
  4709.             )
  4710.         );
  4711.     }
  4712.     /**
  4713.      * @param $idFile
  4714.      *
  4715.      * @return object[]
  4716.      */
  4717.     function getImportdata($idFile)
  4718.     {
  4719.         $em $this->getDoctrine()->getManager();
  4720.         $expertdata $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findBy(array('idFile' => $idFile));
  4721.         foreach ($expertdata as $expert) {
  4722.             $expertdetails $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('email1' => $expert->getEmail()));
  4723.             if ($expertdetails) {
  4724.                 $expert->setStatus(1);
  4725.                 $expert->setIdProfile($expertdetails->getIdInd());
  4726.                 $expert->setOceanexpertProfile($this->generateUrl('view_profile', array('user' => $expertdetails->getIdInd())));
  4727.                 $em->persist($expert);
  4728.                 $em->flush();
  4729.             } else {
  4730.                 if ($expert->getoceanexpertProfile() != '') {
  4731.                     if (strpos($expert->getoceanexpertProfile(), '/expert/') !== false) {
  4732.                         $urlparts explode('/'$expert->getoceanexpertProfile());
  4733.                         $expertpart end($urlparts);
  4734.                     } elseif (strpos($expert->getoceanexpertProfile(), 'viewMemberRecord') !== false) {
  4735.                         $urlparts explode('='$expert->getoceanexpertProfile());
  4736.                         $expertpart end($urlparts);
  4737.                     }
  4738.                     if (isset($expertpart)
  4739.                         && is_numeric($expertpart)
  4740.                     ) {
  4741.                         $user $this->fosUserManager->findUserBy(array('id' => $expertpart));
  4742.                         if ($user) {
  4743.                             $expertdetails $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $user->getId()));
  4744.                         } else {
  4745.                             $expert->setStatus(0);
  4746.                             $expert->setIdProfile('');
  4747.                         }
  4748.                     } else {
  4749.                         $expertdetails $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $expertpart));
  4750.                     }
  4751.                     if ($expertdetails) {
  4752.                         $expert->setStatus(1);
  4753.                         $expert->setIdProfile($expertdetails->getIdInd());
  4754.                         $expert->setOceanexpertProfile($this->generateUrl('view_profile', array('user' => $expertdetails->getIdInd())));
  4755.                     } else {
  4756.                         $expert->setStatus(0);
  4757.                         $expert->setIdProfile('');
  4758.                     }
  4759.                 } else {
  4760.                     $expert->setStatus(0);
  4761.                     $expert->setIdProfile('');
  4762.                 }
  4763.                 $em->persist($expert);
  4764.                 $em->flush();
  4765.             }
  4766.         }
  4767.         return $expertdata;
  4768.     }
  4769.     /**
  4770.      * @param $title
  4771.      * @return string
  4772.      */
  4773.     function makeTitle($title)
  4774.     {
  4775.         $str ucwords(strtolower($title));
  4776.         $exclude 'a,an,the,for,and,nor,but,or,yet,so,such,as,at,around,by,after,along,for,from,of,on,to,with,without';
  4777.         $excluded explode(","$exclude);
  4778.         foreach ($excluded as $noCap) {
  4779.             $str str_replace(ucwords($noCap), strtolower($noCap), $str);
  4780.         }
  4781.         return ucfirst($str);
  4782.     }
  4783.     /**
  4784.      * change some info about the participant
  4785.      * TBC this is only used when importing event participants
  4786.      *
  4787.      * @param $idEvent
  4788.      * @param $idUser
  4789.      * @param Request $request
  4790.      * @return Response
  4791.      */
  4792.     public function editParticipantAction($idEvent$idUserRequest $request)
  4793.     {
  4794.         $em $this->getDoctrine()->getManager();
  4795.         $countries $this->getDoctrine()
  4796.             ->getRepository('OceanExpertBundle:Countries')
  4797.             ->createQueryBuilder('c')
  4798.             ->select('c.idCountry, c.country,c.countryCode')
  4799.             ->orderBy('c.country''asc')
  4800.             ->getQuery()
  4801.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  4802.         foreach ($countries as $country) {
  4803.             $countryArr[$country['idCountry']] = $country['country'];
  4804.         }
  4805.         $userInstitute = array();
  4806.         $instituteSeaRegion $this->getDoctrine()->getRepository('OceanExpertBundle:Regions')->seaRegions();
  4807.         $user $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findOneBy(array('id' => $idUser));
  4808.         if ($user) {
  4809.             $user->setCountry(array_search($user->getCountry(), $countryArr));
  4810.             $user->setNationality(array_search($user->getNationality(), $countryArr));
  4811.             $user->setInstCountry(array_search($user->getInstCountry(), $countryArr));
  4812.             $connection $em->getConnection();
  4813.             $statement $connection->prepare("SELECT i.id_inst, i.inst_name, i.inst_address, i.city, i.state, i.postcode FROM institutions i
  4814.                 WHERE ( i.inst_name = :instName
  4815.                     AND i.country_code = :country
  4816.                     AND i.activated = 1
  4817.                     )
  4818.                 ");
  4819.             $statement->bindValue('instName'$user->getInstitution());
  4820.             $statement->bindValue('country'$user->getInstCountry());
  4821.             $statement->execute();
  4822.             $userInstitute $statement->fetchAll();
  4823.             if (count($userInstitute) == 0) {
  4824.                 $connection $em->getConnection();
  4825.                 $statement $connection->prepare("SELECT i.id_inst, i.inst_name, i.inst_address, i.city, i.state, i.postcode FROM institutions i
  4826.                 WHERE ( MATCH (i.inst_name) AGAINST (:instName)
  4827.                     AND i.country_code = :country
  4828.                     AND i.activated = 1
  4829.                     )
  4830.                 ");
  4831.                 $statement->bindValue('instName'$user->getInstitution());
  4832.                 $statement->bindValue('country'$user->getInstCountry());
  4833.                 $statement->execute();
  4834.                 $userInstitute $statement->fetchAll();
  4835.             }
  4836.         }
  4837.         return $this->render(
  4838.             'Event/editParticipants.html.twig',
  4839.             array(
  4840.                 'data' => array(
  4841.                     'user' => $user,
  4842.                     'idUser' => $idUser,
  4843.                     'idEvent' => $idEvent,
  4844.                     'userInstitute' => $userInstitute,
  4845.                     'countries' => $countries,
  4846.                     'availableSeaRegions' => $instituteSeaRegion
  4847.                 )
  4848.             )
  4849.         );
  4850.     }
  4851.     /**
  4852.      * @param $code
  4853.      * @return string
  4854.      */
  4855.     public function getCountryByCode($code)
  4856.     {
  4857.         $em $this->getDoctrine()->getManager();
  4858.         $product $em->getRepository('OceanExpertBundle:Countries')->find($code);
  4859.         return $product->getCountry();
  4860.     }
  4861.     /**
  4862.      * @param Request $request
  4863.      * @return Response
  4864.      */
  4865.     public function deleteImportParticipantAction(Request $request)
  4866.     {
  4867.         $idParticipant $request->request->get('idParticipant');
  4868.         $em $this->getDoctrine()->getManager();
  4869.         $participant $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findOneBy(array('id' => $idParticipant));
  4870.         if ($participant) {
  4871.             $em->remove($participant);
  4872.             $em->flush();
  4873.             return new Response(1);
  4874.         } else {
  4875.             return new Response(0);
  4876.         }
  4877.     }
  4878.     /**
  4879.      * @param Request $request
  4880.      * @return Response
  4881.      */
  4882.     public function checkParticipantsDetailAction(Request $request)
  4883.     {
  4884.         $idFile $request->request->get('idfile');
  4885.         $invalidProfile $this->checkParticipants($idFile);
  4886.         if (count($invalidProfile) > 0) {
  4887.             $data = array(
  4888.                 'status' => 0,
  4889.                 'participants' => $invalidProfile
  4890.             );
  4891.         } else {
  4892.             $data = array(
  4893.                 'status' => 1,
  4894.                 'participants' => array()
  4895.             );
  4896.         }
  4897.         return new JsonResponse($data);
  4898.     }
  4899.     /**
  4900.      * @param $idFile
  4901.      * @return mixed
  4902.      */
  4903.     function checkParticipants($idFile)
  4904.     {
  4905.         $em $this->getDoctrine()->getManager();
  4906.         $invalidProfile $em->getRepository('OceanExpertBundle:EventParticipantUpload')
  4907.             ->createQueryBuilder('ep')
  4908.             ->select('ep.idProfile, ep.fname, ep.sname, ep.email')
  4909.             ->where('ep.idProfile is NULL')
  4910.             ->orWhere('ep.idProfile = 0')
  4911.             ->andWhere('ep.idFile = :idfile')
  4912.             ->setParameter('idfile'$idFile)
  4913.             ->orderBy('ep.sname''ASC')
  4914.             ->getQuery()
  4915.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  4916.         return $invalidProfile;
  4917.     }
  4918.     /**
  4919.      * Function to check and add event participant
  4920.      * @param Request $request
  4921.      * @return Response
  4922.      */
  4923.     public function addEventParticipantsAction(Request $request)
  4924.     {
  4925.         $idFile $request->request->get('idfile');
  4926.         $idEvent $request->request->get('idevent');
  4927.         $em $this->getDoctrine()->getManager();
  4928.         $invalidProfile $this->checkParticipants($idFile);
  4929.         if (count($invalidProfile) == 0) {
  4930.             $participants $em->getRepository('OceanExpertBundle:EventParticipantUpload')
  4931.                 ->createQueryBuilder('ep')
  4932.                 ->select('ep.idProfile,ep.phone')
  4933.                 ->where('ep.idProfile is not NULL')
  4934.                 ->orWhere('ep.idProfile != 0')
  4935.                 ->andWhere('ep.idFile = :idfile')
  4936.                 ->setParameter('idfile'$idFile)
  4937.                 ->getQuery()
  4938.                 ->getResult(AbstractQuery::HYDRATE_ARRAY);
  4939.             foreach ($participants as $participant) {
  4940.                 $eventparticipant $em->getRepository('OceanExpertBundle:EventParticipants')
  4941.                     ->findOneBy(
  4942.                         array(
  4943.                             'idInd' => $participant['idProfile'],
  4944.                             'idEvent' => $idEvent
  4945.                         )
  4946.                     );
  4947.                 if (!$eventparticipant) {
  4948.                     $eventparticipant = new EventParticipants();
  4949.                     $eventparticipant->setStatus(1);
  4950.                     $eventparticipant->setIdEvent($idEvent);
  4951.                     $eventparticipant->setIdInd($participant['idProfile']);
  4952.                     $eventparticipant->setContactTel($participant['phone']);
  4953.                     $em->persist($eventparticipant);
  4954.                     $em->flush();
  4955.                 }
  4956.                 $removeParticipantData $em->getRepository("OceanExpertBundle:EventParticipantUpload")
  4957.                     ->findOneBy(
  4958.                         array(
  4959.                             'idProfile' => $eventparticipant->getIdInd()
  4960.                         )
  4961.                     );
  4962.                 $em->remove($removeParticipantData);
  4963.                 $em->flush();
  4964.                 $importfile $em->getRepository('OceanExpertBundle:EventParticipantImportFiles')
  4965.                     ->findOneBy(
  4966.                         array(
  4967.                             'id' => $idFile
  4968.                         )
  4969.                     );
  4970.                 if ($importfile) {
  4971.                     unlink($importfile->getPath() . $importfile->getFilename());
  4972.                     $em->remove($importfile);
  4973.                     $em->flush();
  4974.                 }
  4975.             }
  4976.         }
  4977.         return new Response(1);
  4978.     }
  4979.     /**
  4980.      * create ICS file to download
  4981.      * this file should contain all info about an event
  4982.      *
  4983.      * @param int $idEvent id of the event
  4984.      *
  4985.      * @return Response
  4986.      */
  4987.     public function getIcsAction($idEvent)
  4988.     {
  4989.         //https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20220112T000000Z%2F20220112T235959Z&details=thisAreTheDetails&location=&text=thisIsTheTitle
  4990.         $em $this->getDoctrine()->getManager();
  4991.         $event $em->getRepository('OceanExpertBundle:Events')
  4992.             ->findOneBy(
  4993.                 array(
  4994.                     'idEvent' => $idEvent
  4995.                 )
  4996.             );
  4997.         /*
  4998.         Convert times to iCalendar format.
  4999.         They require a block for 'Ymd' and then another block for the time, with format 'his'.
  5000.         Both of those blocks are separated by a "T".
  5001.         The Z is declared at the end for UTC time, but shouldn't be included in the date conversion.
  5002.         */
  5003.         //we cannot set a time in OE for events
  5004.         //$event->setStartOn($event->getStartOn()->format('Ymd\This') . 'Z');
  5005.         //$event->setEndOn($event->getEndOn()->format('Ymd\This') . 'Z');
  5006.         $event->setStartOn($event->getStartOn()->format('Ymd\T') . '000001Z');
  5007.         $event->setEndOn($event->getEndOn()->format('Ymd\This') . '235959Z');
  5008.         //get rid of any formatting we may have added
  5009.         $event->setTitle(strip_tags($event->getEventTitle()));
  5010.         $event->setShortTitle(strip_tags($event->getEventShortTitle()));
  5011.         $response $this->render(
  5012.             'Event/getIcs.html.twig',
  5013.             array(
  5014.                 'url' => $this->generateUrl(
  5015.                     'view_event',
  5016.                     array(
  5017.                         'event' => $event->getIdEvent()
  5018.                     ),
  5019.                     UrlGenerator::ABSOLUTE_URL
  5020.                 ),
  5021.                 'event' => $event
  5022.             )
  5023.         );
  5024.         $response->headers->set(
  5025.             'Content-Type',
  5026.             'text/calendar; charset=utf-8'
  5027.         );
  5028.         $response->headers->set(
  5029.             'Content-Disposition',
  5030.             'attachment; filename="OceanExpertEvent_' $idEvent '_' date('Ymd') . '.ics"'
  5031.         );
  5032.         return $response;
  5033.     }
  5034. }