public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('title', 'text', array('label' => 'Title', 'required' => false, 'max_length' => VARCHAR_COLUMN_LENGTH_USED));
     $builder->add('url', 'url', array('label' => 'URL', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED));
     $builder->add("is_manual_events_creation", "checkbox", array('required' => false, 'label' => 'Do you want to create events manually from this import?'));
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $countries = array();
     $defaultCountry = null;
     foreach ($crb->fetchAll() as $country) {
         $countries[$country->getId()] = $country->getTitle();
         if ($defaultCountry == null && in_array($this->timeZoneName, $country->getTimezonesAsList())) {
             $defaultCountry = $country->getId();
         }
     }
     // TODO if current country not in list add it now
     $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true, 'data' => $defaultCountry));
     /** @var \closure $myExtraFieldValidator **/
     $myExtraFieldValidator = function (FormEvent $event) {
         global $CONFIG;
         $form = $event->getForm();
         // URL validation. We really can't do much except verify ppl haven't put a space in, which they might do if they just type in Google search terms (seen it done)
         if (strpos($form->get("url")->getData(), " ") !== false) {
             $form['url']->addError(new FormError("Please enter a URL"));
         }
     };
     // adding the validator to the FormBuilderInterface
     $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $countries = array();
     foreach ($crb->fetchAll() as $country) {
         $countries[$country->getId()] = $country->getTitle();
     }
     // TODO if current country not in list add it now
     $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true));
     $timezones = array();
     // Must explicetly set name as key otherwise Symfony forms puts an ID in, and that's no good for processing outside form
     foreach ($this->site->getCachedTimezonesAsList() as $timezone) {
         $timezones[$timezone] = $timezone;
     }
     // TODO if current timezone not in list add it now
     $builder->add('timezone', 'choice', array('label' => 'Time Zone', 'choices' => $timezones, 'required' => true));
     if ($this->site->getIsFeatureVirtualEvents()) {
         // if both are an option, user must check which one.
         if ($this->site->getIsFeaturePhysicalEvents()) {
             $builder->add("is_virtual", "checkbox", array('required' => false, 'label' => 'Is event accessible online?'));
         }
     }
     if ($this->site->getIsFeaturePhysicalEvents()) {
         // if both are an option, user must check which one.
         if ($this->site->getIsFeatureVirtualEvents()) {
             $builder->add("is_physical", "checkbox", array('required' => false, 'label' => 'Does the event happen at a place?'));
         }
     }
 }
 function index(Application $app)
 {
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($app['currentSite']);
     $countries = $crb->fetchAll();
     return $app['twig']->render('site/countrylist/index.html.twig', array('countries' => $countries));
 }
 public function listJson(Request $request, Application $app)
 {
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($app['currentSite']);
     $out = array('countries' => array());
     foreach ($crb->fetchAll() as $country) {
         $out['countries'][] = array('slug' => $country->getTwoCharCode(), 'title' => $country->getTitle());
     }
     return json_encode($out);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('title', 'text', array('label' => 'Title', 'required' => false, 'max_length' => VARCHAR_COLUMN_LENGTH_USED));
     $builder->add("is_manual_events_creation", "checkbox", array('required' => false, 'label' => 'Do you want to create events manually from this import?'));
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $countries = array();
     foreach ($crb->fetchAll() as $country) {
         $countries[$country->getId()] = $country->getTitle();
     }
     // TODO if current country not in list add it now
     $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->add('title', 'text', array('label' => 'Title', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus')));
     $builder->add('description', 'textarea', array('label' => 'Description', 'required' => false));
     $builder->add('address', 'textarea', array('label' => 'Address', 'required' => false));
     // TODO use proper label for country
     $builder->add('address_code', 'text', array('label' => 'Postcode', 'required' => false));
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $countries = array();
     foreach ($crb->fetchAll() as $country) {
         $countries[$country->getId()] = $country->getTitle();
     }
     // TODO if current country not in list add it now
     $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true));
     $builder->add('lat', 'hidden', array());
     $builder->add('lng', 'hidden', array());
 }
 protected function run()
 {
     $siteRepository = new SiteRepository();
     $eventCustomFieldsRepo = new EventCustomFieldDefinitionRepository();
     $siteRepositoryBuilder = new SiteRepositoryBuilder();
     $count = 0;
     foreach ($siteRepositoryBuilder->fetchAll() as $site) {
         $crb = new CountryRepositoryBuilder();
         $crb->setSiteIn($site);
         $countries = $crb->fetchAll();
         $timezones = array();
         foreach ($countries as $country) {
             foreach (explode(",", $country->getTimezones()) as $timeZone) {
                 $timezones[] = $timeZone;
             }
         }
         $site->setCachedTimezonesAsList($timezones);
         $site->setCachedIsMultipleCountries(count($countries) > 1);
         $siteRepository->editCached($site);
         $eventCustomFieldsRepo->updateSiteCache($site);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 function listCountries($siteid, Request $request, Application $app)
 {
     $this->build($siteid, $request, $app);
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->parameters['site']);
     $this->parameters['countries'] = $crb->fetchAll();
     return $app['twig']->render('sysadmin/site/countries.html.twig', $this->parameters);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $this->defaultCountry = null;
     $defaultCountryID = null;
     $countries = $crb->fetchAll();
     if (count($countries) > 1) {
         $countriesForSelect = array();
         foreach ($countries as $country) {
             $countriesForSelect[$country->getId()] = $country->getTitle();
             if ($this->defaultCountry == null && in_array($this->timeZoneName, $country->getTimezonesAsList())) {
                 $this->defaultCountry = $country;
                 $defaultCountryID = $country->getId();
             }
         }
         $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countriesForSelect, 'required' => true, 'data' => $defaultCountryID));
     } else {
         if (count($countries) == 1) {
             $this->defaultCountry = $countries[0];
             $builder->add('country_id', 'hidden', array('data' => $this->defaultCountry->getId()));
         }
     }
     $timezones = array();
     // Must explicetly set name as key otherwise Symfony forms puts an ID in, and that's no good for processing outside form
     foreach ($this->site->getCachedTimezonesAsList() as $timezone) {
         $timezones[$timezone] = $timezone;
     }
     if (count($timezones) != 1) {
         $builder->add('timezone', 'choice', array('label' => 'Time Zone', 'choices' => $timezones, 'required' => true));
     } else {
         $timezone = array_pop($timezones);
         $builder->add('timezone', 'hidden', array('data' => $timezone));
     }
     $years = array(date('Y'), date('Y') + 1);
     $data = null;
     if ($this->eventDraft->hasDetailsValue('event.start_at')) {
         $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_at');
     } else {
         if ($this->eventDraft->hasDetailsValue('event.start_end_freetext.start')) {
             $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_end_freetext.start');
         } else {
             if ($this->eventDraft->hasDetailsValue('incoming.event.start_at')) {
                 $data = $this->eventDraft->getDetailsValueAsDateTime('incoming.event.start_at');
             }
         }
     }
     $startOptions = array('label' => 'Start', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true, 'data' => $data);
     if ($this->formWidgetTimeMinutesMultiples > 1) {
         $startOptions['minutes'] = array();
         for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) {
             $startOptions['minutes'][] = $i;
         }
     }
     $builder->add('start_at', 'datetime', $startOptions);
     $data = null;
     if ($this->eventDraft->hasDetailsValue('event.end_at')) {
         $data = $this->eventDraft->getDetailsValueAsDateTime('event.end_at');
     } else {
         if ($this->eventDraft->hasDetailsValue('event.start_end_freetext.end')) {
             $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_end_freetext.end');
         } else {
             if ($this->eventDraft->hasDetailsValue('incoming.event.end_at')) {
                 $data = $this->eventDraft->getDetailsValueAsDateTime('incoming.event.end_at');
             }
         }
     }
     $endOptions = array('label' => 'End', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true, 'data' => $data);
     if ($this->formWidgetTimeMinutesMultiples > 1) {
         $endOptions['minutes'] = array();
         for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) {
             $endOptions['minutes'][] = $i;
         }
     }
     $builder->add('end_at', 'datetime', $endOptions);
     /** @var \closure $myExtraFieldValidator **/
     $myExtraFieldValidator = function (FormEvent $event) {
         global $CONFIG;
         $form = $event->getForm();
         $myExtraFieldStart = $form->get('start_at')->getData();
         $myExtraFieldEnd = $form->get('end_at')->getData();
         // Validate end is after start?
         if ($myExtraFieldStart > $myExtraFieldEnd) {
             $form['start_at']->addError(new FormError("The start can not be after the end!"));
         }
         // validate not to far in future
         $max = \TimeSource::getDateTime();
         $max->add(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInFuture . "Y"));
         if ($myExtraFieldStart > $max) {
             $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future."));
         }
         if ($myExtraFieldEnd > $max) {
             $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future."));
         }
         // validate not to far in past
         $min = \TimeSource::getDateTime();
         $min->sub(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInPast . "Y"));
         if ($myExtraFieldStart < $min) {
             $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past."));
         }
         if ($myExtraFieldEnd < $min) {
             $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past."));
         }
     };
     // adding the validator to the FormBuilderInterface
     $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->add('summary', 'text', array('label' => 'Summary', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus')));
     $builder->add('description', 'textarea', array('label' => 'Description', 'required' => false));
     $builder->add('url', new \symfony\form\MagicUrlType(), array('label' => 'Information Web Page URL', 'required' => false));
     $builder->add('ticket_url', new \symfony\form\MagicUrlType(), array('label' => 'Tickets Web Page URL', 'required' => false));
     $crb = new CountryRepositoryBuilder();
     $crb->setSiteIn($this->site);
     $countries = array();
     $defaultCountry = null;
     foreach ($crb->fetchAll() as $country) {
         $countries[$country->getId()] = $country->getTitle();
         if ($defaultCountry == null && in_array($this->timeZoneName, $country->getTimezonesAsList())) {
             $defaultCountry = $country->getId();
         }
     }
     if (count($countries) != 1) {
         $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true, 'data' => $defaultCountry));
     } else {
         $countryID = array_shift(array_keys($countries));
         $builder->add('country_id', 'hidden', array('data' => $countryID));
     }
     $timezones = array();
     // Must explicetly set name as key otherwise Symfony forms puts an ID in, and that's no good for processing outside form
     foreach ($this->site->getCachedTimezonesAsList() as $timezone) {
         $timezones[$timezone] = $timezone;
     }
     if (count($timezones) != 1) {
         $builder->add('timezone', 'choice', array('label' => 'Time Zone', 'choices' => $timezones, 'required' => true));
     } else {
         $timezone = array_pop($timezones);
         $builder->add('timezone', 'hidden', array('data' => $timezone));
     }
     if ($this->site->getIsFeatureVirtualEvents()) {
         //  if both are an option, user must check which one.
         if ($this->site->getIsFeaturePhysicalEvents()) {
             $builder->add("is_virtual", "checkbox", array('required' => false, 'label' => 'Is event accessible online?'));
         }
     }
     if ($this->site->getIsFeaturePhysicalEvents()) {
         //  if both are an option, user must check which one.
         if ($this->site->getIsFeatureVirtualEvents()) {
             $builder->add("is_physical", "checkbox", array('required' => false, 'label' => 'Does the event happen at a place?'));
         }
     }
     $years = array(date('Y'), date('Y') + 1);
     $startOptions = array('label' => 'Start', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true);
     if ($this->formWidgetTimeMinutesMultiples > 1) {
         $startOptions['minutes'] = array();
         for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) {
             $startOptions['minutes'][] = $i;
         }
     }
     $builder->add('start_at', 'datetime', $startOptions);
     $endOptions = array('label' => 'End', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true);
     if ($this->formWidgetTimeMinutesMultiples > 1) {
         $endOptions['minutes'] = array();
         for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) {
             $endOptions['minutes'][] = $i;
         }
     }
     $builder->add('end_at', 'datetime', $endOptions);
     $this->customFields = array();
     foreach ($this->site->getCachedEventCustomFieldDefinitionsAsModels() as $customField) {
         if ($customField->getIsActive()) {
             $extension = $this->extensionManager->getExtensionById($customField->getExtensionId());
             if ($extension) {
                 $fieldType = $extension->getEventCustomFieldByType($customField->getType());
                 if ($fieldType) {
                     $this->customFields[] = $customField;
                     $options = $fieldType->getSymfonyFormOptions($customField);
                     $options['mapped'] = false;
                     $options['data'] = $builder->getData()->getCustomField($customField);
                     $builder->add('custom_' . $customField->getKey(), $fieldType->getSymfonyFormType($customField), $options);
                 }
             }
         }
     }
     /** @var \closure $myExtraFieldValidator **/
     $myExtraFieldValidator = function (FormEvent $event) {
         global $CONFIG;
         $form = $event->getForm();
         $myExtraFieldStart = $form->get('start_at')->getData();
         $myExtraFieldEnd = $form->get('end_at')->getData();
         // Validate end is after start?
         if ($myExtraFieldStart > $myExtraFieldEnd) {
             $form['start_at']->addError(new FormError("The start can not be after the end!"));
         }
         // validate not to far in future
         $max = \TimeSource::getDateTime();
         $max->add(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInFuture . "Y"));
         if ($myExtraFieldStart > $max) {
             $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future."));
         }
         if ($myExtraFieldEnd > $max) {
             $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future."));
         }
         // validate not to far in past
         $min = \TimeSource::getDateTime();
         $min->sub(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInPast . "Y"));
         if ($myExtraFieldStart < $min) {
             $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past."));
         }
         if ($myExtraFieldEnd < $min) {
             $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past."));
         }
         // URL validation. We really can't do much except verify ppl haven't put a space in, which they might do if they just type in Google search terms (seen it done)
         if (strpos($form->get("url")->getData(), " ") !== false) {
             $form['url']->addError(new FormError("Please enter a URL"));
         }
         if (strpos($form->get("ticket_url")->getData(), " ") !== false) {
             $form['ticket_url']->addError(new FormError("Please enter a URL"));
         }
     };
     // adding the validator to the FormBuilderInterface
     $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator);
 }