<?php
/**
* Controller for the events
*
* @author Mithun
* @author Arno Lambert <a.lambert@unesco.org>
* @since 06/10/16
*/
namespace OceanExpertBundle\Controller;
use CommerceGuys\Addressing\Formatter\DefaultFormatter;
use CommerceGuys\Addressing\Model\Address;
use CommerceGuys\Addressing\Repository\AddressFormatRepository;
use CommerceGuys\Addressing\Repository\CountryRepository;
use CommerceGuys\Addressing\Repository\SubdivisionRepository;
use DateTime;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\NoResultException;
use ErrorException;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface;
use OceanExpertBundle\Entity\DocumentFiles;
use OceanExpertBundle\Entity\EventAgendaitems;
use OceanExpertBundle\Entity\EventBackgrounddocs;
use OceanExpertBundle\Entity\EventContacts;
use OceanExpertBundle\Entity\EventFiles;
use OceanExpertBundle\Entity\EventGroups;
use OceanExpertBundle\Entity\EventLabels;
use OceanExpertBundle\Entity\EventOtherdocs;
use OceanExpertBundle\Entity\EventParticipantImportFiles;
use OceanExpertBundle\Entity\EventParticipantroles;
use OceanExpertBundle\Entity\EventParticipants;
use OceanExpertBundle\Entity\EventParticipantUpload;
use OceanExpertBundle\Entity\EventPresentations;
use OceanExpertBundle\Entity\EventReports;
use OceanExpertBundle\Entity\Events;
use OceanExpertBundle\Entity\EventStaff;
use OceanExpertBundle\Entity\MailQueueFiles;
use OceanExpertBundle\Entity\Mails;
use OceanExpertBundle\Entity\Messages;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Exception;
use Swift_Message;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Class EventController
* @package OceanExpertBundle\Controller
*/
class EventController extends AbstractController
{
/**
* list of possibe event labels
*
* @var array
*/
private $availableEventLabels = array(
1 => array(
'id' => 1,
'type' => 'Official meeting'
),
2 => array(
'id' => 2,
'type' => 'Training course'
),
3 => array(
'id' => 3,
'type' => 'Expert assistance'
),
4 => array(
'id' => 4,
'type' => 'Priority 1'
),
5 => array(
'id' => 5,
'type' => 'Priority 2'
),
6 => array(
'id' => 6,
'type' => 'Priority 3'
),
);
/**
* list of possible participant status
*
* @var array
*/
private $participantStatus = array(
'0' => 'Confirmed & Approved',
'1' => 'Need Confirmation',
'2' => 'Need Approval',
'3' => 'Declined',
'4' => 'Rejected',
);
private UserManagerInterface $fosUserManager;
public function __construct(UserManagerInterface $fosUserManager)
{
$this->fosUserManager = $fosUserManager;
}
/**
* @return Response
*/
public function indexAction()
{
return new Response('Index Page');
}
/**
* create a new event OR edit an existing one
*
* @param Request $request
* @param int $idEvent id of the event to create
*
* @return Response
*
* @throws \Exception
*/
public function createEventAction(Request $request, $idEvent)
{
/*
* @remark: the security check is not really needed here (but better safe than sorry)
* because we already have the line ' - { path: ^/admin, role: ROLE_USER }' in security.yaml
* and this prevents us from going to /admin/event without loging in
*/
$security_context = $this->get('security.authorization_checker');
if ($security_context->isGranted('IS_AUTHENTICATED_FULLY')) {
//let's check if the logged-in user has a 'real' profile
//the mandatory profile fields are all filled and the expert is active
$em = $this->getDoctrine()->getManager();
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
if (!SecurityController::checkUserProfile($em, $userId)) {
return $this->redirect(
$this->generateUrl(
'user_profile_edit'
)
);
}
$participantRoles = array();
$participants = array();
$eventStaff = array();
$eventContacts = array();
$unknownParticipants = array();
$eventLabels = array();
$eventPresentations = array();
$eventBackgrounddocs = array();
$eventOtherdocs = array();
$agendaItems = '';
$agendaItemsdocs = array();
$eventImage = array();
$report = array();
$idContact = array();
/*
* while the function is called createEvent, we just edit an event if a idEvent is given
* OE logic :-(
*/
if ($idEvent != 0) {
$event = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($event) {
$isOrganiser = $em->getRepository('OceanExpertBundle:EventContacts')
->createQueryBuilder('ec')
->select('count(ec.idInd)')
->where('ec.idInd =:idInd')
->andWhere('ec.idEvent =:event')
->setParameters(
array(
'idInd' => $userId,
'event' => $idEvent
)
)
->getQuery()->getSingleScalarResult();
$isCreator = $em->getRepository('OceanExpertBundle:Events')
->createQueryBuilder('e')
->select('count(e.idEvent)')
->where('e.createdBy =:idInd')
->orWhere('e.lastEditBy =:idInd')
->orWhere('e.idContact =:idInd')
->andWhere('e.idEvent =:event')
->setParameters(array('idInd' => $userId, 'event' => $idEvent))
->getQuery()->getSingleScalarResult();
if ($isOrganiser == 1
|| $isCreator == 1
|| $this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')
) {
//@todo what happens here? Arno 21/06/21
} else {
return $this->redirect(
$this->generateUrl(
'view_event',
array(
'event' => $idEvent
)
)
);
}
if (null != $event->getIdContact()) {
$idContact = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->select("i.fname,i.sname, i.idInd")
->where('i.idInd = :idInd')
->setParameter('idInd', $event->getIdContact())
->getQuery()
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
$idContact = array(
'idInd' => $idContact['idInd'],
'user' => $idContact['fname'] . ' ' . $idContact['sname'],
);
}
$eventImage = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventFiles')
->findOneBy(
array(
'idEvent' => $event->getIdEvent()
)
);
$participantRoles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->findBy(
array('idEvent' => $idEvent),
array('ordering' => 'asc')
);
$participants = $this->getEventParticipants($idEvent);
$eventStaff = $this->getEventStaff($idEvent);
$eventContacts = $this->getEventOrganisers($idEvent);
$unknownParticipants = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventUnknownparticipants')
->findBy(
array('idEvent' => $idEvent)
);
$eventLabels = $em
->getRepository('OceanExpertBundle:EventLabels')
->findBy(
array('idEvent' => $idEvent)
);
$eventPresentations = $this->getEventPresentations($idEvent);
$eventBackgrounddocs = $this->getBackgrounddocs($idEvent);
$eventOtherdocs = $this->getEventOtherDocs($idEvent);
$agendaItems = $this->getAgendaItems($event);
$agendaItemsdocs = $this->getDocuments(
'OceanExpertBundle:AgendaitemDocuments',
$idEvent
);
$report = $this->getEventReport($idEvent);
} else {
return $this->render(
'Exception/error.html.twig',
array(
'message' => "cannot find the event with id '$idEvent'"
)
);
}
} else {
$event = new Events();
$event->setStatus(0);
$event->setCreatedBy($userId);
$event->setCreatedAt(new DateTime());
$event->agenda = '';
}
if ($request->getMethod() === 'POST') {
$formData = $request->request->all();
$files = $request->files;
return $this->storeTheEvent(
$event,
$formData,
$files,
$userId
);
}
/*
$participantStatus = array(
'0' => 'Confirmed & Approved',
'1' => 'Need Confirmation',
'2' => 'Need Approval',
'3' => 'Declined',
'4' => 'Rejected',
);
*/
$calenderGroups = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventGroups')
->createQueryBuilder('e')
->select('e.idGroup')
->where('e.idEvent = :idEvent')
->setParameter('idEvent', $idEvent)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$calenderGroups = array_column($calenderGroups, 'idGroup');
$availableEventType = $em
->getRepository('OceanExpertBundle:Eventtypes')
->findBy(
array(),
array(
'eventtypeName' => 'ASC'
)
);
$countries = $this->getDoctrine()
->getRepository('OceanExpertBundle:Countries')
->findBy(
array(),
['country' => 'ASC']
);
$instituteSeaRegion = $this->getDoctrine()
->getRepository('OceanExpertBundle:Regions')
->seaRegions();
$availableCalenderGroups = $this->getSitesGroup();
$documentList = $this->getDocumentList();
$data = array(
'data' => array(
'event' => $event,
'countries' => $countries,
'availableCalenderGroups' => $availableCalenderGroups,
'availableEventType' => $availableEventType,
'availableEventLabels' => $this->availableEventLabels,
'availableSeaRegions' => $instituteSeaRegion,
'participantRoles' => $participantRoles,
'calenderGroups' => $calenderGroups,
'eventLabels' => $eventLabels,
'participants' => $participants,
'eventStaff' => $eventStaff,
'eventContacts' => $eventContacts,
'unknownParticipants' => $unknownParticipants,
'eventPresentations' => $eventPresentations,
'eventBackgrounddocs' => $eventBackgrounddocs,
'eventOtherdocs' => $eventOtherdocs,
'agendaItems' => $agendaItems,
'agendaItemsdocs' => $agendaItemsdocs,
'report' => $report,
'participantStatus' => $this->participantStatus,
'documentList' => $documentList,
'eventEmailContact' => $idContact,
'eventImage' => $eventImage,
)
);
return $this->render(
'Event/addEvent.html.twig',
$data
);
} else {
return $this->render(
'Exception/error.html.twig',
array(
'message' => 'seems you do not have permissions to do this, please log in before making an event'
)
);
}
}
/**
* copy the event with the given idEvent
* show the new event in edit mode
*
* @param Request $request
* @param int $idEvent id of the event to copy
*
* @return Response
*
* @throws \Exception
*/
public function copyEventAction(Request $request, int $idEvent): Response
{
/*
* @remark: the security check is not really needed here (but better safe than sorry)
* because we already have the line ' - { path: ^/admin, role: ROLE_USER }' in security.yaml
* and this prevents us from going to /admin/copyEvent without loging in
*/
$security_context = $this->get('security.authorization_checker');
if ($security_context->isGranted('IS_AUTHENTICATED_FULLY')) {
$em = $this->getDoctrine()->getManager();
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
$participantRoles = array();
$participants = array();
$eventStaffs = array();
$eventContacts = array();
$unknownParticipants = array();
$eventLabels = array();
$eventPresentations = array();
$eventBackgrounddocs = array();
$eventOtherdocs = array();
$agendaItems = '';
$agendaItemsdocs = array();
$eventImage = array();
$report = array();
$idContact = array();
/**
* copy the event with the given idEvent
*/
if ($idEvent != 0) {
//this is the event we will copy
$oldEvent = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($oldEvent) {
//make a new title
$eventTitle = $oldEvent->getTitle() . ' (COPY)';
//get all the other info of the event we copy
$eventImage = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventFiles')
->findOneBy(
array(
'idEvent' => $oldEvent->getIdEvent()
)
);
if (null != $oldEvent->getIdContact()) {
$oldIdContact = $oldEvent->getIdContact();
$idContact = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->select("i.fname,i.sname, i.idInd")
->where('i.idInd = :idInd')
->setParameter('idInd', $oldEvent->getIdContact())
->getQuery()
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
$idContact = array(
'idInd' => $idContact['idInd'],
'user' => $idContact['fname'] . ' ' . $idContact['sname'],
);
}
$participantRoles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->findBy(
array('idEvent' => $idEvent),
array('ordering' => 'asc')
);
$participants = $this->getEventParticipants($idEvent);
$eventStaffs = $this->getEventStaff($idEvent);
$eventContacts = $this->getEventOrganisers($idEvent);
//don't do this, is stupid
/*
$unknownParticipants = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventUnknownparticipants')
->findBy(
array('idEvent' => $idEvent)
);
*/
$eventLabels = $em
->getRepository('OceanExpertBundle:EventLabels')
->findBy(
array('idEvent' => $idEvent)
);
$eventGroups = $em
->getRepository('OceanExpertBundle:EventGroups')
->findBy(
array('idEvent' => $idEvent)
);
//useless to copy agenda's
/*
$agendaItems = $this->getAgendaItems($oldEvent);
$agendaItemsdocs = $this->getDocuments(
'OceanExpertBundle:AgendaitemDocuments',
$idEvent
);
*/
//useless to copy documents
/*
$eventPresentations = $this->getEventPresentations($idEvent);
$eventBackgrounddocs = $this->getBackgrounddocs($idEvent);
$eventOtherdocs = $this->getEventOtherDocs($idEvent);
*/
//we cannot have a final report as this is a new event....
//$report = $this->getEventReport($idEvent);
//check the start and end date
//cannot be in the past
$startOn = $oldEvent->getStartOn();
$endOn = $oldEvent->getEndOn();
$today = new DateTime();
if ($startOn < $today) {
$startOn = $today;
$endOn = $today;
}
//make the new event
$event = new Events();
$event->setIdEventtype($oldEvent->getIdEventtype());
$event->setTitle($eventTitle);
$event->setShorttitle($oldEvent->getShorttitle());
$event->setSummary($oldEvent->getSummary());
$event->setStartOn($startOn);
$event->setendOn($endOn);
$event->setAddress($oldEvent->getAddress());
$event->setCity($oldEvent->getCity());
$event->setState($oldEvent->getState());
$event->setPostcode($oldEvent->getPostcode());
$event->setIdCountry($oldEvent->getIdCountry());
$event->setIdInst($oldEvent->getIdInst());
$event->setUseInstAddr($oldEvent->getUseInstAddr());
$event->setNotes($oldEvent->getNotes());
$event->setWebsite($oldEvent->getWebsite());
$event->setRedirectWebsite($oldEvent->getRedirectWebsite());
$event->setKeywords($oldEvent->getKeywords());
$event->setCreatedBy($userId);
$event->setCreatedAt(new DateTime());
$event->setUpdatedAt(new DateTime());
$event->setLastEditBy($userId);
$event->setIsPublic($oldEvent->getIsPublic());
$event->setIsOpen($oldEvent->getIsOpen());
$event->setShowTravel($oldEvent->getShowTravel());
$event->setEmailPeople($oldEvent->getEmailPeople());
$event->setRegOnline($oldEvent->getRegOnline());
$event->setStatus(0);
if (isset($oldIdContact)) {
$event->setIdContact($oldIdContact);
}
$em->persist($event);
$em->flush();
$idEvent = $event->getIdEvent();
//participants and their roles should be copied also
foreach ($participantRoles as $participantRole) {
$newParticipantRole = new EventParticipantroles();
$newParticipantRole
->setIdEvent($idEvent)
->setOrdering($participantRole->getOrdering())
->setPptOrdering($participantRole->getPptOrdering())
->setRole($participantRole->getRole())
->setIdRole($participantRole->getIdRole());
$em->persist($newParticipantRole);
$em->flush();
}
//participants
foreach ($participants as $participant) {
$newRequest = new Request();
$newRequest->request->set('idInd', $participant['idInd']);
$newRequest->request->set('idEvent', $idEvent);
$newRequest->request->set('membertype', 3);
$this->addEventMemberAction($newRequest);
}
foreach ($eventStaffs as $eventStaff) {
$newRequest = new Request();
$newRequest->request->set('idInd', $eventStaff['id']);
$newRequest->request->set('idEvent', $idEvent);
$newRequest->request->set('membertype', 2);
$this->addEventMemberAction($newRequest);
}
foreach ($eventContacts as $eventContact) {
$newRequest = new Request();
$newRequest->request->set('idInd', $eventContact['id']);
$newRequest->request->set('idEvent', $idEvent);
$newRequest->request->set('membertype', 1);
$this->addEventMemberAction($newRequest);
}
//labels
foreach ($eventLabels as $eventLabel) {
$newEventLabel = new EventLabels();
$newEventLabel
->setIdEvent($idEvent)
->setIdGroup($eventLabel->getIdGroup())
->setIdLabel($eventLabel->getIdLabel());
$em->persist($newEventLabel);
$em->flush();
}
//groups
foreach ($eventGroups as $eventGroup) {
$newEventGroup = new EventGroups();
$newEventGroup
->setIdEvent($idEvent)
->setIdGroup($eventGroup->getIdGroup())
->setInCalendar($eventGroup->getInCalendar());
$em->persist($newEventGroup);
$em->flush();
}
} else {
return $this->render(
'Exception/error.html.twig',
array(
'message' => "cannot find the event with id '$idEvent'"
)
);
}
} else {
/*
* seems we have no 'real' idEvent,
* strange but no panick, let's just make an empty event
*/
$event = new Events();
$event->setStatus(0);
$event->setCreatedBy($userId);
$event->setCreatedAt(new DateTime());
$em->persist($event);
$em->flush();
$idEvent = $event->getIdEvent();
}
/*
* DO NOT DO THIS as this will persist and flush the event again
* remove this if this is still here in 2.4.0
* #641
if ($request->getMethod() === 'POST') {
$formData = $request->request->all();
$files = $request->files;
return $this->storeTheEvent(
$event,
$formData,
$files,
$userId
);
}
*/
/*
$participantStatus = array(
'0' => 'Confirmed & Approved',
'1' => 'Need Confirmation',
'2' => 'Need Approval',
'3' => 'Declined',
'4' => 'Rejected',
);
*/
$calenderGroups = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventGroups')
->createQueryBuilder('e')
->select('e.idGroup')
->where('e.idEvent = :idEvent')
->setParameter('idEvent', $idEvent)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$calenderGroups = array_column(
$calenderGroups,
'idGroup'
);
$availableEventType = $em
->getRepository('OceanExpertBundle:Eventtypes')
->findBy(
array(),
array(
'eventtypeName' => 'ASC'
)
);
$countries = $this->getDoctrine()
->getRepository('OceanExpertBundle:Countries')
->findBy(
array(),
['country' => 'ASC']
);
$instituteSeaRegion = $this->getDoctrine()
->getRepository('OceanExpertBundle:Regions')
->seaRegions();
$availableCalenderGroups = $this->getSitesGroup();
$documentList = $this->getDocumentList();
$data = array(
'data' => array(
'event' => $event,
'countries' => $countries,
'availableCalenderGroups' => $availableCalenderGroups,
'availableEventType' => $availableEventType,
'availableEventLabels' => $this->availableEventLabels,
'availableSeaRegions' => $instituteSeaRegion,
'participantRoles' => $participantRoles,
'calenderGroups' => $calenderGroups,
'eventLabels' => $eventLabels,
'participants' => $participants,
'eventStaff' => $eventStaffs,
'eventContacts' => $eventContacts,
'unknownParticipants' => $unknownParticipants,
'eventPresentations' => $eventPresentations,
'eventBackgrounddocs' => $eventBackgrounddocs,
'eventOtherdocs' => $eventOtherdocs,
'agendaItems' => $agendaItems,
'agendaItemsdocs' => $agendaItemsdocs,
'report' => $report,
'participantStatus' => $this->participantStatus,
'documentList' => $documentList,
'eventEmailContact' => $idContact,
'eventImage' => $eventImage,
)
);
return $this->redirect(
$this->generateUrl(
'edit_event',
array(
'idEvent' => $event->getIdEvent()
)
) . '#overview'
);
} else {
return $this->render(
'Exception/error.html.twig',
array(
'message' => 'seems you do not have permissions to do this, please log in before making an event'
)
);
}
}
/**
* store the form and go to the next step
*
* @param Events $event the event that has been created/edited/copied
* @param array $formData data from the form
* @param object $files submitted files
* @param int $userId id of the user doing this
*
* @return RedirectResponse
*
* @throws \Exception
*
*/
public function storeTheEvent(
Events $event,
array $formData,
object $files,
int $userId
): RedirectResponse
{
$em = $this->getDoctrine()->getManager();
$event->setLastEditBy($userId);
$event->setUpdatedAt(new DateTime());
if (isset($formData['form'])
&& $formData['form'] == 'peopleOption'
) {
$event->setRegOnline(isset($formData['registerOnline']) ? $formData['registerOnline'] : 0);
$event->setEmailPeople(isset($formData['emailPeople']) ? $formData['emailPeople'] : 0);
$em->persist($event);
$em->flush();
$idEvent = $event->getIdEvent();
if (array_key_exists('role', $formData)
&& count($formData['role']) == count($formData['roledisplay'])
) {
$count = count($formData['roledisplay']);
$eventRoles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->findBy(
array(
'idEvent' => $event->getIdEvent()
)
);
foreach ($eventRoles as $eventRole) {
$em->remove($eventRole);
$em->flush();
}
for ($i = 0; $i < $count; $i++) {
if ($formData['role'][$i] != '') {
$eventRoles = new EventParticipantroles();
$eventRoles->setIdEvent($event->getIdEvent());
$eventRoles->setRole($formData['role'][$i]);
$eventRoles->setIdRole($formData['idRole'][$i]);
$eventRoles->setPptOrdering($formData['roledisplay'][$i]);
$eventRoles->setOrdering($i);
$em->persist($eventRoles);
$em->flush();
}
}
}
//finish event
//redirect to confirmation page
//see #35
if (isset($formData['finish'])
&& $formData['finish']
) {
return $this->redirect(
$this->generateUrl(
'confirm_event_creation',
array(
'eventId' => $idEvent
)
)
);
}
return $this->redirect(
$this->generateUrl(
'edit_event',
array(
'idEvent' => $event->getIdEvent()
)
) . '#people'
);
} else {
$event->setIdEventtype($formData['eventType']);
$event->setTitle($formData['eventTitle']);
$event->setShorttitle(isset($formData['shortTitle']) ? $formData['shortTitle'] : '');
$event->setSummary(isset($formData['summary']) ? $formData['summary'] : '');
$event->setStartOn(new DateTime(str_replace('/', '-', $formData['startDate'])));
$event->setEndOn(new DateTime(str_replace('/', '-', $formData['endDate'])));
$event->setAddress(isset($formData['eventAddress']) ? $formData['eventAddress'] : '');
$event->setCity(isset($formData['eventCity']) ? $formData['eventCity'] : '');
$event->setState(isset($formData['eventState']) ? $formData['eventState'] : '');
$event->setPostcode(isset($formData['eventPostCode']) ? $formData['eventPostCode'] : '');
$event->setIdCountry(isset($formData['country']) ? $formData['country'] : null);
if (isset($formData['institute'])) {
$event->setIdInst($formData['institute']);
}
$event->setNotes(isset($formData['eventNotes']) ? $formData['eventNotes'] : '');
$event->setWebsite(isset($formData['eventWebsite']) ? $formData['eventWebsite'] : '');
$event->setKeywords(isset($formData['eventKeywords']) ? $formData['eventKeywords'] : '');
$event->setUseInstAddr(isset($formData['instAddr']) ? 1 : 0);
$event->setIdContact($userId);
$event->setIsPublic(1);
$event->setIsOpen(isset($formData['is_open']) ? $formData['is_open'] : 0);
$em->persist($event);
$em->flush();
$idEvent = $event->getIdEvent();
if (array_key_exists('eventType', $formData)
&& in_array($formData['eventType'], [3, 4])
) {
//for Workshop and training course we always have the roles of instructor and learner
//check if these have already been set, if not create them
foreach (['Instructor', 'Learner'] as $key => $role) {
$fixedRole = $em
->getRepository('OceanExpertBundle:EventParticipantroles')
->findOneBy(
array(
'role' => $role,
'idEvent' => $idEvent
)
);
if (!$fixedRole) {
//this role seems not to exist, make it
//find the new value for the role id
try {
$highestRoleIdReq = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->createQueryBuilder('e')
->select('e.idRole')
->where('e.idEvent = :idEvent')
->setParameter('idEvent', $idEvent)
->orderBy('e.idRole', 'DESC')
->setMaxResults(1)
->getQuery()
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
$highestRoleId = $highestRoleIdReq['idRole'];
$highestRoleId ++;
} catch (NoResultException $e) {
$highestRoleId = 0;
}
$fixedRole = new EventParticipantroles();
$fixedRole->setIdEvent($event->getIdEvent());
$fixedRole->setRole($role);
$fixedRole->setIdRole($highestRoleId);
$fixedRole->setPptOrdering(0);
$fixedRole->setOrdering($key + 1);
$em->persist($fixedRole);
$em->flush();
}
}
}
//save the choosen calender groups
//mind that we have to remove the old ones first
$eventGroups = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventGroups')
->findBy(
array(
'idEvent' => $idEvent
)
);
foreach ($eventGroups as $eventGroup) {
$em->remove($eventGroup);
}
$em->flush();
if (isset($formData['calenderGroups'])) {
foreach ($formData['calenderGroups'] as $idGroup) {
$eventGroup = $em
->getRepository('OceanExpertBundle:EventGroups')
->findOneBy(
array(
'idEvent' => $idEvent,
'idGroup' => $idGroup
)
);
if (!$eventGroup) {
$eventGroup = new EventGroups();
}
$eventGroup->setIdEvent($idEvent);
$eventGroup->setIdGroup($idGroup);
$eventGroup->setInCalendar(1);
$em->persist($eventGroup);
$em->flush();
}
}
$eventLabels = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventLabels')
->findBy(
array(
'idEvent' => $idEvent
)
);
foreach ($eventLabels as $eachlabel) {
$em->remove($eachlabel);
}
$em->flush();
if (isset($formData['labelGroup'])) {
$labels = array_combine($formData['labelGroup'], $formData['label']);
foreach ($labels as $group => $grouplabel) {
$eventLabel = new EventLabels();
$eventLabel->setIdEvent($idEvent);
$eventLabel->setIdGroup($group);
$eventLabel->setIdLabel($grouplabel);
$em->persist($eventLabel);
$em->flush();
}
}
if (null != $files->get('eventImage')) {
$file = $files->get('eventImage');
$filedata = array(
'id' => $idEvent,
'file' => $file,
'filename' => 'eventImage.png',
'type' => 'image',
'path' => "uploads/events/" . $idEvent . "/",
'user' => $userId,
'dbEntry' => 1,
);
$this->uploadFile($filedata);
} else {
if (isset($formData['eventlogo'])
&& $formData['eventlogo'] == ''
) {
$filename = 'uploads/events/' . $idEvent . '/eventImage.png';
if (file_exists($filename)) {
unlink($filename);
}
$eventFile = $this->getDoctrine()
->getManager()
->getRepository('OceanExpertBundle:EventFiles')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($eventFile) {
$em->remove($eventFile);
$em->flush();
}
}
}
//finish event
//redirect to confirmation page
//see #35
if (isset($formData['finish'])
&& $formData['finish']
) {
return $this->redirect(
$this->generateUrl(
'confirm_event_creation',
array(
'eventId' => $idEvent
)
)
);
}
return $this->redirect(
$this->generateUrl(
'edit_event',
array(
'idEvent' => $idEvent
)
) . '#peopleoptions'
);
}
}
/**
* show the confirmation page telling the event has been created
* OR updated
*
* @param Request $request
* @param $eventId
*
* @return Response
*/
public function confirmEventCreationAction(Request $request, $eventId)
{
//check if the event is active
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add(
'select',
' e.status'
);
$repository->add(
'from',
'OceanExpertBundle:Events e'
);
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $eventId);
$active = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
if ($active[0]['status'] == 0) {
$template = 'Event/confirmEventCreation.html.twig';
} elseif ($active[0]['status'] == 1) {
$template = 'Event/confirmEventUpdate.html.twig';
} else {
return $this->render(
'Exception/error.html.twig',
array(
'message' => 'This event seems to be deleted, so no use to update it.'
)
);
}
return $this->render(
$template,
array(
'eventId' => $eventId,
'active' => $active[0]
)
);
}
/**
* @param $event
* @return mixed
*/
public function getEventParticipants($event)
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add(
'select',
'e.idRole,
e.idInd,
i.idInd as id,
i.title,
i.fname,
i.sname,
i.tel,
r.role,
i.useInstAddr,
c.country,
r.role,
r.ordering,
e.status,
e.accommodation,
i.tel'
);
$repository->add(
'from',
'OceanExpertBundle:EventParticipants e'
);
$repository->leftJoin(
'OceanExpertBundle:Indiv',
'i',
'WITH',
'i.idInd = e.idInd'
);
$repository->leftJoin(
'OceanExpertBundle:Countries',
'c',
'WITH',
'c.idCountry = i.countryCode'
);
$repository->leftJoin(
'OceanExpertBundle:EventParticipantroles',
'r',
'WITH',
'e.idRole = r.idRole and e.idEvent = r.idEvent'
);
$repository->andWhere('e.idEvent = :eventId');
$repository->orderBy('r.ordering', 'asc');
$repository->addOrderBy('i.sname', 'asc');
$repository->setParameter('eventId', $event);
$participants = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($participants as $key => $participant) {
//correct the country if the expert has choosen to use the institute address
if ($participant['useInstAddr'] === 1) {
//get the correct country, being the country of the institute
$participants[$key]['country'] = 'tbd';
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add(
'select',
'c.country'
);
$repository->add(
'from',
'OceanExpertBundle:Countries c'
);
$repository->leftJoin(
'OceanExpertBundle:Institutions',
'i',
'WITH',
'c.idCountry = i.countryCode'
);
$repository->leftJoin(
'OceanExpertBundle:IndivInstitution',
'ii',
'WITH',
'ii.idInst = i.idInst'
);
$repository->where('ii.idInd = :idInd');
$repository->setParameter('idInd', $participant['idInd']);
$country = $repository->getQuery()->getResult();
if (isset($country[0])
&& isset($country[0]['country'])
&& $country[0]['country'] != ''
) {
$participants[$key]['country'] = $country[0]['country'];
}
}
}
return $participants;
}
/**
* @param $event
* @return mixed
*/
public function getEventStaff($event)
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'i.idInd as id, i.title, i.fname, i.sname, c.country');
$repository->add('from', 'OceanExpertBundle:EventStaff e');
$repository->leftJoin('OceanExpertBundle:Indiv', 'i', 'WITH', 'i.idInd = e.idInd');
$repository->leftJoin('OceanExpertBundle:Countries', 'c', 'WITH', 'c.idCountry = i.countryCode');
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $event);
return $repository->getQuery()->getResult();
}
/**
* @param $event
* @return mixed
*/
public function getEventOrganisers($event)
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'i.idInd as id, i.title, i.fname, i.sname, e.contactFor, c.country');
$repository->add('from', 'OceanExpertBundle:EventContacts e');
$repository->leftJoin('OceanExpertBundle:Indiv', 'i', 'WITH', 'i.idInd = e.idInd');
$repository->leftJoin('OceanExpertBundle:Countries', 'c', 'WITH', 'c.idCountry = i.countryCode');
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $event);
return $repository->getQuery()->getResult();
}
/**
* @param int $event id of the event
* @param string $order what column do we use to order the result
*
* @return array
*/
public function getEventPresentations($event, $order = '')
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository
->add(
'select',
'e.idAgendaitem, d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt'
)
->add(
'from',
'OceanExpertBundle:EventPresentations e'
)
->leftJoin(
'OceanExpertBundle:Documents',
'd',
'WITH',
'd.idDoc = e.idDoc'
)
->where(
'e.idEvent = :eventId'
)
->setParameter(
'eventId',
$event
);
if ($order == "date") {
$repository->orderBy('d.updatedAt');
} else {
$repository->orderBy('e.idAgendaitem');
}
return $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
}
/**
* @param int $event id of the event
* @param string $order what column will we use to order the results
*
* @return array
*/
public function getBackgrounddocs(int $event, string $order = ''): array
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'd.docCode, d.title, d.idDoc, d.authorText, d.updatedAt ,e.idAgendaitem');
$repository->add('from', 'OceanExpertBundle:EventBackgrounddocs e');
$repository->leftJoin('OceanExpertBundle:Documents', 'd', 'WITH', 'd.idDoc = e.idDoc');
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $event);
if ($order == "date") {
$repository->orderBy('d.updatedAt');
} else {
$repository->orderBy('e.idAgendaitem');
}
$backgrounddocs = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
return $backgrounddocs;
}
/**
* @param $event
* @param string $order
* @return mixed
*/
function getEventOtherDocs($event, $order = '')
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'd.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
$repository->add('from', 'OceanExpertBundle:EventOtherdocs o');
$repository->leftJoin('OceanExpertBundle:Documents', 'd', 'WITH', 'd.idDoc = o.idDoc');
$repository->where('o.idEvent = :eventId');
$repository->setParameter('eventId', $event);
if ($order == "date") {
$repository->orderBy('d.updatedAt');
} else {
$repository->orderBy('o.ordering');
}
$otherDocs = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
return $otherDocs;
}
/**
* @param $table
* @param $event
*
* @return array|DocumentFiles[]
*/
public function getDocuments($table, $event)
{
$idFiles = $this->getDoctrine()
->getRepository($table)
->createQueryBuilder('e')
->select('d.idDoc')
->leftJoin('OceanExpertBundle:DocumentFiles', 'd', 'WITH', 'd.idDoc = e.idDoc')
->where('e.idEvent = :eventId')
->setParameter('eventId', $event)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$idFiles = array_column($idFiles, 'idDoc');
$documents = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:DocumentFiles')
->findBy(
array(
'idDoc' => $idFiles
)
);
return $documents;
}
/**
* @param int $event id of the event
*
* @return mixed
*/
function getEventReport($event)
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'd.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
$repository->add('from', 'OceanExpertBundle:EventReports e');
$repository->leftJoin('OceanExpertBundle:Documents', 'd', 'WITH', 'd.idDoc = e.idDoc');
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $event);
$otherDocs = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
return $otherDocs;
}
/**
* @param $event
*
* @return string json
*/
public function getAgendaItems($event)
{
$em = $this->getDoctrine()->getManager();
$checkEvent = $em
->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'idEvent' => $event
)
);
if (!is_null($checkEvent)) {
$agendaItems = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventAgendaitems')
->createQueryBuilder('e')
->select('e.idAgendaitem, e.id, e.title, e.parentIdevent, e.agendaOrder, e.notes, e.requiredActions')
->where('e.idEvent = :eventId')
->setParameter(':eventId', $event)
->addOrderBy('e.agendaOrder', 'ASC')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($agendaItems as $key => $item) {
$agendaDocuments = $this->getDoctrine()
->getRepository('OceanExpertBundle:AgendaitemDocuments')
->createQueryBuilder('a')
->select('d.title as doctitle, d.idDoc, d.docCode')
->leftJoin('OceanExpertBundle:Documents', 'd', 'WITH', 'd.idDoc = a.idDoc')
->where('a.idEvent = :eventId')
->andwhere('a.idAgendaitem = :idAgendaitem')
->setParameter(':eventId', $event)
->setParameter(':idAgendaitem', $item['idAgendaitem'])
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$agendaItems[$key]['documents'] = $agendaDocuments;
}
// do not return a json response, we stay in this controller, so no headers needed
//return new JsonResponse(
return json_encode(
array(
'status' => 1,
EventController::buildTree(
$agendaItems,
0
)
)
);
}
// do not return a json response, we stay in this controller, so no headers needed
//return new JsonResponse(
return json_encode(
array(
'status' => 0,
'message' => 'no agenda items found'
)
);
}
/**
* @param $ar
* @param null $pid
* @return array
*/
public static function buildTree($ar, $pid = null)
{
$op = array();
$i = 1;
foreach ($ar as $item) {
if ($item['parentIdevent'] == $pid) {
$op[$i] = array(
'title' => $item['title'],
'notes' => $item['notes'],
'requiredActions' => $item['requiredActions'],
'parentIdevent' => $item['parentIdevent'],
'id' => $item['id'],
'agendaOrder' => $item['agendaOrder'],
'idAgendaitem' => $item['idAgendaitem'],
'documents' => $item['documents']
);
//using recursion
$children = EventController::buildTree($ar, $item['id']);
if ($children) {
$op[$i]['children'] = $children;
}
}
$i++;
}
return $op;
}
/**
* @param $data
*/
public function uploadFile($data)
{
$file = $data['file'];
$id = $data['id'];
if (null !== $file) {
$filetype = $file->guessClientExtension();
if (array_key_exists('filename', $data)) {
$filename = $data['filename'];
} else {
$filename = $file->getClientOriginalName();
}
if (array_key_exists('path', $data)) {
$directory = $data['path'];
} else {
$directory = "uploads/events/" . $id . "/";
}
$uploadfile = $file->move($directory, $filename);
if ($data['dbEntry'] == 1) {
$em = $this->getDoctrine()->getManager();
$eventFile = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventFiles')
->findOneBy(
array(
'idEvent' => $id,
'filename' => $filename,
'path' => $directory
)
);
if (!$eventFile) {
$eventFile = new EventFiles();
}
$eventFile->setIdEvent($id);
$eventFile->setType($data['type']);
$eventFile->setFilename($filename);
$eventFile->setPath($directory);
$eventFile->setCreatedBy($data['user']);
$eventFile->setCreatedAt(new DateTime());
$eventFile->setDeleted(0);
$em->persist($eventFile);
$em->flush();
}
}
}
/**
* @return mixed
*/
public function getSitesGroup()
{
$sitesGroup = $this->getDoctrine()
->getRepository('OceanExpertBundle:Groups')
->createQueryBuilder('g')
->select('g.idGroup, g.groupname, g.description')
->where('g.hasSite = 1')
->orderBy('g.groupname', 'ASC')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
return $sitesGroup;
}
/**
* @return array
*/
function getDocumentList()
{
$grouplist = array_map('current', $this->getUserGroups());
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'distinct(d.idGroup) as idGroup, g.groupname');
$repository->add('from', 'OceanExpertBundle:DoclistGroups d');
$repository->leftJoin('OceanExpertBundle:Groups', 'g', 'WITH', 'd.idGroup = g.idGroup');
$repository->where('g.idGroup in (:grouplist)');
$repository->setParameter('grouplist', $grouplist);
$repository->orderBy('g.groupname');
$docGroups = $repository->getQuery()->getResult();
$documentList = array();
foreach ($docGroups as $docGroup) {
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'd.idDoclist, d.title, dg.idGroup');
$repository->add('from', 'OceanExpertBundle:Doclists d');
$repository->leftJoin('OceanExpertBundle:DoclistGroups', 'dg', 'WITH', 'dg.idDoclist = d.idDoclist');
$repository->where('dg.idGroup =:idGroup');
$repository->setParameter('idGroup', $docGroup['idGroup']);
$repository->orderBy('d.title', 'asc');
$documentList[$docGroup['groupname']] = $repository->getQuery()->getResult();
}
return $documentList;
}
/**
* @return array
*/
function getUserGroups()
{
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
if ($userId) {
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'g.idGroup');
/*
* @todo cleanup
* Arno 17/02/2021
* #62
*
$repository->add('from', 'OceanExpertBundle:GroupMembers g');
*/
$repository->add('from', 'OceanExpertBundle:MemberGroups g');
$repository->where('g.idInd = :userId');
$repository->setParameter('userId', $userId);
return $repository->getQuery()->getResult();
} else {
return array();
}
}
/**
* show all past and upcoming events
*
* @param Request $request
*
* @return Response
*/
public function calendarAction(Request $request): Response
{
//is the current user an editor?
$globalEditor = $this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR');
//entity manager
$em = $this->getDoctrine()->getManager();
//get a list of all event types
$repository = $em->createQueryBuilder();
$repository->add(
'select',
'et.idEventtype,
et.eventtypeName'
);
$repository->add(
'from',
'OceanExpertBundle:Eventtypes et'
);
$repository->orderBy('et.idEventtype');
$eventTypes = $repository->getQuery()->getResult();
$availableEventTypes = array();
foreach ($eventTypes as $eventType) {
$availableEventTypes[$eventType['idEventtype']] = $eventType['eventtypeName'];
}
//get a list of all groups
$availableEventGroups = array_column(
$this->getSitesGroup(),
'groupname',
'idGroup'
);
//some name are way too long, so we shorten them
foreach ($availableEventGroups as $key => $group) {
if (strlen($group) > 18) {
$availableEventGroups[$key] = substr($group, 0, 18) . '...';
}
}
/*
* don't use the following lines to add 'All' to the types, groups and label lists
* as this will mess up the order of the groups or the id's
* idem for the labels of course
*
//$availableEventGroups[0] = 'All';
//array_unshift($availableEventGroups, 'All');
*/
$availableEventTypes = array(0 => 'All') + $availableEventTypes;
$availableEventGroups = array(0 => 'All') + $availableEventGroups;
$availableEventLabels = array(
0 => array(
'id' => 0,
'type' => 'All'
)
) + $this->availableEventLabels;
$repository = $em->createQueryBuilder();
$repository->add(
'select',
'month(e.startOn) as month,
year(e.startOn) as year,
e.idEvent,
e.title,
e.shorttitle,
e.idEventtype,
e.startOn,
e.endOn,
e.summary,
e.city,
c.country,
e.isOpen,
e.status'
);
$repository->add(
'from',
'OceanExpertBundle:Events e'
);
$repository->leftJoin(
'OceanExpertBundle:Countries',
'c',
'WITH',
'c.idCountry = e.idCountry'
);
$repository->leftJoin(
'OceanExpertBundle:EventGroups',
'eg',
'WITH',
'eg.idEvent = e.idEvent'
);
$repository->leftJoin(
'OceanExpertBundle:EventLabels',
'l',
'WITH',
'l.idEvent = e.idEvent AND l.idGroup = eg.idGroup'
);
//only show the approved / active ones for the non editor users
if ($globalEditor != 1) {
$repository->where('e.status = 1');
}
$repository->groupBy('e.idEvent');
$repository->orderBy('e.startOn');
//did the user select one or more types?
$activeEventTypes = '0';
if (trim($request->query->get('types')) != '') {
$activeEventTypes = json_decode(
trim(
$request->query->get('types')
)
);
}
//did the user select one or more calendars?
//this is not the calendar that is used with the labels!!!!!!!!!!
$activeEventGroups = '0';
if (trim($request->query->get('groups')) != ''
//&& trim($request->query->get('groups')) != 0
) {
$repository->leftJoin(
'OceanExpertBundle:EventGroups',
'eg2',
'WITH',
'eg2.idEvent = e.idEvent'
);
$activeEventGroups = json_decode(
trim(
$request->query->get(
'groups')
)
);
}
//did the user select one or more labels
//we don't care about the groups here
$activeEventLabels = '0';
if (trim($request->query->get('labels')) != ''
//&& trim($request->query->get('label')) != 0
){
$joinCondition = 'l2.idEvent = e.idEvent';
/*
if ($activeEventGroups != 0) {
$joinCondition .= ' AND l.idGroup = eg.idGroup';
}
*/
$repository->leftJoin(
'OceanExpertBundle:EventLabels',
'l2',
'WITH',
$joinCondition
);
$activeEventLabels = json_decode(
trim(
$request->query->get(
'labels')
)
);
}
/*
dump($request->query);
dump(trim($request->query->get('types')));
dump(trim($request->query->get('groups')));
dump(trim($request->query->get('labels')));
dump($activeEventTypes);
dump($activeEventGroups);
dump($activeEventLabels);
die;
*/
//did the user select a start and end date?
if ((null !== ($request->query->get('start'))
&& trim($request->query->get('start')) != '')
&& (null !== ($request->query->get('end'))
&& trim($request->query->get('end')) != '')
) {
//there is a start and end date in the url
$startdate = $request->query->get('start');
$enddate = $request->query->get('end');
$repository->andWhere('e.startOn BETWEEN :startdate AND :enddate');
$repository->orWhere('e.endOn BETWEEN :startdate AND :enddate');
$repository->setParameters(
array(
'startdate' => $startdate,
'enddate' => $enddate
)
);
} elseif (trim($request->query->get('year') != '')) {
$year = $request->query->get('year');
$startdate = date("$year-01-01");
$enddate = date("$year-12-31");
$repository->andWhere('YEAR(e.startOn) = :year');
$repository->orWhere('YEAR(e.endOn) = :year');
$repository->setParameter(
'year',
$year
);
} else {
//use the current year
$year = date('Y');
$startdate = date(
'Y-m-d'
);
$enddate = date(
'Y-m-t',
strtotime(
"+3 months",
strtotime(
date(
'Y-m-d'
)
)
)
);
$repository->andWhere('(e.startOn BETWEEN :startdate AND :enddate) OR (e.endOn BETWEEN :startdate AND :enddate)');
$repository->orWhere('(e.startOn < :enddate) AND (e.endOn > :startdate)');
//$repository->orWhere('e.endOn BETWEEN :startdate AND :enddate');
$repository->setParameters(
array(
'startdate' => $startdate,
'enddate' => $enddate
)
);
}
//seems like we cannot set this earlier (overwritten bij setParameter???)
//dump($activeEventTypes);
//dump($activeEventGroups);
//dump($activeEventTypes);
if (is_array($activeEventTypes) && !(count($activeEventTypes) == 1 && $activeEventTypes[0] == 0)) {
$repository->andWhere('e.idEventtype IN (:types)');
$repository->setParameter('types', $activeEventTypes);
}
//seems like we cannot set this earlier (overwritten bij setParameter???)
if (is_array($activeEventGroups) && !(count($activeEventGroups) == 1 && $activeEventGroups[0] == 0)) {
$repository->andWhere('eg.idGroup IN (:groups)');
$repository->setParameter('groups', $activeEventGroups);
}
//seems like we cannot set this earlier (overwritten bij setParameter???)
if (is_array($activeEventLabels) && !(count($activeEventLabels) == 1 && $activeEventLabels[0] == 0)) {
$repository->andWhere('l.idLabel IN (:labels)');
$repository->setParameter('labels', $activeEventLabels);
}
//if the current user is not a global editor, only show the events that are approved
if ($globalEditor != 1) {
$repository->andWhere('e.status = 1');
}
//get all the info for the events within the date range
//dump($repository->getQuery()->getDQL());
//dump($repository->getQuery()->getParameters());
//die;
$eventData = $repository->getQuery()->getResult();
//get a list of all years
$repository = $em->createQueryBuilder();
$repository->add(
'select',
'distinct(year(e.startOn))'
);
$repository->add(
'from',
'OceanExpertBundle:Events e'
);
$repository->where('e.startOn != 0');
/*
$repository->leftJoin(
'OceanExpertBundle:EventGroups',
'eg',
'WITH',
'eg.idEvent = e.idEvent'
);
*/
if ($globalEditor != 1) {
$repository->andWhere('e.status = 1');
}
/*
if (is_array($activeEventGroups)) {
$repository->andWhere('eg.idGroup IN (:groups)');
$repository->setParameter('groups', implode(',', $activeEventGroups));
}
*/
$repository->orderBy('e.startOn');
$years = $repository->getQuery()->getResult();
$years = array_reduce(
$years,
'array_merge',
array()
);
$eventCollection = array();
//get the number of participants, presentations and agenda/background/report/other docs
foreach ($eventData as $event) {
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(e.idInd) as participants');
$repository->add('from', 'OceanExpertBundle:EventParticipants e');
$repository->where('e.idEvent = :eventId');
$repository->andWhere('e.status != 3');
$repository->setParameter('eventId', $event['idEvent']);
$participant = $repository->getQuery()->getSingleScalarResult();
$event['participants'] = $participant;
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(ep.idDoc) as presentation');
$repository->add('from', 'OceanExpertBundle:EventPresentations ep');
$repository->where('ep.idEvent = :eventId');
$repository->setParameter('eventId', $event['idEvent']);
$presentation = $repository->getQuery()->getSingleScalarResult();
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(ad.idDoc) as agendadocs');
$repository->add('from', 'OceanExpertBundle:AgendaitemDocuments ad');
$repository->where('ad.idEvent = :eventId');
$repository->setParameter('eventId', $event['idEvent']);
$agendadocs = $repository->getQuery()->getSingleScalarResult();
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(eb.idDoc) as backgrounddocs');
$repository->add('from', 'OceanExpertBundle:EventBackgrounddocs eb');
$repository->where('eb.idEvent = :eventId');
$repository->setParameter('eventId', $event['idEvent']);
$backgroundDocs = $repository->getQuery()->getSingleScalarResult();
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(eO.idDoc) as otherdocs');
$repository->add('from', 'OceanExpertBundle:EventOtherdocs eO');
$repository->where('eO.idEvent = :eventId');
$repository->setParameter('eventId', $event['idEvent']);
$otherDocs = $repository->getQuery()->getSingleScalarResult();
$repository = $em->createQueryBuilder();
$repository->add('select', 'count(eO.idDoc) as reportdocs');
$repository->add('from', 'OceanExpertBundle:EventReports eO');
$repository->where('eO.idEvent = :eventId');
$repository->setParameter('eventId', $event['idEvent']);
$reportDocs = $repository->getQuery()->getSingleScalarResult();
$event['documents'] = $agendadocs + $presentation + $otherDocs + $backgroundDocs + $reportDocs;
$eventDate = date(
'F',
mktime(
0,
0,
0,
$event['month'],
10
)
);
$eventDate .= ' ' . $event['year'];
if (empty($eventCollection)) {
$eventCollection = array(
$eventDate => array($event)
);
} else {
if (array_key_exists($eventDate, $eventCollection)) {
$eventCollection[$eventDate][] = $event;
} else {
$eventCollection[$eventDate] = array($event);
}
}
}
//start 4 months before the start date
$earlierStart = date(
'Y-m-d',
strtotime("$startdate -4 month")
);
//end where we started before
$earlierEnd = $startdate;
//start where we left off
$laterStart = $enddate;
//end 5 months after the later start date
$laterEnd = date(
'Y-m-d',
strtotime("$laterStart +5 month")
);
//dump($activeEventLabels);
//die();
return $this->render('Event/calendar.html.twig', array(
'data' => array(
'events' => $eventCollection,
//'eventTypes' => $eventTypes,
'eventTypes' => array(
'list' => $availableEventTypes,
'active' => $activeEventTypes
),
'groups' => array(
'list' => $availableEventGroups,
'active' => $activeEventGroups
),
'eventLabels' => array(
'list' => $availableEventLabels,
'active' => $activeEventLabels
),
'date' => array(
'start' => $startdate,
'end' => $enddate
),
'year' => array(
'list' => $years,
'active' => date('Y', strtotime($startdate)),
),
'range' => array(
'earlier' => array(
'start' => $earlierStart,
'end' => $earlierEnd
),
'later' => array(
'start' => $laterStart,
'end' => $laterEnd
)
)
)
)
);
}
/**
*
*/
public function listUserEventsAction($idInd)
{
$data = $idInd;
return $this->render('Event/listUserEvents.html.twig', array('data' => $data));
}
/**
* create the PlanningWheel
* get the info of events that
* - are active
* - have a priority set in the labels
* - are within the next 11 months
*
* @return Response
*/
public function viewPlanningWheelAction(): Response
{
// startdate is today
// enddate is +11 months (to avoid confusion with the next year(s))
$startdate = date(
'Y-m-d'
);
$enddate = date(
'Y-m-t',
strtotime(
"+11 months",
strtotime(
date(
'Y-m-d'
)
)
)
);
//get all the events that are active and have a priority set
//this means they have a id labe set to 4 or 5 or 6
//see $this->availableEventLabels
//entity manager
$em = $this->getDoctrine()->getManager();
//get all the info for the events within the date range
//mind that concat only accepts single quotes in Doctrine :-(
$repository = $em->createQueryBuilder()
->add(
'select',
'e.title as name,
l.idLabel as priority,
e.startOn as date,
concat(\'/event/\', e.idEvent) as url'
)
->add(
'from',
'OceanExpertBundle:Events e'
)
->leftJoin(
'OceanExpertBundle:EventLabels',
'l',
'WITH',
'l.idEvent = e.idEvent'
)
->where(
'e.status = 1'
)
->andWhere(
'l.idLabel IN (4,5,6)'
)
->andWhere(
"((e.startOn BETWEEN '$startdate' AND '$enddate')
OR (e.endOn BETWEEN '$startdate' AND '$enddate'))"
)
->orderBy(
'e.startOn'
);
$events = $repository->getQuery()->getResult();
foreach ($events as $key => $event) {
//format the date as expected
$events[$key]['date'] = $event['date']->format('Y-m-d');
//correct the priority to match the wheel
$events[$key]['priority'] = $event['priority'] - 3;
}
return $this->render(
'Event/planningWheel.html.twig',
array(
'events' => json_encode($events)
)
);
}
/**
* show the info for an event, other views are used when making an event!!!
*
* @param int $event id of the event we want to see
*
* @return Response
*/
public function viewEventAction($event)
{
$user = array();
$user['canSendEmail'] = 0;
$user['canEditEvent'] = 0;
$isCreator = 0;
$isOrganiser = 0;
//container for errors
$error = '';
//get database Connection
$em = $this->getDoctrine()->getManager();
if (TRUE === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
$query = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->select('i.idInd,i.fname,i.sname,i.email1,i.email2')
->where('i.idInd = :idInd')
->setParameter('idInd', $this->get('security.token_storage')->getToken()->getUser())
->getQuery();
$user = $query->getOneOrNullResult();
$user['canSendEmail'] = 0;
$user['canEditEvent'] = 0;
if ($user) {
$isParticipant = $em->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idEvent' => $event,
'idInd' => $user['idInd']
)
);
$isCreator = $em->getRepository('OceanExpertBundle:Events')
->createQueryBuilder('e')
->select('count(e.idEvent)')
->where('e.createdBy =:idInd')
->orWhere('e.lastEditBy =:idInd')
->orWhere('e.idContact =:idInd')
->andWhere('e.idEvent =:event')
->setParameters(array('idInd' => $user['idInd'], 'event' => $event))
->getQuery()->getSingleScalarResult();
$isOrganiser = $em->getRepository('OceanExpertBundle:EventContacts')
->findOneBy(
array(
'idEvent' => $event,
'idInd' => $user['idInd']
)
);
if ($isParticipant
|| $isCreator == 1
|| $isOrganiser == 1
) {
$user['canSendEmail'] = 1;
}
}
}
if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')
|| $isCreator == 1
|| $isOrganiser == 1
) {
$eventDetails = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $event
)
);
$user['canSendEmail'] = 1;
$user['canEditEvent'] = 1;
} else {
$eventDetails = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $event,
'status' => 1
)
);
}
//get Event Type
if (isset($eventDetails)) {
$eventType = $em->getRepository('OceanExpertBundle:Eventtypes')
->findOneBy(
array(
'idEventtype' => $eventDetails->getIdEventtype()
)
);
//get Country Events
$eventImage = $em->getRepository('OceanExpertBundle:EventFiles')
->findOneBy(
array(
'idEvent' => $event
)
);
//get the address to show in the view
//this can be a custom address or the address of the institute
//if there is no country set
// and we don't want to use the institute address,
// we don't show the address
$eventCountryCode = 0;
$organization = '';
if (($eventDetails->getIdCountry() != 0
&& $eventDetails->getUseInstAddr() == 0)
|| ($eventDetails->getUseInstAddr() != 0
&& $eventDetails->getIdInst() != 0)
) {
if ($eventDetails->getUseInstAddr()) {
//get info about the institute
$institute = $this->getDoctrine()
->getRepository('OceanExpertBundle:Institutions')
->findOneBy(
array(
'idInst' => $eventDetails->getIdInst()
)
);
$eventAddressLine1 = $institute->getInstAddress();
$eventPostcode = $institute->getPostcode();
$eventCity = $institute->getCity();
$eventState = $institute->getState();
$eventCountryCode = $institute->getCountryCode();
$organization = $institute->getInstName();
} else {
$eventAddressLine1 = $eventDetails->getAddress();
$eventPostcode = $eventDetails->getPostcode();
$eventCity = $eventDetails->getCity();
$eventState = $eventDetails->getState();
$eventCountryCode = $eventDetails->getIdCountry();
}
$country = $em->getRepository('OceanExpertBundle:Countries')
->findOneBy(
array(
'idCountry' => $eventCountryCode
)
);
//format the address with the correct country
$addressFormatRepository = new AddressFormatRepository();
$countryRepository = new CountryRepository();
$subdivisionRepository = new SubdivisionRepository();
$formatter = new DefaultFormatter(
$addressFormatRepository,
$countryRepository,
$subdivisionRepository
);
if (isset($country)
&& $eventCountryCode != 0
) {
$address = new Address();
$address = $address
->withCountryCode($country->getCountryCode())
->withAdministrativeArea($eventState)
->withLocality($eventCity)
->withPostalCode($eventPostcode)
->withAddressLine1($eventAddressLine1);
if ($organization != '') {
$address = $address->withOrganization($organization);
}
$address = $formatter->format($address);
} else {
$address = 'no location defined or online event';
}
//Set event Address to use in view
$eventDetails->setAddress($address);
} elseif ($eventDetails->getUseInstAddr() != 0
&& $eventDetails->getIdInst() == 0) {
$error = 'This event uses the address of an institute but no institute has been selected.';
}
//------------------ Get Organisers ------------
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'i.idInd as id, i.title, i.fname, i.sname');
$repository->add('from', 'OceanExpertBundle:EventContacts e');
$repository->leftJoin('OceanExpertBundle:Indiv', 'i', 'WITH', 'i.idInd = e.idInd');
$repository->where('e.idEvent = :eventId');
$repository->andWhere('i.sname is not null');
$repository->setParameter('eventId', $event);
$repository->orderBy('i.sname', 'ASC');
$organisers = $repository->getQuery()->getResult();
//------------------ Get Staff ------------
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'i.idInd as id, i.title, i.fname, i.sname');
$repository->add('from', 'OceanExpertBundle:EventStaff e');
$repository->leftJoin('OceanExpertBundle:Indiv', 'i', 'WITH', 'i.idInd = e.idInd');
$repository->where('e.idEvent = :eventId');
$repository->setParameter('eventId', $event);
$repository->orderBy('i.sname', 'ASC');
$staff = $repository->getQuery()->getResult();
//------------------ Get Participant count ------------
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'count(e.idInd) as participants, e.status');
$repository->add('from', 'OceanExpertBundle:EventParticipants e');
$repository->where('e.idEvent = :eventId');
$repository->groupBy('e.status');
$repository->setParameter('eventId', $event);
$participantArr = $repository->getQuery()->getResult();
$participant = $provisional = $unapproved = $rejected = $declined = 0;
foreach ($participantArr as $participants) {
switch ($participants['status']) {
case 0:
//confirmed and approved
$participant = $participants['participants'];
break;
case 1:
//needs confirmation
$provisional = $participants['participants'];
break;
case 2:
//needs approval
$unapproved = $participants['participants'];
break;
case 3:
//declined
$declined = $participants['participants'];
break;
case 4:
//rejected
$rejected = $participants['participants'];
break;
}
}
$order = '';
$agenda = $this->getAgendaItems($event);
$agendaDocuments = $this->getAgendaDocuments($event, $order);
$eventPresentations = $this->getEventPresentations($event, $order);
$backgroundDocs = $this->getBackgrounddocs($event, $order);
$otherDocs = $this->getEventOtherDocs($event);
$report = $this->getEventReport($event);
$participantlist = $this->getEventParticipants($event);
$participantsByRole = $this->getParticipantsByRole($event);
$eventGroups = $this->getEventGroups($event);
$edits = $this->getEventEdits($event);
$labels = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventLabels')
->createQueryBuilder('el')
->select('g.groupname, el.idLabel')
->leftJoin('OceanExpertBundle:Groups', 'g', 'WITH', 'g.idGroup = el.idGroup')
->where('el.idEvent = :eventId')
->setParameter(':eventId', $event)
->orderBy('g.groupname')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
//add the label type to the labels
//mind that the array id and the label id are not the same :-(
foreach ($labels as $key => $label) {
$labels[$key]['labelType'] = $this->availableEventLabels[$label['idLabel']]['type'];
}
//make the array we need for OIH schema.org
/*
*/
$OIHTitle = preg_replace(
"/[\n\r\t]+/",
' - ',
trim(
strip_tags($eventDetails->getTitle())
)
);
$OIHData = array(
'@context' => array(
'@vocab' => 'https://schema.org/'
),
"name" => $OIHTitle
);
if ($eventType
&& $eventType->getIdEventtype() == 4
) {
$OIHData['@type'] = 'Course';
$OIHData['@id'] = 'https://oceanexpert.org/event/' . $eventDetails->getIdEvent();
$OIHData['hasCourseInstance'] = array(
'@type' => 'CourseInstance',
"name" => $OIHTitle
);
if ($eventDetails->getStartOn() != '') {
$OIHData['hasCourseInstance']
['startDate'] = $eventDetails->getStartOn()->format('Y-m-d');
}
if ($eventDetails->getEndOn() != '') {
$OIHData['hasCourseInstance']
['endDate'] = $eventDetails->getEndOn()->format('Y-m-d');
}
if ($eventDetails->getAddress() != '') {
$OIHAddress = preg_replace(
"/[\n\r\t]+/",
' - ',
trim(
strip_tags($eventDetails->getAddress())
)
);
$OIHData['hasCourseInstance']
['location'] = array(
'@type' => 'Place',
'name' => $OIHAddress,
'address' => $OIHAddress
);
}
//add the participants if we have any
$attendees = array();
if (count($participantlist)) {
foreach ($participantlist as $oihParticipant) {
//this is the info we want to share
//OE id
$oihParticipantId = $oihParticipant['id'];
//name
$oihParticipantName = $oihParticipant['fname'] . ' ' . $oihParticipant['sname'];
//title
$oihParticipantTitle = $oihParticipant['title'];
$attendees[] = array(
'@type' => 'Person',
'name' => $oihParticipantName,
'jobTitle' => $oihParticipantTitle,
'identifier' => array(
'@id' => 'ID_value_string',
'@type' => 'PropertyValue',
'propertyID' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'url' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'description' => 'UNESCO IOC IODE OceanExpert profile'
)
);
}
}
if (count($staff)) {
foreach ($staff as $oihStaff) {
//this is the info we want to share
//OE id
$oihParticipantId = $oihStaff['id'];
//name
$oihParticipantName = $oihStaff['fname'] . ' ' . $oihStaff['sname'];
//title
$oihParticipantTitle = $oihStaff['title'];
$attendees[] = array(
'@type' => 'Person',
'name' => $oihParticipantName,
'jobTitle' => $oihParticipantTitle,
'identifier' => array(
'@id' => 'ID_value_string',
'@type' => 'PropertyValue',
'propertyID' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'url' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'description' => 'UNESCO IOC IODE OceanExpert profile'
)
);
}
}
if (count($organisers)) {
foreach ($organisers as $oihOrganiser) {
//this is the info we want to share
//OE id
$oihParticipantId = $oihOrganiser['id'];
//name
$oihParticipantName = $oihOrganiser['fname'] . ' ' . $oihOrganiser['sname'];
//title
$oihParticipantTitle = $oihOrganiser['title'];
$attendees[] = array(
'@type' => 'Person',
'name' => $oihParticipantName,
'jobTitle' => $oihParticipantTitle,
'identifier' => array(
'@id' => 'ID_value_string',
'@type' => 'PropertyValue',
'propertyID' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'url' => 'https://oceanexpert.org/expert/' . $oihParticipantId,
'description' => 'UNESCO IOC IODE OceanExpert profile'
)
);
}
}
$OIHData['hasCourseInstance']
['attendee'] = $attendees;
} else {
$OIHData['@type'] = 'Event';
if ($eventDetails->getStartOn() != '') {
$OIHData['startDate'] = $eventDetails->getStartOn()->format('Y-m-d');
}
if ($eventDetails->getEndOn() != '') {
$OIHData['endDate'] = $eventDetails->getEndOn()->format('Y-m-d');
}
if ($eventDetails->getAddress() != '') {
$OIHAddress = preg_replace(
"/[\n\r\t]+/",
' - ',
trim(
strip_tags($eventDetails->getAddress())
)
);
$OIHData['location'] = array(
'@type' => 'Place',
'name' => $OIHAddress,
'address' => $OIHAddress
);
}
}
if ($eventDetails->getSummary() != '') {
$OIHSummary = preg_replace(
"/[\n\r\t]+/",
' - ',
trim(
strip_tags($eventDetails->getSummary())
)
);
$OIHData['description'] = $OIHSummary;
}
$OIHData = json_encode(
$OIHData,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK
);
return $this->render('Event/event.html.twig',
array(
'data' => array(
'OIHData' => $OIHData,
'event' => array(
'eventImage' => $eventImage,
'details' => $eventDetails,
'type' => $eventType,
'people' => array(
'organisers' => $organisers,
'staff' => $staff,
'participants' => $participantlist,
'participantsByRole' => $participantsByRole,
'numberOfParticipants' => $participant,
'numberOfProvisional' => $provisional,
'numberOfUnapproved' => $unapproved,
'numberOfRejected' => $rejected,
'numberOfDeclined' => $declined,
'total' => $participant + $provisional + $unapproved + count($staff) + count($organisers),
),
'agenda' => $agenda,
'agendaDocuments' => $agendaDocuments,
'eventPresentations' => $eventPresentations,
'backgroundDocs' => $backgroundDocs,
'otherDocs' => $otherDocs,
'report' => $report,
'eventGroups' => $eventGroups,
'eventEdits' => $edits,
'eventLabels' => $labels
),
'user' => $user,
'error' => $error
)
)
);
} else {
return new RedirectResponse($this->generateUrl('event_calendar'));
}
}
/**
* @param int $event id of the event
* @param string $order column to be used to order the results
*
* @return mixed
*/
function getAgendaDocuments($event, $order = '')
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'a.idAgendaitem, d.docCode, d.title, d.idDoc, d.authorText, d.updatedAt');
$repository->add('from', 'OceanExpertBundle:AgendaitemDocuments a');
$repository->leftJoin('OceanExpertBundle:Documents', 'd', 'WITH', 'd.idDoc = a.idDoc');
$repository->where('a.idEvent = :eventId');
$repository->setParameter('eventId', $event);
if ($order == "date") {
$repository->orderBy('d.updatedAt');
} else {
$repository->orderBy('a.idAgendaitem');
}
$agendaDocuments = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
return $agendaDocuments;
}
/**
* get CSV file with information about the participants in a given event
* is mainly used for, but not limited to, reporting for OTGA
*
* @param String $idEvent
* @param Request $request
*
* @return Response
*/
public function downloadEventParticipantsInfoAction(String $idEvent, Request $request): Response
{
$participantsInfo = $this->getPrintableParticipantsByRole($idEvent);
$header = [];
$return = [];
//set this in the template as first line
foreach($participantsInfo as $role => $participantInfo) {
$returnRow = [];
foreach ($participantInfo as $participant) {
$returnRow = $participant;
//get rid of some info we do not want
unset($returnRow['idRole']);
unset($returnRow['status']);
//unset($returnRow['gender']);
unset($returnRow['tel']);
unset($returnRow['fax']);
unset($returnRow['ordering']);
//the complete address is already calculated
unset($returnRow['useInstAddr']);
unset($returnRow['addr1']);
unset($returnRow['addr2']);
unset($returnRow['state']);
unset($returnRow['city']);
unset($returnRow['postcode']);
unset($returnRow['countryCode']);
unset($returnRow['country']);
unset($returnRow['insAddr1']);
unset($returnRow['instAddr2']);
unset($returnRow['insCity']);
unset($returnRow['insState']);
unset($returnRow['insPostcode']);
unset($returnRow['insCountryCode']);
unset($returnRow['insCountry']);
//add some info we want
$returnRow['id'] = $returnRow['idInd'];
unset($returnRow['idInd']);
$returnRow['role'] = $role;
$returnRow['idEvent'] = $idEvent;
if (count($returnRow)) {
//make the header using the first correct row
if (!count($return)) {
$header = array_keys($returnRow);
$header = implode(';', $header);
}
$return[] = htmlspecialchars_decode(
strip_tags(
implode(
';',
$returnRow
)
)
);
}
}
}
$response = $this->render(
'Event/downloadEventParticipantsInfo.html.twig',
array(
'header' => $header,
'data' => $return
)
);
$response->headers->set(
'Content-Type',
'text/csv'
);
$response->headers->set(
'Content-Disposition',
'attachment; filename="eventParticipantsInfo' . $idEvent . '_' . date('Ymd') . '.csv"'
);
return $response;
}
/**
* @param $event
* @return array
*/
public function getParticipantsByRole($event)
{
$participants = array();
$roles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->createQueryBuilder('e')
->select('e.role, e.idRole, e.pptOrdering')
->where('e.idEvent = :eventId')
->setParameter('eventId', $event)
->orderBy('e.ordering', 'asc')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$roles[] = array(
"role" => "Other",
"idRole" => '',
"pptOrdering" => '',
);
foreach ($roles as $role) {
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add(
'select',
'e.idRole,
e.idInd,
i.idInd as id,
i.title,
i.fname,
i.sname,
i.useInstAddr,
i.tel,
r.role,
c.country,
r.role,
r.ordering,
e.status,
e.accommodation,
i.tel'
);
$repository->add('from', 'OceanExpertBundle:EventParticipants e');
$repository->leftJoin('OceanExpertBundle:Indiv', 'i', 'WITH', 'i.idInd = e.idInd');
$repository->leftJoin('OceanExpertBundle:IndivInstitution', 'ii', 'WITH', 'ii.idInd = i.idInd');
$repository->leftJoin('OceanExpertBundle:Institutions', 'ins', 'WITH', 'ins.idInst = ii.idInst');
$repository->leftJoin('OceanExpertBundle:Countries', 'c', 'WITH', 'c.idCountry = i.countryCode');
$repository->leftJoin('OceanExpertBundle:EventParticipantroles', 'r', 'WITH', 'e.idRole = r.idRole and e.idEvent = r.idEvent');
$repository->where('e.idEvent = :eventId');
if ($role['idRole'] != '') {
$repository->andwhere('e.idRole = :idRole');
$repository->setParameter('idRole', $role['idRole']);
} else {
$repository->andwhere('e.idRole is NULL');
}
$repository->setParameter('eventId', $event);
switch ($role['pptOrdering']) {
case 0:
$repository->addOrderBy('i.sname', 'asc');
break;
case 1:
$repository->addOrderBy('c.country', 'asc');
break;
case 2:
$repository->addOrderBy('ins.instName', 'asc');
break;
default:
$repository->addOrderBy('i.sname', 'asc');
break;
}
$participantsTmp = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($participantsTmp as $key => $participant) {
//correct the country if the expert has choosen to use the institute address
if ($participant['useInstAddr'] === 1) {
//get the correct country, being the country of the institute
$participantsTmp[$key]['country'] = 'tbd';
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add(
'select',
'c.country'
);
$repository->add(
'from',
'OceanExpertBundle:Countries c'
);
$repository->leftJoin(
'OceanExpertBundle:Institutions',
'i',
'WITH',
'c.idCountry = i.countryCode'
);
$repository->leftJoin(
'OceanExpertBundle:IndivInstitution',
'ii',
'WITH',
'ii.idInst = i.idInst'
);
$repository->where('ii.idInd = :idInd');
$repository->setParameter('idInd', $participant['idInd']);
$country = $repository->getQuery()->getResult();
if (isset($country[0])
&& isset($country[0]['country'])
&& $country[0]['country'] != ''
) {
$participantsTmp[$key]['country'] = $country[0]['country'];
}
}
}
$participants[$role['role']] = $participantsTmp;
}
return $participants;
}
/**
* @param $idEvent
* @return array|EventGroups[]
*/
private function getEventGroups($idEvent)
{
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
$repository->add('select', 'eg.idGroup, g.groupname');
$repository->add('from', 'OceanExpertBundle:EventGroups eg');
$repository->leftJoin('OceanExpertBundle:Groups', 'g', 'WITH', 'g.idGroup = eg.idGroup');
$repository->where('eg.idEvent =:idEvent');
$repository->setParameter('idEvent', $idEvent);
$repository->orderBy('g.groupname', 'asc');
$eventGroups = $repository->getQuery()->getResult();
return $eventGroups;
}
/**
* @param int $idEvent id of the event
*
* @return array
*/
private function getEventEdits($idEvent)
{
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
$lastEdit = $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $event->getLastEditBy()));
$created = $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $event->getCreatedBy()));
if ($lastEdit) {
$edit['lastEditAt'] = $event->getUpdatedAt();
$edit['lastEditBy'] = $lastEdit->getFname() . ' ' . $lastEdit->getSname();
$edit['lastEditId'] = $event->getLastEditBy();
} else {
$edit['lastEditAt'] = $event->getUpdatedAt();
$edit['lastEditId'] = $event->getLastEditBy();
}
if ($created) {
$edit['createdBy'] = $created->getFname() . ' ' . $created->getSname();
$edit['createdAt'] = $event->getCreatedAt();
$edit['createdId'] = $event->getCreatedBy();
} else {
$edit['createdAt'] = $event->getCreatedAt();
$edit['createdId'] = $event->getCreatedBy();
}
return $edit;
}
/**
* @param $event
* @return JsonResponse
*/
public function eventImageUploadAction($event)
{
return new JsonResponse($_FILES);
}
/**
* @param $idEvent
* @param Request $request
* @return JsonResponse
*/
public function addAgendaItemAjaxAction($idEvent, Request $request)
{
$data = $request->request->all();
$em = $this->getDoctrine()->getManager();
$agendaName = isset($data['agendaName']) ? $data['agendaName'] : '';
$agendaNumber = isset($data['agendaNumber']) ? $data['agendaNumber'] : '';
$agendaOrder = 0;
//the agenda item number should be unique for this event
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'idEvent' => $idEvent,
'idAgendaitem' => $agendaNumber
)
);
if ($event) {
return new JsonResponse(
array(
'status' => 0,
'message' => 'Agenda item number already exists'
)
);
}
if (isset($data['parentId']) && $data['parentId'] != "undefined") {
$parentId = $data['parentId'];
$parent = 0;
} else {
$parentId = 0;
$parent = 1;
$highest_id = $em->createQueryBuilder()
->select('MAX(e.agendaOrder)')
->from('OceanExpertBundle:EventAgendaitems', 'e')
->where('e.idEvent = :idEvent')
->andWhere('e.parentIdevent = 0')
->setParameter(':idEvent', $idEvent)
->getQuery()
->getSingleScalarResult();
$agendaOrder = $highest_id + 1;
}
$agendaItem = new EventAgendaitems();
$agendaItem->setIdEvent($idEvent);
$agendaItem->setIdAgendaitem($agendaNumber);
$agendaItem->setParentIdevent($parentId);
$agendaItem->setTitle($agendaName);
$agendaItem->setNotes('');
$agendaItem->setRequiredActions('');
$agendaItem->setAgendaOrder($agendaOrder);
$em->persist($agendaItem);
$em->flush();
$this->updateEvent($idEvent);
$id = $agendaItem->getId();
$agendaName = $agendaItem->getTitle();
return new JsonResponse(
array(
'status' => 1,
'childGroup' => $id,
'groupName' => $agendaName,
'parent' => $parent
)
);
}
/**
* @return boolean
*/
public function updateEvent($idEvent)
{
//@todo this is not logic, normal user can copy an event but not edit it....
if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')) {
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
$author = $this->get('security.token_storage')->getToken()->getUser();
$event->setLastEditBy($author->getId());
$event->setUpdatedAt(new DateTime("now"));
$em->persist($event);
$em->flush();
}
return true;
}
/**
* @param Request $request
* @return JsonResponse
*/
public function deleteAgendaItemAjaxAction(Request $request)
{
$idAgenda = $request->request->get('agendaId');
$idEvent = $request->request->get('eventId');
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('OceanExpertBundle:EventAgendaitems')->findById($idAgenda);
if ($repository) {
$agendaItems = $em->getRepository('OceanExpertBundle:EventAgendaitems')->findOneBy(array('id' => $idAgenda));
$id = $agendaItems->getId();
$em->remove($agendaItems);
$em->flush();
do {
$agendaItems = $em->getRepository('OceanExpertBundle:EventAgendaitems')->findBy(array('parentIdevent' => $id));
if ($agendaItems) {
foreach ($agendaItems as $agendaItem) {
$id = $agendaItem->getId();
$em->remove($agendaItem);
}
$em->flush();
} else {
$id = 0;
}
} while ($id != 0);
$this->updateEvent($idEvent);
}
return new JsonResponse($idAgenda);
}
/**
* @param Request $request
* @return JsonResponse
*/
public function updateAgendaItemAjaxAction(Request $request)
{
$idAgenda = $request->request->get('idAgenda');
$idEvent = $request->request->get('idEvent');
$action = $request->request->get('action');
$em = $this->getDoctrine()->getManager();
$agenda = $em
->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'id' => $idAgenda
)
);
if ($action == "edit") {
$agendaName = $request->request->get('agendaName');
$agendaNumber = $request->request->get('agendaNumber');
$notes = $request->request->get('notes');
$actions = $request->request->get('actions');
$agenda->setIdAgendaitem($agendaNumber);
$agenda->setTitle($agendaName);
$agenda->setNotes($notes);
$agenda->setRequiredActions($actions);
$em->persist($agenda);
$em->flush();
}
$this->updateEvent($idEvent);
$agendaDetails = array(
'idAgenda' => $agenda->getId(),
'idAgendaItem' => $agenda->getIdAgendaitem(),
'agendaTitle' => $agenda->getTitle(),
'notes' => $agenda->getNotes(),
'actions' => $agenda->getRequiredActions(),
'status' => 1,
);
return new JsonResponse($agendaDetails);
}
/**
* (self)register for an event
*
* @param int $idEvent id of the event
*
* @return RedirectResponse|Response|null
*/
public function registerEventAction($idEvent, Request $request)
{
//as we need the email address
//check that the user is logged in
//and has a complete profile
if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
$user = $this->get('security.token_storage')->getToken()->getUser();
//let's check if the logged-in user has a 'real' profile
//the mandatory profile fields are all filled and the expert is active
$em = $this->getDoctrine()->getManager();
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
if (!SecurityController::checkUserProfile($em, $userId)) {
return $this->redirect(
$this->generateUrl(
'user_profile_edit'
)
);
}
$userEmail = $user->getEmail();
} else {
//redirect to the login page
return $this->redirect(
$this->generateUrl(
'fos_user_security_login',
array(
)
)
);
}
$event = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
$eventCountry = $em
->getRepository('OceanExpertBundle:Countries')
->findOneBy(
array(
'idCountry' => $event->getIdCountry()
)
);
if (!isset($eventCountry)
|| !($eventCountry->getCountry())
) {
$eventCountry = 'country not specified (yet)';
} else {
$eventCountry = $eventCountry->getCountry();
}
$status = array();
if ($request->isMethod('POST')) {
//user wants to (self)register
//even while we already checked the user's email address
// and checked that the profile exists, we still need to check
// if the user is active
$query = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->select('
i.idInd,
i.fname,
i.sname,
i.email1,
i.email2'
)
->where('i.email1 = :email')
->orWhere('i.email2 = :email')
->andWhere('i.status = 1')
->setParameter('email', $userEmail)
->getQuery();
$participant = $query->getOneOrNullResult();
if ($participant) {
$eventParticipants = $em
->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $participant['idInd']
)
);
if ($eventParticipants) {
//get some info about the user's status as participant
//skip the rest and show the register page with warning about status
$status = array(
'user' => $this->getExpertById($participant['idInd']),
'userEventStatus' => $eventParticipants->getStatus(),
);
} else {
$eventParticipants = new EventParticipants();
$eventParticipants->setIdEvent($idEvent);
$eventParticipants->setIdInd($participant['idInd']);
$eventParticipants->setStatus(2);
$eventParticipants->setArriveOn(
new DateTime(
date(
'd-m-Y',
strtotime($request->request->get('arriveOn'))
)
)
);
$eventParticipants->setLeaveOn(
new DateTime(
date(
'd-m-Y',
strtotime($request->request->get('leaveOn'))
)
)
);
$eventParticipants->setAccommodation(
$request->request->get('accomodation')
);
$eventParticipants->setContactTel(
$request->request->get('contact')
);
$eventParticipants->setStatusChangedAt(
new DateTime()
);
$em->persist($eventParticipants);
$em->flush();
$url = $this->generateUrl(
'view_event',
array(
'event' => $idEvent
)
);
return $this->redirect(
sprintf(
'%s#%s',
$url,
'participants'
)
);
}
} else {
$status = array(
'userStatus' => 'not active',
'user' => '',
'userEventStatus' => ''
);
}
}
$data = array(
'event' => $event,
'eventCountry' => $eventCountry,
'status' => $status,
'email' => $userEmail
);
return $this->render(
'Event/registerEvent.html.twig',
array(
'data' => $data
)
);
}
/**
* @param int $idInd id of the expert
*
* @return mixed
*/
private function getExpertById($idInd)
{
$query = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->select('i.idInd, i.title, i.fname, i.sname, i.email1, i.email2')
->where('i.idInd = :idInd')
->setParameter('idInd', $idInd)
->getQuery();
return $query->getOneOrNullResult();
}
/**
* @param $eventId
*/
public function updateEventAgenda($eventId)
{
//@todo there is a function to get the agenda items
$agendaItems = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventAgendaitems')
->findBy(array('idEvent' => $eventId));
$em = $this->getDoctrine()->getManager();
foreach ($agendaItems as $agendaItem) {
$items = explode('.', $agendaItem->getIdAgendaitem());
$parentId = 0;
if (count($items) > 1) {
$parentArr = array_slice($items, 0, -1);
$parent = implode(".", $parentArr);
$parentItem = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'idEvent' => $eventId,
'idAgendaitem' => $parent
)
);
$parentId = $parentItem->getId();
}
$agendaItem->setParentIdevent($parentId);
$em->persist($agendaItem);
$em->flush();
}
$this->updateEvent($eventId);
}
/**
* add a participant to the list of participant for a given event
*
* @return JsonResponse
*/
public function addEventMemberAction(Request $request, TokenGeneratorInterface $fosTokenGenerator, UserManagerInterface $fosUserManager)
{
$idInd = $request->request->get('idInd');
$idEvent = $request->request->get('idEvent');
$membertype = $request->request->get('membertype');
$name = $request->request->get('name');
$em = $this->getDoctrine()->getManager();
$participantRoles = array();
$status = 0;
//why did the status not change to 1
$reason = '';
//get the correct email address of the user
$user = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $idInd
)
);
if ($user) {
$email1 = $user->getEmail1();
$email2 = $user->getEmail2();
if ($email2 != '') {
$email = $email2;
} elseif ($email1 != '') {
$email = $email1;
} else {
$email = 'info@oceanexpert.org';
}
} else {
$reason = 'user not found';
}
//get the info about the event
$eventInfo = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if (!$eventInfo) {
$reason = 'event not found';
} else {
if ($membertype == 1) {
$participantType = 'event organiser';
$eventStaff = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventContacts')
->findBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if (!$eventStaff) {
$eventContact = new EventContacts();
$eventContact->setIdEvent($idEvent);
$eventContact->setIdInd($idInd);
$eventContact->setContactFor('');
$em->persist($eventContact);
$em->flush();
$status = 1;
} else {
$reason = 'already in event contacts';
}
} elseif ($membertype == 2) {
$participantType = 'event staff member';
$eventStaff = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventStaff')
->findBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if (!$eventStaff) {
$eventStaff = new EventStaff();
$eventStaff->setIdEvent($idEvent);
$eventStaff->setIdInd($idInd);
$em->persist($eventStaff);
$em->flush();
$status = 1;
} else {
$reason = 'is already in the event staff';
}
} elseif ($membertype == 3) {
$participantType = 'event participant';
$eventParticipant = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventParticipants')
->findBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if (!$eventParticipant) {
$eventParticipant = new EventParticipants();
$eventParticipant->setIdEvent($idEvent);
$eventParticipant->setStatus(1);
$eventParticipant->setIdInd($idInd);
$em->persist($eventParticipant);
$em->flush();
$status = 1;
} else {
$reason = 'already in event participants';
}
$participantRoles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->createQueryBuilder('e')
->select('e.idRole,e.role')
->where('e.idEvent = :eventId')
->setParameter('eventId', $idEvent)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
} elseif ($membertype == 4) {
$participantType = 'event observer';
$eventInfo->setIdContact($idInd);
$em->persist($eventInfo);
$em->flush();
$status = 1;
}
$this->updateEvent($idEvent);
}
if ($reason === '') {
$participantCountry = $this->getDoctrine()
->getRepository('OceanExpertBundle:Indiv')
->createQueryBuilder('i')
->leftJoin('OceanExpertBundle:Countries', 'c', 'WITH', 'i.countryCode = c.idCountry')
->select('c.country')
->where('i.idInd = :idInd')
->setParameter('idInd', $idInd)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
} else {
$participantCountry = array();
$participantCountry[0]['country'] = '';
}
$data = array(
'idInd' => $idInd,
'name' => $name,
'participantRoles' => $participantRoles,
'participantCountry' => $participantCountry[0]['country'],
'memberType' => $membertype,
);
$event = array(
'idEvent' => $idEvent,
'title' => $eventInfo->getTitle(),
'eventPeriod' => $eventInfo->getStartOn()->format('d-m-Y') . ' to ' . $eventInfo->getEndOn()->format('d-m-Y'),
'eventAddress' => $eventInfo->getAddress(),
'eventUrl' => $this->generateUrl(
'view_event',
array(
'event' => $idEvent
),
UrlGeneratorInterface::ABSOLUTE_URL
)
);
//send an email to the user to let them know they have been added to the event
if ($eventInfo->getEmailPeople()
&& $reason === ''
) {
//who is sending this mail
$sendUser = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $eventInfo->getIdContact()
)
);
if ($sendUser) {
$firstName = $sendUser->getFName();
$lastName = $sendUser->getSName();
if ($firstName != '' && $lastName != '') {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' . $firstName . ' ' . $lastName
);
} else {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
} else {
$fromEmail =array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
$message = new Swift_Message(
'Participation in an event',
$this->renderView(
'Email/eventAddParticipant.html.twig',
array(
'data' => $data,
'event' => $event,
'participantType' => $participantType
)
),
'text/html'
);
$message->setFrom(
$fromEmail
);
$message->setTo(
array(
$email => $name
)
);
$this->get('mailer')->send($message);
$comment = 'sent mail to ' . $email;
} elseif (!$eventInfo->getEmailPeople()) {
$comment = 'no mail sent as this option is not set';
}
$return = array(
'data' => $data,
'status' => $status
);
if ($reason !== '') {
$return['reason'] = $reason;
}
//add some comment if any
if ($comment !== '') {
$return['comment'] = $comment;
}
return new JsonResponse(
$return
);
}
/**
* @return JsonResponse
*/
public function deleteEventMemberAction(Request $request)
{
$idInd = $request->request->get('idInd');
$idEvent = $request->request->get('idEvent');
$membertype = $request->request->get('membertype');
$comment = '';
$em = $this->getDoctrine()->getManager();
switch ($membertype) {
case 1:
$eventContact = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventContacts')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if ($eventContact) {
$em->remove($eventContact);
$em->flush();
}
break;
case 2:
$eventStaff = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventStaff')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if ($eventStaff) {
$em->remove($eventStaff);
$em->flush();
}
break;
case 3:
$eventParticipant = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if ($eventParticipant) {
$em->remove($eventParticipant);
$em->flush();
}
break;
}
//send an email to the user to let them know they have been removed from the event
$eventInfo = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($eventInfo->getEmailPeople()) {
//get the name and email of the participant
$participant = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $idInd
)
);
//strange construction to keep this compatible with the other send mail code
//this will make it easier to refactor this later
$data['name'] = $participant->getTitle() . ' ' . $participant->getFName() . ' ' . $participant->getSName();
$participantEmail1 = $participant->getEmail1();
$participantEmail2 = $participant->getEmail2();
if ($participantEmail2 != '') {
$email = $participantEmail2;
} elseif ($participantEmail1 != '') {
$email = $participantEmail1;
}
//who is sending this mail
$sendUser = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $eventInfo->getIdContact()
)
);
if ($sendUser) {
$firstName = $sendUser->getFName();
$lastName = $sendUser->getSName();
if ($firstName != '' && $lastName != '') {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' . $firstName . ' ' . $lastName
);
} else {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
} else {
$fromEmail =array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
$event['title'] = $eventInfo->getTitle();
$event['eventAddress'] = $eventInfo->getAddress();
$event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' . $eventInfo->getEndOn()->format('d-m-Y');
$event['eventUrl'] = $this->generateUrl(
'view_event',
array(
'event' => $idEvent
),
UrlGeneratorInterface::ABSOLUTE_URL
);
$message = new Swift_Message(
'Participation in an event',
$this->renderView(
'Email/eventDeleteParticipant.html.twig',
array(
'data' => $data,
'event' => $event
)
),
'text/html'
);
$message->setFrom(
$fromEmail
);
$message->setTo(
array(
$email => $data['name']
)
);
$this->get('mailer')->send($message);
$comment = 'sent mail to ' . $email;
} elseif (!$eventInfo->getEmailPeople()) {
$comment = 'no mail sent as this option is not set';
}
return new JsonResponse(
array(
'status' => 1,
'id' => $membertype,
'comment' => $comment
)
);
}
/**
* change some settings of a event participant
* this is called by AJAX when either
* - changing the role
* - changing the status
* - changing the comments
* this is not the same as editParticipantAction()
*
* @return JsonResponse
*/
public function editEventMemberAction(Request $request)
{
$data = $request->request->all();
$idEvent = $data['idEvent'];
$idInd = $data['idInd'];
$em = $this->getDoctrine()->getManager();
$eventParticipant = $em
->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
if (isset($data['idRole'])) {
$idRole = $data['idRole'];
//get information about the old role
$oldRoleId = $eventParticipant->getIdRole();
$oldRole = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventParticipantroles')
->findOneBy(
array(
'idRole' => $oldRoleId,
'idEvent' => $idEvent
)
);
if ($oldRole) {
$oldRole = $oldRole->getRole();
} else {
$oldRole = 'no role';
}
//set the new roleid
$eventParticipant->setIdRole($idRole);
//get info about the new role
$role = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:EventParticipantroles')
->findOneBy(
array(
'idRole' => $idRole,
'idEvent' => $idEvent
)
);
$role = $role->getRole();
$mailContent = "role changed from '$oldRole' to '$role'";
} elseif (isset($data['comments'])) {
$oldComments = $eventParticipant->getAccommodation();
$eventParticipant->setAccommodation($data['comments']);
$mailContent = "comments changed from '$oldComments' to '" . $data['comments'] . '"';
} elseif (isset($data['status'])) {
$oldStatus = $this->participantStatus[$eventParticipant->getStatus()];
$status = $this->participantStatus[$data['status']];
$eventParticipant->setStatus($data['status']);
$mailContent = "status changed from '$oldStatus' to '$status'";
}
$em->persist($eventParticipant);
$em->flush();
$this->updateEvent($data['idEvent']);
//send an email to the user to warn that something has changed
$eventInfo = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($eventInfo->getEmailPeople()) {
//get the name and email of the participant
$participant = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $idInd
)
);
//strange construction to keep this compatible with the other send mail code
//this will make it easier to refactor this later
$data['name'] = $participant->getTitle() . ' ' . $participant->getFName() . ' ' . $participant->getSName();
$participantEmail1 = $participant->getEmail1();
$participantEmail2 = $participant->getEmail2();
if ($participantEmail2 != '') {
$email = $participantEmail2;
} elseif ($participantEmail1 != '') {
$email = $participantEmail1;
}
//who is sending this mail
$sendUser = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $eventInfo->getIdContact()
)
);
if ($sendUser) {
$firstName = $sendUser->getFName();
$lastName = $sendUser->getSName();
if ($firstName != '' && $lastName != '') {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' . $firstName . ' ' . $lastName
);
} else {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
} else {
$fromEmail =array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
$event['title'] = $eventInfo->getTitle();
$event['eventAddress'] = $eventInfo->getAddress();
$event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' . $eventInfo->getEndOn()->format('d-m-Y');
$event['eventUrl'] = $this->generateUrl(
'view_event',
array(
'event' => $idEvent
),
UrlGeneratorInterface::ABSOLUTE_URL
);
$message = new Swift_Message(
'Participation in an event',
$this->renderView(
'Email/eventEditParticipant.html.twig',
array(
'data' => $data,
'event' => $event,
'mailContent' => $mailContent
)
),
'text/html'
);
$message->setFrom(
$fromEmail
);
$message->setTo(
array(
$email => $data['name']
)
);
$this->get('mailer')->send($message);
$comment = 'sent mail to ' . $email;
} elseif (!$eventInfo->getEmailPeople()) {
$comment = 'no mail sent as this option is not set';
}
return new JsonResponse(
array(
'status' => 1,
'paricipant' => $eventParticipant,
'comment' => $comment,
'mailContent' => $mailContent
)
);
}
/**
* change the info linked to a event contact/organiser
* this is called by AJAX
*
* @return JsonResponse
*/
public function editEventContactsAction(Request $request)
{
$idInd = $request->request->get('idInd');
$idEvent = $request->request->get('idEvent');
$contactfor = $request->request->get('contactfor');
$em = $this->getDoctrine()->getManager();
$eventContact = $em
->getRepository('OceanExpertBundle:EventContacts')
->findOneBy(
array(
'idEvent' => $idEvent,
'idInd' => $idInd
)
);
//get the old contactfor value
$oldContactFor = $eventContact->getContactFor();
$mailContent = "'contact for' changed from '$oldContactFor' to '$contactfor'";
$eventContact->setContactFor($contactfor);
$em->persist($eventContact);
$em->flush();
$this->updateEvent($idEvent);
//send an email to the user to warn that something has changed
$eventInfo = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($eventInfo->getEmailPeople()) {
//get the name and email of the participant
$participant = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $idInd
)
);
//strange construction to keep this compatible with the other send mail code
//this will make it easier to refactor this later
$data['name'] = $participant->getTitle() . ' ' . $participant->getFName() . ' ' . $participant->getSName();
$participantEmail1 = $participant->getEmail1();
$participantEmail2 = $participant->getEmail2();
if ($participantEmail2 != '') {
$email = $participantEmail2;
} elseif ($participantEmail1 != '') {
$email = $participantEmail1;
}
//who is sending this mail
$sendUser = $this->getDoctrine()->getManager()
->getRepository('OceanExpertBundle:Indiv')
->findOneBy(
array(
'idInd' => $eventInfo->getIdContact()
)
);
if ($sendUser) {
$firstName = $sendUser->getFName();
$lastName = $sendUser->getSName();
if ($firstName != '' && $lastName != '') {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team on behalf of ' . $firstName . ' ' . $lastName
);
} else {
$fromEmail = array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
} else {
$fromEmail =array(
'info@oceanexpert.org' => 'OceanExpert Team'
);
}
$event['title'] = $eventInfo->getTitle();
$event['eventAddress'] = $eventInfo->getAddress();
$event['eventPeriod'] = $eventInfo->getStartOn()->format('d-m-Y') . ' to ' . $eventInfo->getEndOn()->format('d-m-Y');
$event['eventUrl'] = $this->generateUrl(
'view_event',
array(
'event' => $idEvent
),
UrlGeneratorInterface::ABSOLUTE_URL
);
$message = new Swift_Message(
'Participation in an event',
$this->renderView(
'Email/eventEditParticipant.html.twig',
array(
'data' => $data,
'event' => $event,
'mailContent' => $mailContent
)
),
'text/html'
);
$message->setFrom(
$fromEmail
);
$message->setTo(
array(
$email => $data['name']
)
);
$this->get('mailer')->send($message);
$comment = 'sent mail to ' . $email;
} elseif (!$eventInfo->getEmailPeople()) {
$comment = 'no mail sent as this option is not set';
}
return new JsonResponse(
array(
'status' => 1,
'comment' => $comment,
'mailContent' => $mailContent
)
);
}
/**
* @return JsonResponse
*/
public function eventClearContactAction(Request $request)
{
$idEvent = $request->request->get('idEvent');
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
$event->setIdContact('');
$em->persist($event);
$em->flush();
$this->updateEvent($idEvent);
return new JsonResponse(array('status' => 1));
}
/**
* @param Request $request
*
* @return JsonResponse
*/
public function addEventDocumentAction(Request $request)
{
$documentType = $request->request->get('doctype');
$idEvent = $request->request->get('idEvent');
$idDoc = $request->request->get('idDoc');
if (null != $request->request->get('idAgenda')) {
$idAgenda = $request->request->get('idAgenda');
}
$em = $this->getDoctrine()->getManager();
$idAgendaItem = '';
//see doctypes in the database
switch ($documentType) {
case "1":
$report = $em->getRepository('OceanExpertBundle:EventReports')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if ($report) {
$em->remove($report);
$em->flush();
}
$report = new EventReports();
$report->setIdEvent($idEvent);
$report->setIdDoc($idDoc);
$em->persist($report);
$em->flush();
break;
case "2":
$presentation = $em->getRepository('OceanExpertBundle:EventPresentations')
->findOneBy(
array(
'idEvent' => $idEvent,
'idDoc' => $idDoc
)
);
if ($presentation) {
$em->remove($presentation);
$em->flush();
}
$presentation = new EventPresentations();
$presentation->setIdDoc($idDoc);
$presentation->setIdEvent($idEvent);
$em->persist($presentation);
$em->flush();
break;
case "3":
$backgroundDocs = $em->getRepository('OceanExpertBundle:EventBackgrounddocs')
->findOneBy(
array(
'idEvent' => $idEvent,
'idDoc' => $idDoc
)
);
if ($backgroundDocs) {
$em->remove($backgroundDocs);
$em->flush();
}
$backgroundDocs = new EventBackgrounddocs();
$backgroundDocs->setIdDoc($idDoc);
$backgroundDocs->setIdEvent($idEvent);
$em->persist($backgroundDocs);
$em->flush();
break;
case "4":
$otherDocs = $em->getRepository('OceanExpertBundle:EventOtherdocs')
->findOneBy(
array(
'idEvent' => $idEvent,
'idDoc' => $idDoc
)
);
if ($otherDocs) {
$em->remove($otherDocs);
$em->flush();
}
$otherDocs = new EventOtherdocs();
$otherDocs->setIdDoc($idDoc);
$otherDocs->setIdEvent($idEvent);
$em->persist($otherDocs);
$em->flush();
break;
case "5":
if ($idAgenda != '') {
$agendaDetails = $em->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'id' => $idAgenda
)
);
if ($agendaDetails) {
$idAgendaItem = $agendaDetails->getIdAgendaitem();
$agendaDocs = $em->getRepository('OceanExpertBundle:AgendaitemDocuments')
->findOneBy(
array(
'idEvent' => $idEvent,
'idDoc' => $idDoc,
'idAgendaitem' => $agendaDetails->getIdAgendaitem()
)
);
if ($agendaDocs) {
$em->remove($agendaDocs);
$em->flush();
}
$conn = $this->getDoctrine()->getConnection();
$stmt = $conn->prepare('INSERT INTO agendaitem_documents (id_event, id_agendaitem, id_doc) VALUES (?, ?, ?)');
$stmt->bindValue(1, $idEvent);
$stmt->bindValue(2, $idAgendaItem);
$stmt->bindValue(3, $idDoc);
$stmt->execute();
}
}
break;
}
$data = array(
'status' => 1,
$request->request->all(),
'idAgendaItem' => $idAgendaItem
);
return new JsonResponse($data);
}
/**
* @return JsonResponse
*/
public function saveAgendaOrderAction(Request $request): JsonResponse
{
$order = $request->request->get('order');
$agendaOrders = json_decode($order);
$i = 0;
foreach ($agendaOrders->groups as $agendaData) {
$agenda = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventAgendaitems')
->findOneBy(
array(
'id' => $agendaData->agendaId
)
);
$em = $this->getDoctrine()->getManager();
if ($agenda) {
$agenda->setParentIdevent($agendaData->parentId);
$agenda->setAgendaOrder($i);
$em->persist($agenda);
$em->flush();
$this->updateEvent($agenda->getIdEvent());
}
$i++;
}
return new JsonResponse($order);
}
/**
* @return Response
*/
function updatePresentationAgendaAction(Request $request)
{
$idDoc = $request->request->get('idDoc');
$idEvent = $request->request->get('idEvent');
$agendaItem = $request->request->get('agendaItem');
$em = $this->getDoctrine()->getManager();
$eventPresentation = $em->getRepository('OceanExpertBundle:EventPresentations')
->findOneBy(
array(
'idEvent' => $idEvent,
'idDoc' => $idDoc
)
);
if ($eventPresentation) {
$eventPresentation->setIdAgendaitem($agendaItem);
$em->persist($eventPresentation);
$em->flush();
$this->updateEvent($idEvent);
}
return new JsonResponse(array('status' => 1));
}
/**
* send an invitation to the participants that have been added to this event
*
* @return Response
*/
public function sendInvitesEventParticipantsAction(Request $request)
{
//what is our environment?
$env = $this->container->get('kernel')->getEnvironment();
$idEvent = $request
->request
->get('idEvent');
$em = $this
->getDoctrine()
->getManager();
$event = $em
->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
$sender = $this->fosUserManager->findUserBy(
array(
'id' => $event->getIdContact()
)
);
$data = array(
'userid' => $event->getIdContact(),
'eventInvitation' => $event->getIdEvent(),
'selfMail' => "false",
'email' => $sender->getEmail()
);
$filename = uniqid() . '.json';
$filePath = '/tmp/emailqueue';
if ($env !== 'prod') {
$filePath .= "_$env";
}
if (!file_exists($filePath . '/')) {
mkdir(
$filePath,
0777
);
}
$fp = fopen(
$filePath . '/' . $filename,
'w'
);
fwrite($fp, json_encode($data));
fclose($fp);
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$eventUrl = $baseurl . $this->generateUrl('view_event', array('event' => $idEvent));
$message = new Messages();
$message->setIdSender($event->getIdContact());
$message->setSearchstring($eventUrl);
$message->setSubject("Event Invitation Mail");
$message->setMessage("Event Invitation email for all participants for event " . $event->getTitle());
$message->setIgnoreprefs(1);
$message->setApproved(2);
$message->setDateentered(new DateTime("now"));
$message->setDatequeued(new DateTime("now"));
$em->persist($message);
$em->flush();
$mailQueue = new MailQueueFiles();
$mailQueue->setIdInd($event->getIdContact());
$mailQueue->setFileName($filename);
$mailQueue->setCreatedAt(new DateTime("now"));
$mailQueue->setProcessedAt(null);
$mailQueue->setProcessed(0);
$mailQueue->setIdMessage($message->getIdMsg());
$mailQueue->setApproved(1);
$em->persist($mailQueue);
$em->flush();
return new JsonResponse(
array(
'status' => 1
)
);
}
/**
* store the confirmation of a participant to an event
*
* @param int $idEvent id of the event
* @param string $hash the confirmation check hash
* @param Request $request the request object
*
* @return Response
*
* @throws \Exception
*/
public function confirmEventParticipationAction(int $idEvent, string $hash, Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$participants = $em->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idEvent' => $idEvent,
'hash' => $hash
)
);
$event = $em->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
$eventCountry = $em->getRepository('OceanExpertBundle:Countries')
->findOneBy(
array(
'idCountry' => $event->getIdCountry()
)
);
if ($participants) {
if ($participants->getStatus() == 1) {
$message = array(
'status' => 1,
'message' => '',
);
} else {
$message = array(
'status' => 0,
'message' => "Your participation in this event has already been confirmed.",
);
}
$expert = $this->getExpertById($participants->getIdInd());
} else {
$message = array(
'status' => 0,
'message' => "The link you are trying to use to confirm your participation is (no longer) valid.",
);
$expert = '';
}
if (null != ($request->request->get('decision'))
&& $request->request->get('decision') != ''
&& null != $participants
) {
$decision = $request->request->get('decision');
$reason = '';
if ($event->getIdContact() != '') {
$contact = $this->getExpertById($event->getIdContact());
} else {
$contact = $this->getExpertById($event->getCreatedBy());
}
$fromName = ucwords($contact['fname']) . ' ' . ucwords($contact['sname']);
$participantName = ucwords($expert['fname']) . ' ' . ucwords($expert['sname']);
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$eventUrl = $baseurl . $this->generateUrl('view_event', array('event' => $idEvent));
if (null != ($request->request->get('reason'))) {
$reason = $request->request->get('reason');
}
if ($decision == 1) {
$participants->setStatus(0);
if (null != ($request->request->get('arriveOn'))) {
$arriveOn = $request->request->get('arriveOn');
$participants->setArriveOn(
new DateTime(date(
'd-m-Y',
strtotime($arriveOn)
)
)
);
}
if (null != ($request->request->get('leaveOn'))) {
$leaveOn = $request->request->get('leaveOn');
$participants->setLeaveOn(
new DateTime(date(
'd-m-Y',
strtotime($leaveOn)
)
)
);
}
if (null != ($request->request->get('contact'))) {
$contactTel = $request->request->get('contact');
$participants->setContactTel($contactTel);
}
$action = 'Thank you, your acceptance has been noted and a confirmation has been sent to you by email.';
$subject = 'Confirmation of Participation in "' . $event->getTitle() . '"';
$msg = '<p>Dear ' . $expert['title'] . ' ' . ucwords($expert['fname']) . ' ' . ucwords($expert['sname']) . ',</p>';
$msg .= '<p>Thank you for confirming your participation in the event "' . $event->getTitle() . '". </p>';
$msg .= '<p>All information on this event can be found at:</p>';
$msg .= '<p><a href="' . $eventUrl . '">' . $eventUrl . '</a></p>';
$msg .= 'Regards,<br/>';
$msg .= $fromName;
if (trim($expert['email2']) != '') {
$recipient = $expert['email2'];
} else {
$recipient = $expert['email1'];
}
if (trim($contact['email2']) != '') {
$sender = $contact['email2'];
} else {
$sender = $contact['email1'];
}
$this->sendEmail(
$recipient,
$sender,
$subject,
$msg,
$contact['idInd']
);
} else {
$participants->setStatus(3);
$action = "Thank you, your response has been noted. Thanks for replying to our invitation.";
$subject = ucwords($participantName) . " has Declined an Event Invitation";
$msg = "<p>Dear " . ucwords($fromName) . ",</p>";
$msg .= "<p>This is an email to let you know that " . ucwords($participantName) . ' ';
$msg .= "has declined an invitation to take part in '" . $event->getTitle() . "'.</p>";
if ($reason) {
$msg .= "<p>They gave the following reason:</p>";
$msg .= "<p>'" . $reason . "'</p>";
}
$msg .= "<p>You can view the status of all of the participants for this event at</p>";
$msg .= "<p><a href='" . $eventUrl . "#participants'>$eventUrl#participants</a>" . "</p>";
$msg .= "Regards,<br/>";
$msg .= "OceanExpert Team";
if (trim($contact['email2']) != '') {
$recipient = $contact['email2'];
} else {
$recipient = $contact['email1'];
}
$this->sendEmail(
$recipient,
"info@oceanexpert.org",
$subject,
$msg,
$contact['idInd']
);
}
$participants->setStatusChangedAt(new DateTime('now'));
$em->persist($participants);
$em->flush();
$message = array(
'status' => 2,
'message' => $action,
);
}
if (!isset($eventCountry)
|| !($eventCountry->getCountry())
) {
$eventCountry = 'not specified (yet)';
} else {
$eventCountry = $eventCountry->getCountry();
}
$data = array(
'event' => $event,
'response' => $message,
'expert' => $expert,
'eventCountry' => $eventCountry,
);
return $this->render(
'Event/eventConfirmation.html.twig',
array(
'data' => $data
)
);
}
/**
* @param $to
* @param $from
* @param $subject
* @param $message
* @param $idInd
*/
private function sendEmail($to, $from, $subject, $message, $idInd)
{
$em = $this->getDoctrine()->getManager();
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$now = new DateTime('now');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$template = $this->get('twig')
->render(
'Email/generalEventTemplate.html.twig',
array(
'message' => $message
)
);
$mail = new Mails();
$mail->setCreateTime($now);
$mail->setTimeToSend($now);
$mail->setIdUser($idInd);
$mail->setIp($ip);
$mail->setSender($from);
$mail->setRecipient($to);
$mail->setHeaders($headers);
$mail->setSubject($subject);
$mail->setBody(
trim(
preg_replace(
'/\s\s+/',
' ',
$template
)
)
);
$mail->setAttachments('');
$mail->setTrySent(0);
$mail->setDeleteAfterSend(1);
$mail->setMandrilId(null);
$em->persist($mail);
$em->flush();
}
/**
* @param $idEvent
* @return Response
*/
public function viewPrintableParticipantsAction($idEvent)
{
if ($idEvent == 0) {
return new Response('No event id provided.');
}
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
$data = array(
'event' => $event,
'participants' => $this->getPrintableParticipantsByRole($idEvent)
);
return $this->render('Event/printableParticipants.html.twig', array('data' => $data));
}
/**
* get the participants by role for the given event
*
* @param int idEvent
*
* @return array | Response
*/
private function getPrintableParticipantsByRole($idEvent)
{
$participants = array();
$roles = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventParticipantroles')
->createQueryBuilder('e')
->select('e.role,e.idRole,e.pptOrdering')
->where('e.idEvent = :eventId')
->setParameter('eventId', $idEvent)
->orderBy('e.ordering', 'asc')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
$roles[] = array(
"role" => "Other",
"idRole" => '',
"pptOrdering" => '',
);
$addressFormatRepository = new AddressFormatRepository();
$countryRepository = new CountryRepository();
$subdivisionRepository = new SubdivisionRepository();
$formatter = new DefaultFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository);
$address = new Address();
foreach ($roles as $role) {
$repository = $this->getDoctrine()->getManager()->createQueryBuilder();
if ($this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
//let's check if the logged-in user has a 'real' profile
//the mandatory profile fields are all filled and the expert is active
$em = $this->getDoctrine()->getManager();
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
if (!SecurityController::checkUserProfile($em, $userId)) {
return $this->render(
'Exception/error.html.twig',
array(
'message' => 'seems your profile is not complete yet or has not been approved yet. Please complete your profile first.',
)
);
}
$repository->add(
'select',
'e.idRole,
e.idInd,
e.status,
i.title,
i.fname,
i.sname,
i.gender,
i.useInstAddr,
i.tel,
i.fax,
i.addr1,
i.addr2,
i.city,
i.state,
i.postcode,
i.jobtitle,
i.email1,
i.email2,
c.countryCode,
c.country,
ins.instName,
ins.instNameEng,
i.dept,
ins.instAddress insAddr1,
ins.addr2 as instAddr2,
ins.city as insCity,
ins.state as insState,
ins.postcode as insPostcode,
ci.countryCode as insCountryCode,
ci.country as insCountry,
r.role,
r.ordering'
);
} else {
$repository->add(
'select',
'e.idRole,
e.idInd,
e.status,
i.title,
i.fname,
i.sname,
i.useInstAddr,
i.tel,
i.fax,
i.addr1,
i.addr2,
i.city,
i.state,
i.postcode,
i.jobtitle,
i.email1,
i.email2,
c.countryCode,
c.country,
ins.instName,
ins.instNameEng,
i.dept,
ins.instAddress as insAddr1,
ins.addr2 as instAddr2,
ins.city as insCity,
ins.state as insState,
ins.postcode as insPostcode,
ci.countryCode as insCountryCode,
ci.country as insCountry,
r.role,
r.ordering'
);
}
$repository->add(
'from',
'OceanExpertBundle:EventParticipants e'
);
$repository->leftJoin(
'OceanExpertBundle:Indiv',
'i',
'WITH',
'i.idInd = e.idInd'
);
$repository->leftJoin(
'OceanExpertBundle:IndivInstitution',
'ii',
'WITH',
'ii.idInd = i.idInd'
);
$repository->leftJoin(
'OceanExpertBundle:Countries',
'c',
'WITH',
'c.idCountry = i.countryCode'
);
$repository->leftJoin(
'OceanExpertBundle:Institutions',
'ins',
'WITH',
'ins.idInst = ii.idInst'
);
$repository->leftJoin(
'OceanExpertBundle:Countries',
'ci',
'WITH',
'ci.idCountry = ins.countryCode'
);
$repository->leftJoin(
'OceanExpertBundle:EventParticipantroles',
'r',
'WITH',
'e.idRole = r.idRole and e.idEvent = r.idEvent'
);
$repository->where('e.idEvent = :eventId');
$repository->andWhere('e.status in (0,1)');
if ($role['idRole'] != '') {
$repository->andwhere('e.idRole = :idRole');
$repository->setParameter('idRole', $role['idRole']);
} else {
$repository->andwhere('e.idRole is NULL');
}
$repository->setParameter('eventId', $idEvent);
$repository->addOrderBy('i.sname', 'asc');
$participantsResult = $repository->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($participantsResult as $key => $participant) {
if ($participant['useInstAddr'] == 1) {
$address = $address
->withCountryCode($participant['insCountryCode'])
->withAdministrativeArea($participant['insState'])
->withLocality($participant['insCity'])
->withPostalCode($participant['insPostcode'])
->withAddressLine1($participant['insAddr1'])
->withAddressLine2($participant['instAddr2']);
} else {
$address = $address
->withCountryCode($participant['countryCode'])
->withAdministrativeArea($participant['state'])
->withLocality($participant['city'])
->withPostalCode($participant['postcode'])
->withAddressLine1($participant['addr1'])
->withAddressLine2($participant['addr2']);
}
try {
$participantsResult[$key]['address'] = $formatter->format($address);
} catch (ErrorException $e) {
$participantsResult[$key]['address'] = 'incorrect address';
}
}
if (count($participantsResult) > 0) {
$participants[$role['role']] = $participantsResult;
}
}
//remove as much as possible all stupid chars that people enter in their profiles....
//or stuff we put there....
//put all in one string
$participants = json_encode($participants);
//these lines may look weird
// but this is the only way to get rid of ALL strange things people put in their profiles
$participants = preg_replace('/&/s', 'and ', $participants);
$participants = preg_replace('/amp;/s', '', $participants);
$participants = preg_replace('/"/s', 'and ', $participants);
$participants = preg_replace('/quot;/s', '', $participants);
$participants = preg_replace('/&/s', 'and ', $participants);
$participants = preg_replace('/\\\"/s', '', $participants);
$participants = html_entity_decode($participants);
$participants = htmlspecialchars_decode($participants);
$participants = preg_replace('/<br\s?\/?>/s', ' ', $participants);
$participants = preg_replace('/<\/?p>/s', ' ', $participants);
$participants = strip_tags($participants);
$participants = preg_replace('/\\\\r\\\\n/s', ' ', $participants);
$participants = preg_replace('/\n/', '', $participants);
$participants = preg_replace('/\\\\n/', '', $participants);
$participants = preg_replace('/\s+/', ' ', $participants);
//make it an associative array again
return json_decode($participants, true);
}
/**
* @param $idEvent
* @return Response
*/
public function viewAgendaPrintableAction($idEvent)
{
$data = $this->getPrintableAgendaData($idEvent);
return $this->render(
'Event/agendaPrintable.html.twig',
array(
'data' => $data
)
);
}
/**
* get the agenda items for this event
* sort the data by agendaOrder in a natural order
*
* @param int $idEvent
*
* @return array|Response
*/
private function getPrintableAgendaData(int $idEvent)
{
if ($idEvent == 0) {
return new Response('No event id provided.');
}
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
$country = $em->getRepository('OceanExpertBundle:Countries')
->findOneBy(
array(
'idCountry' => $event->getIdCountry()
)
);
$tmpAgendaItems = $this->getDoctrine()
->getRepository('OceanExpertBundle:EventAgendaitems')
->createQueryBuilder('e')
->select('e.idAgendaitem, e.id, e.title, e.parentIdevent, e.agendaOrder, e.notes, e.requiredActions')
->where('e.idEvent = :eventId')
->setParameter(':eventId', $event)
->addOrderBy('e.idAgendaitem + 0', 'ASC')
->addOrderBy('e.agendaOrder', 'ASC')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($tmpAgendaItems as $key => $tmpAgendaItem) {
$agendaItems[$tmpAgendaItem['idAgendaitem']] = $tmpAgendaItem;
}
ksort($agendaItems, SORT_NATURAL);
$addressFormatRepository = new AddressFormatRepository();
$countryRepository = new CountryRepository();
$subdivisionRepository = new SubdivisionRepository();
$formatter = new DefaultFormatter(
$addressFormatRepository,
$countryRepository,
$subdivisionRepository
);
if (isset($country)) {
$address = new Address();
$address = $address
->withCountryCode($country->getCountryCode())
->withAdministrativeArea($event->getState())
->withLocality($event->getCity())
->withPostalCode($event->getPostcode())
->withAddressLine1($event->getAddress());
$address = $formatter->format($address);
} else {
$address = 'no location specified or online event';
}
return array(
'event' => $event,
'address' => $address,
'agenda' => $agendaItems
);
}
/**
* @param $idEvent
* @return Response
*/
public function viewAnnonatedAgendaPrintableAction($idEvent)
{
$data = $this->getPrintableAgendaData($idEvent);
return $this->render('Event/agendaAnnonated.html.twig', array('data' => $data));
}
/**
* @return JsonResponse
*/
public function updateEventStatusAction(Request $request)
{
$idEvent = $request->request->get('idEvent');
$eventStatus = $request->request->get('eventStatus');
$status = 0;
$message = '';
if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')) {
$author = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
if (isset($eventStatus)
&& $eventStatus != ''
) {
$event->setStatus($eventStatus);
$event->setLastEditBy($author->getId());
$event->setUpdatedAt(new DateTime("now"));
$em->persist($event);
$em->flush();
$status = 1;
}
} else {
$status = 0;
$message = 'you have no rights to do this';
}
return new JsonResponse(
array(
'status' => $status,
'eStatus' => $eventStatus,
'message' => $message
)
);
}
/**
* @param $idEvent
* @param $idFile
* @param Request $request
*
* @return Response|RedirectResponse
*/
public function importParticipantsAction($idEvent, $idFile, Request $request)
{
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
$eventDetails = $this->getDoctrine()->getRepository('OceanExpertBundle:Events')->findOneBy(array('idEvent' => $idEvent));
$eventParticipants = array();
$idfile = '';
$importFile = array();
$error = '';
$em = $this->getDoctrine()->getManager();
if ($idFile != 0) {
$eventParticipants = $this->getImportdata($idFile);
$importFile = $em->getRepository('OceanExpertBundle:EventParticipantImportFiles')->findOneBy(array('id' => $idFile, 'idEvent' => $idEvent));
if (!$importFile) {
return $this->redirect($this->generateUrl('import_event_participants', array('idEvent' => $idEvent)));
}
}
if ($request->isMethod('POST')) {
$file = $request->files->get('importfile');
$filedata = array(
'id' => $idEvent,
'file' => $file,
'filename' => $file->getClientOriginalName(),
'type' => 'image',
'path' => "uploads/events/" . $idEvent . "/uploadParticipantsFiles/",
'user' => $userId,
'dbEntry' => 0
);
if ($file->getClientSize() > 33554432) {
$error = "File size is too big (> 32MB)";
}
$mimetypes = array(
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel'
);
if (!in_array($file->getClientMimetype(), $mimetypes)) {
$error = "Not an excel file. Please save the file in microsoft Excel format and upload again.";
}
$file = $filedata['path'] . $filedata['filename'];
$types = array('Xlsx', 'Xls');
if ($error == '') {
$this->uploadFile($filedata);
$importFile = new EventParticipantImportFiles();
$importFile->setIdEvent($idEvent);
$importFile->setFilename($filedata['filename']);
$importFile->setPath($filedata['path']);
$importFile->setUploadedBy($userId);
$importFile->setUploadedAt(new DateTime());
$em->persist($importFile);
$em->flush();
$idfile = $importFile->getId();
foreach ($types as $type) {
try {
$reader = IOFactory::createReader($type);
} catch (Exception $e) {
$error = "File cannot be read.";
}
if ($reader->canRead($file)) {
break;
} else {
$error = "Not an excel file. Please save the file in microsoft Excel format and upload again.";
}
}
if (file_exists($file)) {
$objPHPExcel = IOFactory::load($file);
foreach ($objPHPExcel->getWorksheetIterator() as $sheet) {
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
if ($highestRow > 1) {
if ($highestColumn == "W") {
$headings = $sheet->rangeToArray('A2:' . $highestColumn . 2,
NULL,
TRUE,
FALSE)[0];
for ($row = 2; $row <= $highestRow; $row++) {
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE)[0];
$eventParticipant = new EventParticipantUpload();
$eventParticipant->setEmail($rowData[0]);
$eventParticipant->setFname($this->makeTitle($rowData[1]));
$eventParticipant->setSname(strtoupper($rowData[2]));
$eventParticipant->setGender($this->makeTitle($rowData[3]));
$eventParticipant->setNationality($this->makeTitle($rowData[4]));
$eventParticipant->setPhone($rowData[5]);
$eventParticipant->setAddressLine1($this->makeTitle($rowData[6]));
$eventParticipant->setAddressLine2($this->makeTitle($rowData[7]));
$eventParticipant->setCity($this->makeTitle($rowData[8]));
$eventParticipant->setState($this->makeTitle($rowData[9]));
$eventParticipant->setZipCode($rowData[10]);
$eventParticipant->setCountry($this->makeTitle($rowData[11]));
$eventParticipant->setInstitution($this->makeTitle($rowData[12]));
$eventParticipant->setInstAddrLine1($this->makeTitle($rowData[13]));
$eventParticipant->setInstAddrLine2($this->makeTitle($rowData[14]));
$eventParticipant->setInstCity($this->makeTitle($rowData[15]));
$eventParticipant->setInstState($this->makeTitle($rowData[16]));
$eventParticipant->setInstZipCode($rowData[17]);
$eventParticipant->setInstCountry($this->makeTitle($rowData[18]));
$eventParticipant->setInstEmail($rowData[19]);
$eventParticipant->setJobTitle(ucfirst($rowData[20]));
$eventParticipant->setJobDescription(ucfirst($rowData[21]));
$eventParticipant->setoceanexpertProfile($rowData[22]);
$eventParticipant->setIdFile($idfile);
$em->persist($eventParticipant);
$em->flush();
}
} else {
$error = "Invalid column count in the file. The number of columns should be 23.";
unlink($file);
if ($importFile) {
$em->remove($importFile);
$em->flush();
}
}
} else {
$error = "No import data present in the file.";
unlink($file);
if ($importFile) {
$em->remove($importFile);
$em->flush();
}
}
}
}
if ($error == '') {
return $this->redirect(
$this->generateUrl(
'import_event_participants',
array(
'idEvent' => $idEvent,
'idFile' => $idfile
)
)
);
} else {
return $this->render(
'Event/importEventParticipants.html.twig',
array(
'data' => array(
'event' => $eventDetails,
'participants' => $eventParticipants,
'idFile' => $idfile,
'importFile' => $importFile,
'fileerror' => $error
)
)
);
}
}
}
return $this->render(
'Event/importEventParticipants.html.twig',
array(
'data' => array(
'event' => $eventDetails,
'participants' => $eventParticipants,
'idFile' => $idfile,
'importFile' => $importFile,
'fileerror' => $error
)
)
);
}
/**
* @param $idFile
*
* @return object[]
*/
function getImportdata($idFile)
{
$em = $this->getDoctrine()->getManager();
$expertdata = $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findBy(array('idFile' => $idFile));
foreach ($expertdata as $expert) {
$expertdetails = $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('email1' => $expert->getEmail()));
if ($expertdetails) {
$expert->setStatus(1);
$expert->setIdProfile($expertdetails->getIdInd());
$expert->setOceanexpertProfile($this->generateUrl('view_profile', array('user' => $expertdetails->getIdInd())));
$em->persist($expert);
$em->flush();
} else {
if ($expert->getoceanexpertProfile() != '') {
if (strpos($expert->getoceanexpertProfile(), '/expert/') !== false) {
$urlparts = explode('/', $expert->getoceanexpertProfile());
$expertpart = end($urlparts);
} elseif (strpos($expert->getoceanexpertProfile(), 'viewMemberRecord') !== false) {
$urlparts = explode('=', $expert->getoceanexpertProfile());
$expertpart = end($urlparts);
}
if (isset($expertpart)
&& is_numeric($expertpart)
) {
$user = $this->fosUserManager->findUserBy(array('id' => $expertpart));
if ($user) {
$expertdetails = $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $user->getId()));
} else {
$expert->setStatus(0);
$expert->setIdProfile('');
}
} else {
$expertdetails = $em->getRepository('OceanExpertBundle:Indiv')->findOneBy(array('idInd' => $expertpart));
}
if ($expertdetails) {
$expert->setStatus(1);
$expert->setIdProfile($expertdetails->getIdInd());
$expert->setOceanexpertProfile($this->generateUrl('view_profile', array('user' => $expertdetails->getIdInd())));
} else {
$expert->setStatus(0);
$expert->setIdProfile('');
}
} else {
$expert->setStatus(0);
$expert->setIdProfile('');
}
$em->persist($expert);
$em->flush();
}
}
return $expertdata;
}
/**
* @param $title
* @return string
*/
function makeTitle($title)
{
$str = ucwords(strtolower($title));
$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';
$excluded = explode(",", $exclude);
foreach ($excluded as $noCap) {
$str = str_replace(ucwords($noCap), strtolower($noCap), $str);
}
return ucfirst($str);
}
/**
* change some info about the participant
* TBC this is only used when importing event participants
*
* @param $idEvent
* @param $idUser
* @param Request $request
* @return Response
*/
public function editParticipantAction($idEvent, $idUser, Request $request)
{
$em = $this->getDoctrine()->getManager();
$countries = $this->getDoctrine()
->getRepository('OceanExpertBundle:Countries')
->createQueryBuilder('c')
->select('c.idCountry, c.country,c.countryCode')
->orderBy('c.country', 'asc')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($countries as $country) {
$countryArr[$country['idCountry']] = $country['country'];
}
$userInstitute = array();
$instituteSeaRegion = $this->getDoctrine()->getRepository('OceanExpertBundle:Regions')->seaRegions();
$user = $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findOneBy(array('id' => $idUser));
if ($user) {
$user->setCountry(array_search($user->getCountry(), $countryArr));
$user->setNationality(array_search($user->getNationality(), $countryArr));
$user->setInstCountry(array_search($user->getInstCountry(), $countryArr));
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT i.id_inst, i.inst_name, i.inst_address, i.city, i.state, i.postcode FROM institutions i
WHERE ( i.inst_name = :instName
AND i.country_code = :country
AND i.activated = 1
)
");
$statement->bindValue('instName', $user->getInstitution());
$statement->bindValue('country', $user->getInstCountry());
$statement->execute();
$userInstitute = $statement->fetchAll();
if (count($userInstitute) == 0) {
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT i.id_inst, i.inst_name, i.inst_address, i.city, i.state, i.postcode FROM institutions i
WHERE ( MATCH (i.inst_name) AGAINST (:instName)
AND i.country_code = :country
AND i.activated = 1
)
");
$statement->bindValue('instName', $user->getInstitution());
$statement->bindValue('country', $user->getInstCountry());
$statement->execute();
$userInstitute = $statement->fetchAll();
}
}
return $this->render(
'Event/editParticipants.html.twig',
array(
'data' => array(
'user' => $user,
'idUser' => $idUser,
'idEvent' => $idEvent,
'userInstitute' => $userInstitute,
'countries' => $countries,
'availableSeaRegions' => $instituteSeaRegion
)
)
);
}
/**
* @param $code
* @return string
*/
public function getCountryByCode($code)
{
$em = $this->getDoctrine()->getManager();
$product = $em->getRepository('OceanExpertBundle:Countries')->find($code);
return $product->getCountry();
}
/**
* @param Request $request
* @return Response
*/
public function deleteImportParticipantAction(Request $request)
{
$idParticipant = $request->request->get('idParticipant');
$em = $this->getDoctrine()->getManager();
$participant = $em->getRepository('OceanExpertBundle:EventParticipantUpload')->findOneBy(array('id' => $idParticipant));
if ($participant) {
$em->remove($participant);
$em->flush();
return new Response(1);
} else {
return new Response(0);
}
}
/**
* @param Request $request
* @return Response
*/
public function checkParticipantsDetailAction(Request $request)
{
$idFile = $request->request->get('idfile');
$invalidProfile = $this->checkParticipants($idFile);
if (count($invalidProfile) > 0) {
$data = array(
'status' => 0,
'participants' => $invalidProfile
);
} else {
$data = array(
'status' => 1,
'participants' => array()
);
}
return new JsonResponse($data);
}
/**
* @param $idFile
* @return mixed
*/
function checkParticipants($idFile)
{
$em = $this->getDoctrine()->getManager();
$invalidProfile = $em->getRepository('OceanExpertBundle:EventParticipantUpload')
->createQueryBuilder('ep')
->select('ep.idProfile, ep.fname, ep.sname, ep.email')
->where('ep.idProfile is NULL')
->orWhere('ep.idProfile = 0')
->andWhere('ep.idFile = :idfile')
->setParameter('idfile', $idFile)
->orderBy('ep.sname', 'ASC')
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
return $invalidProfile;
}
/**
* Function to check and add event participant
* @param Request $request
* @return Response
*/
public function addEventParticipantsAction(Request $request)
{
$idFile = $request->request->get('idfile');
$idEvent = $request->request->get('idevent');
$em = $this->getDoctrine()->getManager();
$invalidProfile = $this->checkParticipants($idFile);
if (count($invalidProfile) == 0) {
$participants = $em->getRepository('OceanExpertBundle:EventParticipantUpload')
->createQueryBuilder('ep')
->select('ep.idProfile,ep.phone')
->where('ep.idProfile is not NULL')
->orWhere('ep.idProfile != 0')
->andWhere('ep.idFile = :idfile')
->setParameter('idfile', $idFile)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($participants as $participant) {
$eventparticipant = $em->getRepository('OceanExpertBundle:EventParticipants')
->findOneBy(
array(
'idInd' => $participant['idProfile'],
'idEvent' => $idEvent
)
);
if (!$eventparticipant) {
$eventparticipant = new EventParticipants();
$eventparticipant->setStatus(1);
$eventparticipant->setIdEvent($idEvent);
$eventparticipant->setIdInd($participant['idProfile']);
$eventparticipant->setContactTel($participant['phone']);
$em->persist($eventparticipant);
$em->flush();
}
$removeParticipantData = $em->getRepository("OceanExpertBundle:EventParticipantUpload")
->findOneBy(
array(
'idProfile' => $eventparticipant->getIdInd()
)
);
$em->remove($removeParticipantData);
$em->flush();
$importfile = $em->getRepository('OceanExpertBundle:EventParticipantImportFiles')
->findOneBy(
array(
'id' => $idFile
)
);
if ($importfile) {
unlink($importfile->getPath() . $importfile->getFilename());
$em->remove($importfile);
$em->flush();
}
}
}
return new Response(1);
}
/**
* create ICS file to download
* this file should contain all info about an event
*
* @param int $idEvent id of the event
*
* @return Response
*/
public function getIcsAction($idEvent)
{
//https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20220112T000000Z%2F20220112T235959Z&details=thisAreTheDetails&location=&text=thisIsTheTitle
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('OceanExpertBundle:Events')
->findOneBy(
array(
'idEvent' => $idEvent
)
);
/*
Convert times to iCalendar format.
They require a block for 'Ymd' and then another block for the time, with format 'his'.
Both of those blocks are separated by a "T".
The Z is declared at the end for UTC time, but shouldn't be included in the date conversion.
*/
//we cannot set a time in OE for events
//$event->setStartOn($event->getStartOn()->format('Ymd\This') . 'Z');
//$event->setEndOn($event->getEndOn()->format('Ymd\This') . 'Z');
$event->setStartOn($event->getStartOn()->format('Ymd\T') . '000001Z');
$event->setEndOn($event->getEndOn()->format('Ymd\This') . '235959Z');
//get rid of any formatting we may have added
$event->setTitle(strip_tags($event->getEventTitle()));
$event->setShortTitle(strip_tags($event->getEventShortTitle()));
$response = $this->render(
'Event/getIcs.html.twig',
array(
'url' => $this->generateUrl(
'view_event',
array(
'event' => $event->getIdEvent()
),
UrlGenerator::ABSOLUTE_URL
),
'event' => $event
)
);
$response->headers->set(
'Content-Type',
'text/calendar; charset=utf-8'
);
$response->headers->set(
'Content-Disposition',
'attachment; filename="OceanExpertEvent_' . $idEvent . '_' . date('Ymd') . '.ics"'
);
return $response;
}
}