src/Twig/RegistrationFormExtension.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use App\Entity\InternalEvent;
  4. use App\Entity\InternalEventRegistrationAttendance;
  5. use App\Entity\MainEvent;
  6. use App\Entity\Organisation;
  7. use App\Entity\OrganisationMember;
  8. use App\Entity\Person;
  9. use App\Processor\InternalEventRegistrationAttendanceProcessor;
  10. use App\Processor\InternalEventRegistrationProcessor;
  11. use App\Processor\MainEventProcessor;
  12. /**
  13.  * NOTE: no business logic here. Just use another service.
  14.  *
  15.  * Class RegistrationFormExtension
  16.  * @package App\Twig
  17.  */
  18. class RegistrationFormExtension extends \Twig_Extension
  19. {
  20.     private $mainEventProcessor;
  21.     private $internalEventRegistrationProcessor;
  22.     private $internalEventRegistrationAttendanceProcessor;
  23.     public function __construct(
  24.         MainEventProcessor $mainEventProcessor,
  25.         InternalEventRegistrationProcessor $internalEventRegistrationProcessor,
  26.         InternalEventRegistrationAttendanceProcessor $internalEventRegistrationAttendanceProcessor
  27.     ) {
  28.         $this->mainEventProcessor $mainEventProcessor;
  29.         $this->internalEventRegistrationProcessor $internalEventRegistrationProcessor;
  30.         $this->internalEventRegistrationAttendanceProcessor $internalEventRegistrationAttendanceProcessor;
  31.     }
  32.     /**
  33.      * A function is used when you need to use the inputs to compute another result.
  34.      * For example, the {{ dump(username) }} function which will call internally the var_dump php function.
  35.      */
  36.     public function getFunctions()
  37.     {
  38.         return [
  39.             new \Twig_Function('can_attend_main_event', array($this'canAttendMainEvent')),
  40.             new \Twig_Function('is_representative_event', array($this'isRepresentativeEvent')),
  41.             new \Twig_Function('is_proxy_allowed', array($this'isProxyAllowed')),
  42.             new \Twig_Function('is_guest_allowed', array($this'isGuestAllowed')),
  43.             new \Twig_Function('is_registered_in_event', array($this'isRegisteredInEvent')),
  44.             new \Twig_Function('is_industry_council_event', array($this'IsIndustryCouncilEvent')),
  45.         ];
  46.     }
  47.     /**
  48.      * A filter is a way to transform the displayed data.
  49.      * For example if you want to display the content of a date "1991-01-01" to "January 1, 1991",
  50.      * you'll have to write a filter (example : {{ username|to_words }})
  51.      */
  52.     public function getFilters()
  53.     {
  54.         return [
  55. //            new \Twig_SimpleFilter('as_hermetic_string', array($this, 'asHermeticString')),
  56.         ];
  57.     }
  58.     /**
  59.      * @param Organisation $organisation
  60.      * @param MainEvent $mainEvent
  61.      * @return bool
  62.      */
  63.     public function canAttendMainEvent(Organisation $organisationMainEvent $mainEvent)
  64.     {
  65.         return $this->mainEventProcessor->canAttendMainEvent($organisation$mainEvent);
  66.     }
  67.     /**
  68.      * @deprecated Use the one in the model.
  69.      * @param int $type
  70.      * @return bool
  71.      */
  72.     public function isRepresentativeEvent(int $type)
  73.     {
  74.         return $this->internalEventRegistrationProcessor->isRepresentativeEvent($type);
  75.     }
  76.     /**
  77.      * @deprecated Use the one in the model.
  78.      * @param int $type
  79.      * @return bool
  80.      */
  81.     public function isProxyAllowed(int $type)
  82.     {
  83.         return $this->internalEventRegistrationProcessor->isProxyAllowed($type);
  84.     }
  85.     /**
  86.      * @deprecated Use the one in the model.
  87.      * @param int $type
  88.      * @return bool
  89.      */
  90.     public function isGuestAllowed(int $type)
  91.     {
  92.         return $this->internalEventRegistrationProcessor->isGuestAllowed($type);
  93.     }
  94.     /**
  95.      * @param OrganisationMember $member
  96.      * @param InternalEvent $internalEvent
  97.      * @return bool
  98.      */
  99.     public function isRegisteredInEvent(OrganisationMember $memberInternalEvent $internalEvent)
  100.     {
  101.         return $this->internalEventRegistrationAttendanceProcessor->isRegisteredInEvent($member$internalEvent);
  102.     }
  103. //    public function asHermeticString($id)
  104. //    {
  105. //        return array_search ($id, CircuitFormType::HERMETIC_CHOICES);
  106. //    }
  107.     /**
  108.      * @param InternalEvent $internalEvent
  109.      * @param Person $person
  110.      * @return bool
  111.      */
  112.     public function IsIndustryCouncilEvent(InternalEvent $internalEventPerson $person)
  113.     {
  114.         if($internalEvent->getType() === InternalEvent::TYPE_INDUSTRY_COUNCIL && $person->isIcrepresentative()){
  115.             return true;
  116.         }else{
  117.             return false;
  118.         }
  119.     }
  120. }