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?'));
         }
     }
 }
 public function create(SiteModel $site, UserAccountModel $owner, $countries, SiteQuotaModel $siteQuota, $canAnyUserVerifiedEdit = false)
 {
     global $DB, $CONFIG, $EXTENSIONHOOKRUNNER;
     $createdat = \TimeSource::getFormattedForDataBase();
     if (!$site->isSlugValid($site->getSlug(), $CONFIG)) {
         throw new Exception("Slug not valid");
     }
     try {
         $DB->beginTransaction();
         // TODO should check slug not already exist and nice error
         $timezones = array();
         foreach ($countries as $country) {
             foreach (explode(",", $country->getTimezones()) as $timeZone) {
                 $timezones[] = $timeZone;
             }
         }
         $site->setCachedTimezonesAsList($timezones);
         $site->setCachedIsMultipleCountries(count($countries) > 1);
         // Site
         $stat = $DB->prepare("INSERT INTO site_information (title, slug, slug_canonical, " . "created_at,cached_is_multiple_timezones,cached_is_multiple_countries," . "cached_timezones,is_feature_map,is_feature_importer,is_feature_curated_list," . "is_listed_in_index,is_web_robots_allowed, " . " prompt_emails_days_in_advance,site_quota_id, " . "is_feature_tag,is_feature_physical_events,is_feature_virtual_events) " . "VALUES (:title, :slug, :slug_canonical, " . " :created_at,:cached_is_multiple_timezones,:cached_is_multiple_countries," . ":cached_timezones,:is_feature_map,:is_feature_importer,:is_feature_curated_list," . ":is_listed_in_index,:is_web_robots_allowed, " . " :prompt_emails_days_in_advance, :site_quota_id, " . ":is_feature_tag,:is_feature_physical_events,:is_feature_virtual_events) RETURNING id");
         $stat->execute(array('title' => substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'slug' => $site->getSlug(), 'slug_canonical' => SiteModel::makeCanonicalSlug($site->getSlug()), 'cached_is_multiple_timezones' => $site->getCachedIsMultipleTimezones() ? 1 : 0, 'cached_is_multiple_countries' => $site->getCachedIsMultipleCountries() ? 1 : 0, 'cached_timezones' => $site->getCachedTimezones(), 'created_at' => $createdat, 'is_feature_curated_list' => $site->getIsFeatureCuratedList() ? 1 : 0, 'is_feature_importer' => $site->getIsFeatureImporter() ? 1 : 0, 'is_feature_map' => $site->getIsFeatureMap() ? 1 : 0, 'is_feature_tag' => $site->getIsFeatureTag() ? 1 : 0, 'is_feature_virtual_events' => $site->getIsFeatureVirtualEvents() ? 1 : 0, 'is_feature_physical_events' => $site->getIsFeaturePhysicalEvents() ? 1 : 0, 'is_listed_in_index' => $site->getIsListedInIndex() ? 1 : 0, 'is_web_robots_allowed' => $site->getIsWebRobotsAllowed() ? 1 : 0, 'prompt_emails_days_in_advance' => $site->getPromptEmailsDaysInAdvance(), 'site_quota_id' => $siteQuota->getId()));
         $data = $stat->fetch();
         $site->setId($data['id']);
         $stat = $DB->prepare("INSERT INTO site_history (site_id, user_account_id, " . "title, slug, slug_canonical, created_at,is_feature_map,is_feature_importer," . "is_feature_curated_list,is_listed_in_index,is_web_robots_allowed, " . " prompt_emails_days_in_advance, is_new," . "is_feature_tag,is_feature_physical_events,is_feature_virtual_events) " . "VALUES (:site_id, :user_account_id, :title, " . ":slug, :slug_canonical,  :created_at,:is_feature_map,:is_feature_importer," . ":is_feature_curated_list,:is_listed_in_index,:is_web_robots_allowed, " . " :prompt_emails_days_in_advance, '1', " . ":is_feature_tag,:is_feature_physical_events,:is_feature_virtual_events)");
         $stat->execute(array('site_id' => $site->getId(), 'user_account_id' => $owner->getId(), 'title' => substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'slug' => $site->getSlug(), 'slug_canonical' => SiteModel::makeCanonicalSlug($site->getSlug()), 'created_at' => $createdat, 'is_feature_curated_list' => $site->getIsFeatureCuratedList() ? 1 : 0, 'is_feature_importer' => $site->getIsFeatureImporter() ? 1 : 0, 'is_feature_map' => $site->getIsFeatureMap() ? 1 : 0, 'is_feature_tag' => $site->getIsFeatureTag() ? 1 : 0, 'is_feature_virtual_events' => $site->getIsFeatureVirtualEvents() ? 1 : 0, 'is_feature_physical_events' => $site->getIsFeaturePhysicalEvents() ? 1 : 0, 'is_listed_in_index' => $site->getIsListedInIndex() ? 1 : 0, 'is_web_robots_allowed' => $site->getIsWebRobotsAllowed() ? 1 : 0, 'prompt_emails_days_in_advance' => $site->getPromptEmailsDaysInAdvance()));
         // Permissions
         $ugr = new UserGroupRepository();
         $userGroupEditors = new UserGroupModel();
         $userGroupEditors->setTitle("Editors");
         $userGroupEditors->setIsIncludesVerifiedUsers($canAnyUserVerifiedEdit);
         $ugr->createForSite($site, $userGroupEditors, $owner, array(array('org.openacalendar', 'CALENDAR_CHANGE')), array($owner));
         $userGroupEditors = new UserGroupModel();
         $userGroupEditors->setTitle("Administrators");
         $ugr->createForSite($site, $userGroupEditors, $owner, array(array('org.openacalendar', 'CALENDAR_ADMINISTRATE')), array($owner));
         // Countries!
         $stat = $DB->prepare("INSERT INTO country_in_site_information (site_id,country_id,is_in,is_previously_in,created_at) VALUES (:site_id,:country_id,'1','1',:created_at)");
         foreach ($countries as $country) {
             $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId(), 'created_at' => $createdat));
         }
         $stat = $DB->prepare("INSERT INTO user_watches_site_information (user_account_id,site_id,is_watching,is_was_once_watching,last_watch_started,created_at) " . "VALUES (:user_account_id,:site_id,:is_watching,:is_was_once_watching,:last_watch_started,:created_at)");
         $stat->execute(array('user_account_id' => $owner->getId(), 'site_id' => $site->getId(), 'is_watching' => '1', 'is_was_once_watching' => '1', 'created_at' => \TimeSource::getFormattedForDataBase(), 'last_watch_started' => \TimeSource::getFormattedForDataBase()));
         $DB->commit();
         $EXTENSIONHOOKRUNNER->afterSiteCreate($site, $owner);
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 protected function newEventFromImportedEventModel(ImportedEventModel $importedEvent)
 {
     $event = new EventModel();
     $event->setFromImportedEventModel($importedEvent);
     if ($this->site->getIsFeaturePhysicalEvents() && !$this->site->getIsFeatureVirtualEvents()) {
         $event->setIsPhysical(true);
         $event->setIsVirtual(false);
     } else {
         if (!$this->site->getIsFeaturePhysicalEvents() && $this->site->getIsFeatureVirtualEvents()) {
             $event->setIsPhysical(false);
             $event->setIsVirtual(true);
         }
     }
     if ($this->country) {
         // country is set on importer.
         $event->setCountryId($this->country->getId());
         $timezones = $this->country->getTimezonesAsList();
         if ($importedEvent->getTimezone() && in_array($importedEvent->getTimezone(), $timezones)) {
             $event->setTimezone($importedEvent->getTimezone());
         } else {
             if ($timezones) {
                 // take first timezone in that country at random :-/
                 $event->setTimezone($timezones[0]);
             }
         }
         if ($this->area) {
             $event->setAreaId($this->area->getId());
         }
     } else {
         // if no country set on importer, we just pick first one at random :-/
         $crb = new \repositories\builders\CountryRepositoryBuilder();
         $crb->setSiteIn($this->site);
         $crb->setLimit(1);
         $countries = $crb->fetchAll();
         if (count($countries) > 0) {
             $country = $countries[0];
             $event->setCountryId($country->getId());
             $timezones = $country->getTimezonesAsList();
             if ($importedEvent->getTimezone() && in_array($importedEvent->getTimezone(), $timezones)) {
                 $event->setTimezone($importedEvent->getTimezone());
             } else {
                 if ($timezones) {
                     // take first timezone in that country at random :-/
                     $event->setTimezone($timezones[0]);
                 }
             }
         }
     }
     return $event;
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('summary', 'text', array('label' => 'Summary', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus'), 'data' => $this->eventDraft->getDetailsValue('event.summary')));
     $builder->add('description', 'textarea', array('label' => 'Description', 'required' => false, 'data' => $this->eventDraft->getDetailsValue('event.description')));
     $builder->add('url', new \symfony\form\MagicUrlType(), array('label' => 'Information Web Page URL', 'required' => false, 'data' => $this->eventDraft->getDetailsValue('event.url')));
     $builder->add('ticket_url', new \symfony\form\MagicUrlType(), array('label' => 'Tickets Web Page URL', 'required' => false, 'data' => $this->eventDraft->getDetailsValue('event.ticket_url')));
     $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['data'] = $this->eventDraft->getDetailsValue('event.custom.' . $customField->getKey());
                     $builder->add('custom_' . $customField->getKey(), $fieldType->getSymfonyFormType($customField), $options);
                 }
             }
         }
     }
     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?', 'data' => $this->eventDraft->hasDetailsValue('event.is_virtual') ? $this->eventDraft->getDetailsValue('event.is_virtual') : $this->fieldIsVirtualDefault));
         } else {
             $builder->add('is_virtual', 'hidden', array('data' => true));
         }
     } else {
         $builder->add('is_virtual', 'hidden', array('data' => false));
     }
     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?', 'data' => $this->eventDraft->hasDetailsValue('event.is_physical') ? $this->eventDraft->getDetailsValue('event.is_physical') : $this->fieldIsPhysicalDefault));
         } else {
             $builder->add('is_physical', 'hidden', array('data' => true));
         }
     } else {
         $builder->add('is_physical', 'hidden', array('data' => false));
     }
     /** @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"));
         }
         if (strpos($form->get("ticket_url")->getData(), " ") !== false) {
             $form['ticket_url']->addError(new FormError("Please enter a URL"));
         }
         // Title
         if (!trim($form->get('summary')->getData())) {
             $form->get('summary')->addError(new FormError("Please enter a summary"));
         }
         // TODO it has to be at least one or the other of physical or virtual
     };
     // 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);
 }
 /**
  * @param SiteModel $site
  * @param $fields
  * @param UserAccountModel $user As opposed to other DBAccess classes, User can not be NULL.
  * @throws Exception
  * @throws \Exception
  */
 public function update(SiteModel $site, $fields, UserAccountModel $user)
 {
     $alreadyInTransaction = $this->db->inTransaction();
     // Make Information Data
     $fieldsSQL1 = array();
     $fieldsParams1 = array('id' => $site->getId());
     foreach ($fields as $field) {
         $fieldsSQL1[] = " " . $field . "=:" . $field . " ";
         if ($field == 'title') {
             $fieldsParams1['title'] = substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
         } else {
             if ($field == 'slug') {
                 $fieldsParams1['slug'] = substr($site->getSlug(), 0, VARCHAR_COLUMN_LENGTH_USED);
                 $fieldsSQL1[] = " slug_canonical=:slug_canonical ";
                 $fieldsParams1['slug_canonical'] = substr(SiteModel::makeCanonicalSlug($site->getSlug()), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'description_text') {
                     $fieldsParams1['description_text'] = $site->getDescriptionText();
                 } else {
                     if ($field == 'footer_text') {
                         $fieldsParams1['footer_text'] = $site->getFooterText();
                     } else {
                         if ($field == 'is_web_robots_allowed') {
                             $fieldsParams1['is_web_robots_allowed'] = $site->getIsWebRobotsAllowed() ? 1 : 0;
                         } else {
                             if ($field == 'is_closed_by_sys_admin') {
                                 $fieldsParams1['is_closed_by_sys_admin'] = $site->getIsClosedBySysAdmin() ? 1 : 0;
                             } else {
                                 if ($field == 'closed_by_sys_admin_reason') {
                                     $fieldsParams1['closed_by_sys_admin_reason'] = $site->getClosedBySysAdminReason();
                                 } else {
                                     if ($field == 'is_listed_in_index') {
                                         $fieldsParams1['is_listed_in_index'] = $site->getIsListedInIndex() ? 1 : 0;
                                     } else {
                                         if ($field == 'is_feature_importer') {
                                             $fieldsParams1['is_feature_importer'] = $site->getIsFeatureImporter() ? 1 : 0;
                                         } else {
                                             if ($field == 'is_feature_curated_list') {
                                                 $fieldsParams1['is_feature_curated_list'] = $site->getIsFeatureCuratedList() ? 1 : 0;
                                             } else {
                                                 if ($field == 'is_feature_map') {
                                                     $fieldsParams1['is_feature_map'] = $site->getIsFeatureMap() ? 1 : 0;
                                                 } else {
                                                     if ($field == 'is_feature_virtual_events') {
                                                         $fieldsParams1['is_feature_virtual_events'] = $site->getIsFeatureVirtualEvents() ? 1 : 0;
                                                     } else {
                                                         if ($field == 'is_feature_physical_events') {
                                                             $fieldsParams1['is_feature_physical_events'] = $site->getIsFeaturePhysicalEvents() ? 1 : 0;
                                                         } else {
                                                             if ($field == 'is_feature_group') {
                                                                 $fieldsParams1['is_feature_group'] = $site->getIsFeatureGroup() ? 1 : 0;
                                                             } else {
                                                                 if ($field == 'prompt_emails_days_in_advance') {
                                                                     $fieldsParams1['prompt_emails_days_in_advance'] = $site->getPromptEmailsDaysInAdvance();
                                                                 } else {
                                                                     if ($field == 'is_feature_tag') {
                                                                         $fieldsParams1['is_feature_tag'] = $site->getIsFeatureTag() ? 1 : 0;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Make History Data
     $fieldsSQL2 = array('site_id', 'user_account_id', 'created_at');
     $fieldsSQLParams2 = array(':site_id', ':user_account_id', ':created_at');
     $fieldsParams2 = array('site_id' => $site->getId(), 'user_account_id' => $user ? $user->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase());
     foreach ($this->possibleFields as $field) {
         if (in_array($field, $fields) || $field == 'title') {
             $fieldsSQL2[] = " " . $field . " ";
             $fieldsSQLParams2[] = " :" . $field . " ";
             if ($field == 'title') {
                 $fieldsParams2['title'] = substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'slug') {
                     $fieldsParams2['slug'] = substr($site->getSlug(), 0, VARCHAR_COLUMN_LENGTH_USED);
                     $fieldsSQL2[] = " slug_canonical  ";
                     $fieldsSQLParams2[] = " :slug_canonical  ";
                     $fieldsParams2['slug_canonical'] = substr(SiteModel::makeCanonicalSlug($site->getSlug()), 0, VARCHAR_COLUMN_LENGTH_USED);
                 } else {
                     if ($field == 'description_text') {
                         $fieldsParams2['description_text'] = $site->getDescriptionText();
                     } else {
                         if ($field == 'footer_text') {
                             $fieldsParams2['footer_text'] = $site->getFooterText();
                         } else {
                             if ($field == 'is_web_robots_allowed') {
                                 $fieldsParams2['is_web_robots_allowed'] = $site->getIsWebRobotsAllowed() ? 1 : 0;
                             } else {
                                 if ($field == 'is_closed_by_sys_admin') {
                                     $fieldsParams2['is_closed_by_sys_admin'] = $site->getIsClosedBySysAdmin() ? 1 : 0;
                                 } else {
                                     if ($field == 'closed_by_sys_admin_reason') {
                                         $fieldsParams2['closed_by_sys_admin_reason'] = $site->getClosedBySysAdminReason();
                                     } else {
                                         if ($field == 'is_listed_in_index') {
                                             $fieldsParams2['is_listed_in_index'] = $site->getIsListedInIndex() ? 1 : 0;
                                         } else {
                                             if ($field == 'is_feature_importer') {
                                                 $fieldsParams2['is_feature_importer'] = $site->getIsFeatureImporter() ? 1 : 0;
                                             } else {
                                                 if ($field == 'is_feature_curated_list') {
                                                     $fieldsParams2['is_feature_curated_list'] = $site->getIsFeatureCuratedList() ? 1 : 0;
                                                 } else {
                                                     if ($field == 'is_feature_map') {
                                                         $fieldsParams2['is_feature_map'] = $site->getIsFeatureMap() ? 1 : 0;
                                                     } else {
                                                         if ($field == 'is_feature_virtual_events') {
                                                             $fieldsParams2['is_feature_virtual_events'] = $site->getIsFeatureVirtualEvents() ? 1 : 0;
                                                         } else {
                                                             if ($field == 'is_feature_physical_events') {
                                                                 $fieldsParams2['is_feature_physical_events'] = $site->getIsFeaturePhysicalEvents() ? 1 : 0;
                                                             } else {
                                                                 if ($field == 'is_feature_group') {
                                                                     $fieldsParams2['is_feature_group'] = $site->getIsFeatureGroup() ? 1 : 0;
                                                                 } else {
                                                                     if ($field == 'prompt_emails_days_in_advance') {
                                                                         $fieldsParams2['prompt_emails_days_in_advance'] = $site->getPromptEmailsDaysInAdvance();
                                                                     } else {
                                                                         if ($field == 'is_feature_tag') {
                                                                             $fieldsParams2['is_feature_tag'] = $site->getIsFeatureTag() ? 1 : 0;
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " 0 ";
         } else {
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " -2 ";
         }
     }
     try {
         if (!$alreadyInTransaction) {
             $this->db->beginTransaction();
         }
         // Information SQL
         $stat = $this->db->prepare("UPDATE site_information  SET " . implode(",", $fieldsSQL1) . " WHERE id=:id");
         $stat->execute($fieldsParams1);
         // History SQL
         $stat = $this->db->prepare("INSERT INTO site_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")");
         $stat->execute($fieldsParams2);
         if (!$alreadyInTransaction) {
             $this->db->commit();
         }
     } catch (Exception $e) {
         if (!$alreadyInTransaction) {
             $this->db->rollBack();
         }
         throw $e;
     }
 }