<?php
namespace App\Twig;
use App\Entity\InternalEvent;
use App\Entity\InternalEventRegistrationAttendance;
use App\Entity\MainEvent;
use App\Entity\Organisation;
use App\Entity\OrganisationMember;
use App\Entity\Person;
use App\Processor\InternalEventRegistrationAttendanceProcessor;
use App\Processor\InternalEventRegistrationProcessor;
use App\Processor\MainEventProcessor;
/**
* NOTE: no business logic here. Just use another service.
*
* Class RegistrationFormExtension
* @package App\Twig
*/
class RegistrationFormExtension extends \Twig_Extension
{
private $mainEventProcessor;
private $internalEventRegistrationProcessor;
private $internalEventRegistrationAttendanceProcessor;
public function __construct(
MainEventProcessor $mainEventProcessor,
InternalEventRegistrationProcessor $internalEventRegistrationProcessor,
InternalEventRegistrationAttendanceProcessor $internalEventRegistrationAttendanceProcessor
) {
$this->mainEventProcessor = $mainEventProcessor;
$this->internalEventRegistrationProcessor = $internalEventRegistrationProcessor;
$this->internalEventRegistrationAttendanceProcessor = $internalEventRegistrationAttendanceProcessor;
}
/**
* A function is used when you need to use the inputs to compute another result.
* For example, the {{ dump(username) }} function which will call internally the var_dump php function.
*/
public function getFunctions()
{
return [
new \Twig_Function('can_attend_main_event', array($this, 'canAttendMainEvent')),
new \Twig_Function('is_representative_event', array($this, 'isRepresentativeEvent')),
new \Twig_Function('is_proxy_allowed', array($this, 'isProxyAllowed')),
new \Twig_Function('is_guest_allowed', array($this, 'isGuestAllowed')),
new \Twig_Function('is_registered_in_event', array($this, 'isRegisteredInEvent')),
new \Twig_Function('is_industry_council_event', array($this, 'IsIndustryCouncilEvent')),
];
}
/**
* A filter is a way to transform the displayed data.
* For example if you want to display the content of a date "1991-01-01" to "January 1, 1991",
* you'll have to write a filter (example : {{ username|to_words }})
*/
public function getFilters()
{
return [
// new \Twig_SimpleFilter('as_hermetic_string', array($this, 'asHermeticString')),
];
}
/**
* @param Organisation $organisation
* @param MainEvent $mainEvent
* @return bool
*/
public function canAttendMainEvent(Organisation $organisation, MainEvent $mainEvent)
{
return $this->mainEventProcessor->canAttendMainEvent($organisation, $mainEvent);
}
/**
* @deprecated Use the one in the model.
* @param int $type
* @return bool
*/
public function isRepresentativeEvent(int $type)
{
return $this->internalEventRegistrationProcessor->isRepresentativeEvent($type);
}
/**
* @deprecated Use the one in the model.
* @param int $type
* @return bool
*/
public function isProxyAllowed(int $type)
{
return $this->internalEventRegistrationProcessor->isProxyAllowed($type);
}
/**
* @deprecated Use the one in the model.
* @param int $type
* @return bool
*/
public function isGuestAllowed(int $type)
{
return $this->internalEventRegistrationProcessor->isGuestAllowed($type);
}
/**
* @param OrganisationMember $member
* @param InternalEvent $internalEvent
* @return bool
*/
public function isRegisteredInEvent(OrganisationMember $member, InternalEvent $internalEvent)
{
return $this->internalEventRegistrationAttendanceProcessor->isRegisteredInEvent($member, $internalEvent);
}
// public function asHermeticString($id)
// {
// return array_search ($id, CircuitFormType::HERMETIC_CHOICES);
// }
/**
* @param InternalEvent $internalEvent
* @param Person $person
* @return bool
*/
public function IsIndustryCouncilEvent(InternalEvent $internalEvent, Person $person)
{
if($internalEvent->getType() === InternalEvent::TYPE_INDUSTRY_COUNCIL && $person->isIcrepresentative()){
return true;
}else{
return false;
}
}
}