public function infoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Does not exist.");
     }
     $out = array('event' => array('slug' => $this->event->getSlug(), 'slugForURL' => $this->event->getSlugForUrl(), 'summary' => $this->event->getSummary(), 'summaryDisplay' => $this->event->getSummaryDisplay(), 'description' => $this->event->getDescription(), 'url' => $this->event->getUrl(), 'ticket_url' => $this->event->getTicketUrl()));
     return json_encode($out);
 }
 public function addEvent(EventModel $event, $groups = array(), VenueModel $venue = null, AreaModel $area = null, CountryModel $country = null, $eventMedias = array())
 {
     global $CONFIG;
     $out = array('slug' => $event->getSlug(), 'slugforurl' => $event->getSlugForUrl(), 'summary' => $event->getSummary(), 'summaryDisplay' => $event->getSummaryDisplay(), 'description' => $event->getDescription() ? $event->getDescription() : '', 'deleted' => (bool) $event->getIsDeleted(), 'cancelled' => (bool) $event->getIsCancelled(), 'is_physical' => (bool) $event->getIsPhysical(), 'is_virtual' => (bool) $event->getIsVirtual(), 'custom_fields' => array());
     $out['siteurl'] = $CONFIG->isSingleSiteMode ? 'http://' . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl() : 'http://' . ($this->site ? $this->site->getSlug() : $event->getSiteSlug()) . "." . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl();
     $out['url'] = $event->getUrl() && filter_var($event->getUrl(), FILTER_VALIDATE_URL) ? $event->getUrl() : $out['siteurl'];
     $out['ticket_url'] = $event->getTicketUrl() && filter_var($event->getTicketUrl(), FILTER_VALIDATE_URL) ? $event->getTicketUrl() : null;
     $out['timezone'] = $event->getTimezone();
     $startLocal = clone $event->getStartAt();
     $startLocal->setTimeZone($this->localTimeZone);
     $startTimeZone = clone $event->getStartAt();
     $startTimeZone->setTimeZone(new \DateTimeZone($event->getTimezone()));
     $out['start'] = array('timestamp' => $event->getStartAt()->getTimestamp(), 'rfc2882utc' => $event->getStartAt()->format('r'), 'rfc2882local' => $startLocal->format('r'), 'displaylocal' => $startLocal->format('D j M Y h:ia'), 'yearlocal' => $startLocal->format('Y'), 'monthlocal' => $startLocal->format('n'), 'daylocal' => $startLocal->format('j'), 'hourlocal' => $startLocal->format('G'), 'minutelocal' => $startLocal->format('i'), 'rfc2882timezone' => $startTimeZone->format('r'), 'displaytimezone' => $startTimeZone->format('D j M Y h:ia'), 'yeartimezone' => $startTimeZone->format('Y'), 'monthtimezone' => $startTimeZone->format('n'), 'daytimezone' => $startTimeZone->format('j'), 'hourtimezone' => $startTimeZone->format('G'), 'minutetimezone' => $startTimeZone->format('i'));
     $endLocal = clone $event->getEndAt();
     $endLocal->setTimeZone($this->localTimeZone);
     $endTimeZone = clone $event->getEndAt();
     $endTimeZone->setTimeZone(new \DateTimeZone($event->getTimezone()));
     $out['end'] = array('timestamp' => $event->getEndAt()->getTimestamp(), 'rfc2882utc' => $event->getEndAt()->format('r'), 'rfc2882local' => $endLocal->format('r'), 'displaylocal' => $endLocal->format('D j M Y h:ia'), 'yearlocal' => $endLocal->format('Y'), 'monthlocal' => $endLocal->format('n'), 'daylocal' => $endLocal->format('j'), 'hourlocal' => $endLocal->format('G'), 'minutelocal' => $endLocal->format('i'), 'rfc2882timezone' => $endTimeZone->format('r'), 'displaytimezone' => $endTimeZone->format('D j M Y h:ia'), 'yeartimezone' => $endTimeZone->format('Y'), 'monthtimezone' => $endTimeZone->format('n'), 'daytimezone' => $endTimeZone->format('j'), 'hourtimezone' => $endTimeZone->format('G'), 'minutetimezone' => $endTimeZone->format('i'));
     if (is_array($groups)) {
         $out['groups'] = array();
         foreach ($groups as $group) {
             $out['groups'][] = array('slug' => $group->getSlug(), 'title' => $group->getTitle(), 'description' => $group->getDescription());
         }
     }
     if ($venue) {
         $out['venue'] = array('slug' => $venue->getSlug(), 'title' => $venue->getTitle(), 'description' => $venue->getDescription(), 'address' => $venue->getAddress(), 'addresscode' => $venue->getAddressCode(), 'lat' => $venue->getLat(), 'lng' => $venue->getLng());
     }
     if ($area) {
         $out['areas'] = array(array('slug' => $area->getSlug(), 'title' => $area->getTitle()));
     }
     if ($country) {
         $out['country'] = array('title' => $country->getTitle());
     }
     if (is_array($eventMedias)) {
         $out['medias'] = array();
         $siteurl = $CONFIG->getWebSiteDomainSecure($this->site->getSlug());
         foreach ($eventMedias as $eventMedia) {
             $out['medias'][] = array('slug' => $eventMedia->getSlug(), 'title' => $eventMedia->getTitle(), 'sourceUrl' => $eventMedia->getSourceUrl(), 'sourcetext' => $eventMedia->getSourceText(), 'picture' => array('fullURL' => $siteurl . '/media/' . $eventMedia->getSlug() . '/full', 'normalURL' => $siteurl . '/media/' . $eventMedia->getSlug() . '/normal', 'thumbnailURL' => $siteurl . '/media/' . $eventMedia->getSlug() . '/thumbnail'));
         }
     }
     if ($this->site) {
         foreach ($this->site->getCachedEventCustomFieldDefinitionsAsModels() as $customField) {
             $out['custom_fields'][$customField->getKey()] = $event->getCustomField($customField);
         }
     }
     $this->events[] = $out;
 }
 public function addEvent(EventModel $event, $groups = array(), VenueModel $venue = null, AreaModel $area = null, CountryModel $country = null, $eventMedias = array())
 {
     global $CONFIG;
     $siteurlbase = $CONFIG->getWebSiteDomainSecure($this->site ? $this->site->getSlug() : $event->getSiteSlug());
     $siteurl = $siteurlbase . '/event/' . $event->getSlugForUrl();
     $url = $event->getUrl() && filter_var($event->getUrl(), FILTER_VALIDATE_URL) ? $event->getUrl() : $siteurl;
     $ticket_url = $event->getTicketUrl() && filter_var($event->getTicketUrl(), FILTER_VALIDATE_URL) ? $event->getTicketUrl() : null;
     $this->events[] = $this->getCell($event->getSlug()) . $this->delimiter . $this->getCell($event->getSlugForUrl()) . $this->delimiter . $this->getCell($event->getSummary()) . $this->delimiter . $this->getCell($event->getSummaryDisplay()) . $this->delimiter . $this->getCell($event->getDescription()) . $this->delimiter . $this->getCellBoolean($event->getIsDeleted()) . $this->delimiter . $this->getCellBoolean($event->getIsCancelled()) . $this->delimiter . $this->getCellBoolean($event->getIsPhysical()) . $this->delimiter . $this->getCellBoolean($event->getIsVirtual()) . $this->delimiter . $this->getCell($siteurl) . $this->delimiter . $this->getCell($url) . $this->delimiter . $this->getCell($ticket_url) . $this->delimiter . $this->getCell($event->getTimezone()) . $this->delimiter . $this->getCell($event->getStartAtInUTC()->format("r")) . $this->delimiter . $this->getCell($event->getEndAtInUTC()->format("r")) . $this->delimiter . $this->getCell($event->getStartAtInTimezone()->format("r")) . $this->delimiter . $this->getCell($event->getEndAtInTimezone()->format("r")) . $this->delimiter . ($venue ? $this->getCell($venue->getSlug()) . $this->delimiter . $this->getCell($venue->getSlugForUrl()) . $this->delimiter . $this->getCell($venue->getTitle()) . $this->delimiter . $this->getCell($venue->getDescription()) . $this->delimiter . $this->getCell($venue->getAddress()) . $this->delimiter . $this->getCell($venue->getAddressCode()) . $this->delimiter . $this->getCell($venue->getLat()) . $this->delimiter . $this->getCell($venue->getLng()) . $this->delimiter . $this->getCell($siteurlbase . '/venue/' . $venue->getSlugForUrl()) . $this->delimiter : $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter) . ($area ? $this->getCell($area->getSlug()) . $this->delimiter . $this->getCell($area->getSlugForUrl()) . $this->delimiter . $this->getCell($area->getTitle()) . $this->delimiter . $this->getCell($area->getDescription()) . $this->delimiter . $this->getCell($siteurlbase . '/area/' . $area->getSlugForUrl()) . $this->delimiter : $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter . $this->delimiter) . ($country ? $this->getCell($country->getTwoCharCode()) . $this->delimiter . $this->getCell($country->getTitle()) . $this->delimiter . $this->getCell($siteurlbase . '/country/' . $country->getTwoCharCode()) . $this->delimiter : $this->delimiter . $this->delimiter . $this->delimiter);
 }
 public function addEvent(EventModel $event, $groups = array(), VenueModel $venue = null, AreaModel $area = null, CountryModel $country = null, $eventMedias = array())
 {
     global $CONFIG;
     if ($event->getIsDeleted()) {
         return false;
     }
     // ########################################### Get Data
     $siteSlug = $this->site ? $this->site->getSlug() : $event->getSiteSlug();
     $ourUrl = $CONFIG->isSingleSiteMode ? 'http://' . $CONFIG->webSiteDomain . '/event/' . $event->getSlug() : 'http://' . $siteSlug . "." . $CONFIG->webSiteDomain . '/event/' . $event->getSlug();
     $dh = new \DateTime('', $this->localTimeZone);
     $dh->setTimestamp($event->getStartAt()->getTimestamp());
     $dateTxt = $dh->format('D j M Y h:ia') . ' to ';
     $dateTxtShort = $dh->format('D j M');
     $dh->setTimestamp($event->getEndAt()->getTimestamp());
     $dateTxt .= $dh->format('D j M Y h:ia');
     // ########################################## Build
     $txt = '<entry>';
     $txt .= '<id>' . $ourUrl . '</id>';
     $txt .= '<link href="' . $ourUrl . '"/>';
     $txt .= '<title>' . $this->getData($event->getSummaryDisplay() . ', ' . $dateTxtShort) . '</title>';
     $txt .= '<summary>' . $dateTxt . '</summary>';
     $content = '';
     foreach ($this->extraHeaders as $extraHeader) {
         $content .= $extraHeader->getHtml() . "<br><br>";
     }
     $content .= $dateTxt . "<br>";
     if ($event->getDescription()) {
         $content .= str_replace("\n", "<br>", htmlentities($event->getDescription(), ENT_QUOTES, 'UTF-8')) . '<br>';
     }
     // TODO $event->getUrl()
     $content .= '<a href="' . htmlentities($ourUrl) . '">More details at ' . htmlentities($ourUrl) . '</a><br>';
     $content .= '<p style="font-style:italic;font-size:80%">' . 'Powered by <a href="' . $ourUrl . '">' . $CONFIG->siteTitle . '</a>';
     foreach ($this->extraFooters as $extraFooter) {
         $content .= "<br>" . $extraFooter->getHtml();
     }
     $content .= '</p>';
     $txt .= '<content type="html">' . $this->getBigData($content) . '</content>';
     $txt .= $this->getUpdatedString($event);
     $txt .= '<author><name>' . $CONFIG->siteTitle . '</name></author></entry>' . " \r\n";
     $this->events[] = $txt;
 }
 public function applyChangeToFutureEvents()
 {
     $startDiff = $this->initalEvent->getStartAtInUTC()->diff($this->initialEventJustBeforeLastChange->getStartAtInUTC());
     $endDiff = $this->initalEvent->getEndAtInUTC()->diff($this->initialEventJustBeforeLastChange->getEndAtInUTC());
     foreach ($this->futureEvents as $futureEvent) {
         $this->futureEventsProposedChanges[$futureEvent->getSlug()] = new EventInRecurSetProposedChangesModel();
         if (($this->initalEventLastChange->getCountryIdChanged() || $this->initalEventLastChange->getVenueIdChanged() || $this->initalEventLastChange->getAreaIdChanged()) && ($this->initalEvent->getCountryId() != $futureEvent->getCountryId() || $this->initalEvent->getAreaId() != $futureEvent->getAreaId() || $this->initalEvent->getVenueId() != $futureEvent->getVenueId())) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setCountryAreaVenueIdChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getCountryId() != $futureEvent->getCountryId() || $this->initialEventJustBeforeLastChange->getAreaId() != $futureEvent->getAreaId() || $this->initialEventJustBeforeLastChange->getVenueId() != $futureEvent->getVenueId()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setCountryAreaVenueIdChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getSummaryChanged()) {
             $summary = $this->initalEvent->getSummary();
             // change month title
             $currentMonthLong = $this->initalEvent->getStartAtInUTC()->format('F');
             $currentMonthShort = $this->initalEvent->getStartAtInUTC()->format('M');
             if (stripos($summary, $currentMonthLong) !== false) {
                 $summary = str_ireplace($currentMonthLong, $futureEvent->getStartAtInUTC()->format('F'), $summary);
             } else {
                 if (stripos($summary, $currentMonthShort) !== false) {
                     $summary = str_ireplace($currentMonthShort, $futureEvent->getStartAtInUTC()->format('M'), $summary);
                 }
             }
             if ($summary != $futureEvent->getSummary()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setSummary($summary);
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setSummaryChangePossible(true);
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setSummaryChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getDescriptionChanged() && $this->initalEvent->getDescription() != $futureEvent->getDescription()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setDescriptionChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getDescription() == $futureEvent->getDescription()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setDescriptionChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getUrlChanged() && $this->initalEvent->getUrl() != $futureEvent->getUrl()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setUrlChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getUrl() == $futureEvent->getUrl()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setUrlChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getTicketUrlChanged() && $this->initalEvent->getTicketUrl() != $futureEvent->getTicketUrl()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setTicketUrlChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getTicketUrl() == $futureEvent->getTicketUrl()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setTicketUrlChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getTimezoneChanged() && $this->initalEvent->getTimezone() != $futureEvent->getTimezone()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setTimezoneChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getTimezone() == $futureEvent->getTimezone()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setTimezoneChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getIsPhysicalChanged() && $this->initalEvent->getIsPhysical() != $futureEvent->getIsPhysical()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsPhysicalChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getIsPhysical() == $futureEvent->getIsPhysical()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsPhysicalChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getIsVirtualChanged() && $this->initalEvent->getIsVirtual() != $futureEvent->getIsVirtual()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsVirtualChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getIsVirtual() == $futureEvent->getIsVirtual()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsVirtualChangeSelected(true);
             }
         }
         if ($this->initalEventLastChange->getIsCancelledChanged() && $this->initalEvent->getIsCancelled() != $futureEvent->getIsCancelled()) {
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsCancelledChangePossible(true);
             if ($this->initialEventJustBeforeLastChange->getIsCancelled() == $futureEvent->getIsCancelled()) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setIsCancelledChangeSelected(true);
             }
         }
         if ($startDiff->y != 0 || $startDiff->m != 0 || $startDiff->d != 0 || $startDiff->h != 0 || $startDiff->i != 0 || $startDiff->s != 0 || ($endDiff->y != 0 || $endDiff->m != 0 || $endDiff->d != 0 || $endDiff->h != 0 || $endDiff->i != 0 || $endDiff->s != 0)) {
             $start = clone $futureEvent->getStartAtInUTC();
             $start->sub($startDiff);
             $end = clone $futureEvent->getEndAtInUTC();
             $end->sub($endDiff);
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setStartEndAtChangePossible(true);
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setStartEndAtChangeSelected(true);
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setStartAt($start);
             $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setEndAt($end);
         }
         foreach ($this->customFields as $customField) {
             if ($this->initalEventLastChange->hasCustomField($customField) && $this->initalEvent->getCustomField($customField) != $futureEvent->getCustomField($customField)) {
                 $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setCustomFieldChangePossible($customField, true);
                 if ($this->initialEventJustBeforeLastChange->getCustomField($customField) == $futureEvent->getCustomField($customField)) {
                     $this->futureEventsProposedChanges[$futureEvent->getSlug()]->setCustomFieldChangeSelected($customField, true);
                 }
             }
         }
     }
 }
 public function addEvent(EventModel $event, $groups = array(), VenueModel $venue = null, AreaModel $area = null, CountryModel $country = null, $eventMedias = array())
 {
     global $CONFIG;
     $siteSlug = $this->site ? $this->site->getSlug() : $event->getSiteSlug();
     $txt = $this->getIcalLine('BEGIN', 'VEVENT');
     $txt .= $this->getIcalLine('UID', $event->getSlug() . '@' . $siteSlug . "." . $CONFIG->webSiteDomain);
     $url = $CONFIG->isSingleSiteMode ? 'http://' . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl() : 'http://' . $siteSlug . "." . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl();
     $txt .= $this->getIcalLine('URL', $url);
     if ($event->getIsDeleted()) {
         $txt .= $this->getIcalLine('SUMMARY', $event->getSummaryDisplay() . " [DELETED]");
         $txt .= $this->getIcalLine('METHOD', 'CANCEL');
         $txt .= $this->getIcalLine('STATUS', 'CANCELLED');
         $txt .= $this->getIcalLine('DESCRIPTION', 'DELETED');
     } else {
         if ($event->getIsCancelled()) {
             $txt .= $this->getIcalLine('SUMMARY', $event->getSummaryDisplay() . " [CANCELLED]");
             $txt .= $this->getIcalLine('METHOD', 'CANCEL');
             $txt .= $this->getIcalLine('STATUS', 'CANCELLED');
             $txt .= $this->getIcalLine('DESCRIPTION', 'CANCELLED');
         } else {
             $txt .= $this->getIcalLine('SUMMARY', $event->getSummaryDisplay());
             $description = '';
             foreach ($this->extraHeaders as $extraHeader) {
                 $description .= $extraHeader->getText() . "\n\n";
             }
             $description .= $event->getDescription() . "\n" . $url . "\n" . "Powered by " . $CONFIG->siteTitle;
             foreach ($this->extraFooters as $extraFooter) {
                 $description .= "\n" . $extraFooter->getText();
             }
             $txt .= $this->getIcalLine('DESCRIPTION', $description);
             $descriptionHTML = "<html><body>";
             foreach ($this->extraHeaders as $extraHeader) {
                 $descriptionHTML .= "<p>" . $extraHeader->getHtml() . "</p>";
             }
             $descriptionHTML .= "<p>" . str_replace("\r", "", str_replace("\n", "<br>", htmlentities($event->getDescription()))) . "</p>";
             //if ($event->getUrl()) $descriptionHTML .= '<p>More info: <a href="'.$event->getUrl().'">'.$event->getUrl().'</a></p>';
             $descriptionHTML .= '<p>More info: <a href="' . $url . '">' . $url . '</a></p>';
             $descriptionHTML .= '<p style="font-style:italic;font-size:80%">Powered by <a href="' . $url . '">' . $CONFIG->siteTitle . '</a>';
             foreach ($this->extraFooters as $extraFooter) {
                 $descriptionHTML .= "<br>" . $extraFooter->getHtml();
             }
             $descriptionHTML .= '</p>';
             $descriptionHTML .= '</body></html>';
             $txt .= $this->getIcalLine("X-ALT-DESC;FMTTYPE=text/html", $descriptionHTML);
             $locationDetails = array();
             if ($event->getVenue() && $event->getVenue()->getTitle()) {
                 $locationDetails[] = $event->getVenue()->getTitle();
             }
             if ($event->getVenue() && $event->getVenue()->getAddress()) {
                 $locationDetails[] = $event->getVenue()->getAddress();
             }
             if ($event->getArea() && $event->getArea()->getTitle()) {
                 $locationDetails[] = $event->getArea()->getTitle();
             }
             if ($event->getVenue() && $event->getVenue()->getAddressCode()) {
                 $locationDetails[] = $event->getVenue()->getAddressCode();
             }
             if ($locationDetails) {
                 $txt .= $this->getIcalLine('LOCATION', implode(", ", $locationDetails));
             }
             if ($event->getVenue() && $event->getVenue()->getLat() && $event->getVenue()->getLng()) {
                 $txt .= $this->getIcalLine('GEO', $event->getVenue()->getLat() . ";" . $event->getVenue()->getLng());
             }
         }
     }
     $txt .= $this->getIcalLine('DTSTART', $event->getStartAt()->format("Ymd") . "T" . $event->getStartAt()->format("His") . "Z");
     $txt .= $this->getIcalLine('DTEND', $event->getEndAt()->format("Ymd") . "T" . $event->getEndAt()->format("His") . "Z");
     $txt .= $this->getIcalLine('END', 'VEVENT');
     $this->events[] = $txt;
 }
 public function createWithMetaData(EventModel $event, SiteModel $site, EventEditMetaDataModel $eventEditMetaDataModel, GroupModel $group = null, $additionalGroups = null, ImportedEventModel $importedEvent = null, $tags = array(), $medias = array())
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("SELECT max(slug) AS c FROM event_information WHERE site_id=:site_id");
         $stat->execute(array('site_id' => $site->getId()));
         $data = $stat->fetch();
         $event->setSlug($data['c'] + 1);
         $stat = $DB->prepare("INSERT INTO event_information (site_id, slug, summary,description,start_at,end_at," . " created_at, event_recur_set_id,venue_id,country_id,timezone, " . " url, ticket_url, is_physical, is_virtual, area_id, approved_at, is_deleted, is_cancelled, custom_fields) " . " VALUES (:site_id, :slug, :summary, :description, :start_at, :end_at, " . " :created_at, :event_recur_set_id,:venue_id,:country_id,:timezone, " . " :url, :ticket_url, :is_physical, :is_virtual, :area_id, :approved_at, '0', '0', :custom_fields) RETURNING id");
         $stat->execute(array('site_id' => $site->getId(), 'slug' => $event->getSlug(), 'summary' => substr($event->getSummary(), 0, VARCHAR_COLUMN_LENGTH_USED), 'description' => $event->getDescription(), 'start_at' => $event->getStartAtInUTC()->format("Y-m-d H:i:s"), 'end_at' => $event->getEndAtInUTC()->format("Y-m-d H:i:s"), 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase(), 'event_recur_set_id' => $event->getEventRecurSetId(), 'country_id' => $event->getCountryId(), 'venue_id' => $event->getVenueId(), 'area_id' => $event->getVenueId() ? null : $event->getAreaId(), 'timezone' => $event->getTimezone(), 'url' => substr($event->getUrl(), 0, VARCHAR_COLUMN_LENGTH_USED), 'ticket_url' => substr($event->getTicketUrl(), 0, VARCHAR_COLUMN_LENGTH_USED), 'is_physical' => $event->getIsPhysical() ? 1 : 0, 'is_virtual' => $event->getIsVirtual() ? 1 : 0, 'custom_fields' => json_encode($event->getCustomFields())));
         $data = $stat->fetch();
         $event->setId($data['id']);
         $stat = $DB->prepare("INSERT INTO event_history (event_id, summary, description,start_at, end_at, " . " user_account_id  , created_at,venue_id,country_id,timezone," . " url, ticket_url, is_physical, is_virtual, area_id, is_new, approved_at, is_deleted, is_cancelled, edit_comment, custom_fields) VALUES " . " (:event_id, :summary, :description, :start_at, :end_at, " . " :user_account_id  , :created_at,:venue_id,:country_id,:timezone," . " :url, :ticket_url, :is_physical, :is_virtual, :area_id, '1', :approved_at, '0', '0', :edit_comment, :custom_fields)");
         $stat->execute(array('event_id' => $event->getId(), 'summary' => substr($event->getSummary(), 0, VARCHAR_COLUMN_LENGTH_USED), 'description' => $event->getDescription(), 'start_at' => $event->getStartAtInUTC()->format("Y-m-d H:i:s"), 'end_at' => $event->getEndAtInUTC()->format("Y-m-d H:i:s"), 'user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase(), 'country_id' => $event->getCountryId(), 'venue_id' => $event->getVenueId(), 'area_id' => $event->getVenueId() ? null : $event->getAreaId(), 'timezone' => $event->getTimezone(), 'url' => substr($event->getUrl(), 0, VARCHAR_COLUMN_LENGTH_USED), 'ticket_url' => substr($event->getTicketUrl(), 0, VARCHAR_COLUMN_LENGTH_USED), 'is_physical' => $event->getIsPhysical() ? 1 : 0, 'is_virtual' => $event->getIsVirtual() ? 1 : 0, 'edit_comment' => $eventEditMetaDataModel->getEditComment(), 'custom_fields' => json_encode($event->getCustomFields())));
         // Group can be passed as model or as field on event!
         if (!$group && $event->getGroupId()) {
             $group = new GroupModel();
             $group->setId($event->getGroupId());
         }
         if ($group || $additionalGroups) {
             $stat = $DB->prepare("INSERT INTO event_in_group (group_id,event_id,added_by_user_account_id,added_at,is_main_group,addition_approved_at) " . "VALUES (:group_id,:event_id,:added_by_user_account_id,:added_at,:is_main_group,:addition_approved_at)");
             if ($group) {
                 $stat->execute(array('group_id' => $group->getId(), 'event_id' => $event->getId(), 'added_by_user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'added_at' => \TimeSource::getFormattedForDataBase(), 'addition_approved_at' => \TimeSource::getFormattedForDataBase(), 'is_main_group' => 1));
             }
             if ($additionalGroups && is_array($additionalGroups)) {
                 foreach ($additionalGroups as $additionalGroup) {
                     if ($additionalGroup->getId() != $group->getId()) {
                         $stat->execute(array('group_id' => $additionalGroup->getId(), 'event_id' => $event->getId(), 'added_by_user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'added_at' => \TimeSource::getFormattedForDataBase(), 'addition_approved_at' => \TimeSource::getFormattedForDataBase(), 'is_main_group' => 0));
                     }
                 }
             }
         }
         if ($eventEditMetaDataModel->getUserAccount()) {
             if ($event->getGroupId()) {
                 $ufgr = new UserWatchesGroupRepository();
                 $ufgr->startUserWatchingGroupIdIfNotWatchedBefore($eventEditMetaDataModel->getUserAccount(), $event->getGroupId());
             } else {
                 // TODO watch site?
             }
         }
         if ($importedEvent) {
             $stat = $DB->prepare("INSERT INTO imported_event_is_event (imported_event_id, event_id, created_at) " . "VALUES (:imported_event_id, :event_id, :created_at)");
             $stat->execute(array('imported_event_id' => $importedEvent->getId(), 'event_id' => $event->getId(), 'created_at' => \TimeSource::getFormattedForDataBase()));
         }
         if ($tags) {
             $stat = $DB->prepare("INSERT INTO event_has_tag (tag_id,event_id,added_by_user_account_id,added_at,addition_approved_at) " . "VALUES (:tag_id,:event_id,:added_by_user_account_id,:added_at,:addition_approved_at)");
             foreach ($tags as $tag) {
                 $stat->execute(array('tag_id' => $tag->getId(), 'event_id' => $event->getId(), 'added_by_user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'added_at' => \TimeSource::getFormattedForDataBase(), 'addition_approved_at' => \TimeSource::getFormattedForDataBase()));
             }
         }
         if ($medias) {
             $stat = $DB->prepare("INSERT INTO media_in_event (event_id,media_id,added_by_user_account_id,added_at,addition_approved_at) " . "VALUES (:event_id,:media_id,:added_by_user_account_id,:added_at,:addition_approved_at)");
             foreach ($medias as $media) {
                 $stat->execute(array('event_id' => $event->getId(), 'media_id' => $media->getId(), 'added_by_user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'added_at' => \TimeSource::getFormattedForDataBase(), 'addition_approved_at' => \TimeSource::getFormattedForDataBase()));
             }
         }
         if ($eventEditMetaDataModel->getCreatedFromNewEventDraftID()) {
             $stat = $DB->prepare("UPDATE new_event_draft_information SET event_id=:event_id WHERE id=:id");
             $stat->execute(array('event_id' => $event->getId(), 'id' => $eventEditMetaDataModel->getCreatedFromNewEventDraftID()));
             $stat = $DB->prepare("INSERT INTO new_event_draft_history (new_event_draft_id, event_id, user_account_id,created_at,details_changed,was_existing_event_id_changed,not_duplicate_events_changed) " . "VALUES (:new_event_draft_id, :event_id, :user_account_id,:created_at,-2,-2,-2 )");
             $stat->execute(array('new_event_draft_id' => $eventEditMetaDataModel->getCreatedFromNewEventDraftID(), 'event_id' => $event->getId(), 'user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => \TimeSource::getFormattedForDataBase()));
         }
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 public function update(EventModel $event, $fields, EventEditMetaDataModel $eventEditMetaDataModel)
 {
     $alreadyInTransaction = $this->db->inTransaction();
     // Make Information Data
     $fieldsSQL1 = array();
     $fieldsParams1 = array('id' => $event->getId());
     foreach ($fields as $field) {
         if ($field == 'custom') {
             $fieldsSQL1[] = " custom_fields = :custom_fields ";
             $fieldsParams1['custom_fields'] = json_encode($event->getCustomFields());
         } else {
             $fieldsSQL1[] = " " . $field . "=:" . $field . " ";
             if ($field == 'summary') {
                 $fieldsParams1['summary'] = substr($event->getSummary(), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'description') {
                     $fieldsParams1['description'] = $event->getDescription();
                 } else {
                     if ($field == 'start_at') {
                         $fieldsParams1['start_at'] = $event->getStartAt()->format("Y-m-d H:i:s");
                     } else {
                         if ($field == 'end_at') {
                             $fieldsParams1['end_at'] = $event->getEndAt()->format("Y-m-d H:i:s");
                         } else {
                             if ($field == 'venue_id') {
                                 $fieldsParams1['venue_id'] = $event->getVenueId();
                             } else {
                                 if ($field == 'area_id') {
                                     $fieldsParams1['area_id'] = $event->getAreaId();
                                 } else {
                                     if ($field == 'country_id') {
                                         $fieldsParams1['country_id'] = $event->getCountryId();
                                     } else {
                                         if ($field == 'timezone') {
                                             $fieldsParams1['timezone'] = substr($event->getTimezone(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                         } else {
                                             if ($field == 'url') {
                                                 $fieldsParams1['url'] = substr($event->getUrl(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                             } else {
                                                 if ($field == 'ticket_url') {
                                                     $fieldsParams1['ticket_url'] = substr($event->getTicketUrl(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                                 } else {
                                                     if ($field == 'is_physical') {
                                                         $fieldsParams1['is_physical'] = $event->getIsPhysical() ? 1 : 0;
                                                     } else {
                                                         if ($field == 'is_virtual') {
                                                             $fieldsParams1['is_virtual'] = $event->getIsVirtual() ? 1 : 0;
                                                         } else {
                                                             if ($field == 'is_cancelled') {
                                                                 $fieldsParams1['is_cancelled'] = $event->getIsCancelled() ? 1 : 0;
                                                             } else {
                                                                 if ($field == 'is_deleted') {
                                                                     $fieldsParams1['is_deleted'] = $event->getIsDeleted() ? 1 : 0;
                                                                 } else {
                                                                     if ($field == 'is_duplicate_of_id') {
                                                                         $fieldsParams1['is_duplicate_of_id'] = $event->getIsDuplicateOfId();
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Make History Data
     $fieldsSQL2 = array('event_id', 'user_account_id', 'created_at', 'approved_at', 'from_ip');
     $fieldsSQLParams2 = array(':event_id', ':user_account_id', ':created_at', ':approved_at', ':from_ip');
     $fieldsParams2 = array('event_id' => $event->getId(), 'user_account_id' => $eventEditMetaDataModel->getUserAccount() ? $eventEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase(), 'approved_at' => $this->timesource->getFormattedForDataBase(), 'from_ip' => $eventEditMetaDataModel->getIp());
     if ($eventEditMetaDataModel->getRevertedFromHistoryCreatedAt()) {
         $fieldsSQL2[] = ' reverted_from_created_at ';
         $fieldsSQLParams2[] = ' :reverted_from_created_at ';
         $fieldsParams2['reverted_from_created_at'] = $eventEditMetaDataModel->getRevertedFromHistoryCreatedAt()->format("Y-m-d H:i:s");
     }
     if ($eventEditMetaDataModel->getEditComment()) {
         $fieldsSQL2[] = ' edit_comment ';
         $fieldsSQLParams2[] = ' :edit_comment ';
         $fieldsParams2['edit_comment'] = $eventEditMetaDataModel->getEditComment();
     }
     foreach ($this->possibleFields as $field) {
         if (in_array($field, $fields) || $field == 'summary') {
             $fieldsSQL2[] = " " . $field . " ";
             $fieldsSQLParams2[] = " :" . $field . " ";
             if ($field == 'summary') {
                 $fieldsParams2['summary'] = substr($event->getSummary(), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'description') {
                     $fieldsParams2['description'] = $event->getDescription();
                 } else {
                     if ($field == 'start_at') {
                         $fieldsParams2['start_at'] = $event->getStartAt()->format("Y-m-d H:i:s");
                     } else {
                         if ($field == 'end_at') {
                             $fieldsParams2['end_at'] = $event->getEndAt()->format("Y-m-d H:i:s");
                         } else {
                             if ($field == 'venue_id') {
                                 $fieldsParams2['venue_id'] = $event->getVenueId();
                             } else {
                                 if ($field == 'area_id') {
                                     $fieldsParams2['area_id'] = $event->getAreaId();
                                 } else {
                                     if ($field == 'country_id') {
                                         $fieldsParams2['country_id'] = $event->getCountryId();
                                     } else {
                                         if ($field == 'timezone') {
                                             $fieldsParams2['timezone'] = substr($event->getTimezone(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                         } else {
                                             if ($field == 'url') {
                                                 $fieldsParams2['url'] = substr($event->getUrl(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                             } else {
                                                 if ($field == 'ticket_url') {
                                                     $fieldsParams2['ticket_url'] = substr($event->getTicketUrl(), 0, VARCHAR_COLUMN_LENGTH_USED);
                                                 } else {
                                                     if ($field == 'is_physical') {
                                                         $fieldsParams2['is_physical'] = $event->getIsPhysical() ? 1 : 0;
                                                     } else {
                                                         if ($field == 'is_virtual') {
                                                             $fieldsParams2['is_virtual'] = $event->getIsVirtual() ? 1 : 0;
                                                         } else {
                                                             if ($field == 'is_cancelled') {
                                                                 $fieldsParams2['is_cancelled'] = $event->getIsCancelled() ? 1 : 0;
                                                             } else {
                                                                 if ($field == 'is_deleted') {
                                                                     $fieldsParams2['is_deleted'] = $event->getIsDeleted() ? 1 : 0;
                                                                 } else {
                                                                     if ($field == 'is_duplicate_of_id') {
                                                                         $fieldsParams2['is_duplicate_of_id'] = $event->getIsDuplicateOfId();
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " 0 ";
         } else {
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " -2 ";
         }
     }
     if (in_array("custom", $fields)) {
         $fieldsSQL2[] = " custom_fields ";
         $fieldsSQLParams2[] = " :custom_fields ";
         $fieldsParams2['custom_fields'] = json_encode($event->getCustomFields());
         $fieldsSQL2[] = " custom_fields_changed ";
         $fieldsSQLParams2[] = " 0 ";
     } else {
         $fieldsSQL2[] = " custom_fields_changed ";
         $fieldsSQLParams2[] = " -2 ";
     }
     try {
         if (!$alreadyInTransaction) {
             $this->db->beginTransaction();
         }
         // Information SQL
         $stat = $this->db->prepare("UPDATE event_information  SET " . implode(",", $fieldsSQL1) . " WHERE id=:id");
         $stat->execute($fieldsParams1);
         // History SQL
         $stat = $this->db->prepare("INSERT INTO event_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")");
         $stat->execute($fieldsParams2);
         if (!$alreadyInTransaction) {
             $this->db->commit();
         }
     } catch (Exception $e) {
         if (!$alreadyInTransaction) {
             $this->db->rollBack();
         }
         throw $e;
     }
 }
 public function addEvent(EventModel $event, VenueModel $venue = null, AreaModel $area = null, CountryModel $country = null)
 {
     global $CONFIG;
     $out = array('slug' => $event->getSlug(), 'slugforurl' => $event->getSlugForUrl(), 'summary' => $event->getSummary(), 'summaryDisplay' => $event->getSummaryDisplay(), 'description' => $event->getDescription() ? $event->getDescription() : '', 'deleted' => (bool) $event->getIsDeleted(), 'cancelled' => (bool) $event->getIsCancelled(), 'is_physical' => (bool) $event->getIsPhysical(), 'is_virtual' => (bool) $event->getIsVirtual());
     $out['siteurl'] = $CONFIG->isSingleSiteMode ? 'http://' . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl() : 'http://' . ($this->site ? $this->site->getSlug() : $event->getSiteSlug()) . "." . $CONFIG->webSiteDomain . '/event/' . $event->getSlugForUrl();
     $out['url'] = $event->getUrl() && filter_var($event->getUrl(), FILTER_VALIDATE_URL) ? $event->getUrl() : $out['siteurl'];
     $out['ticket_url'] = $event->getTicketUrl() && filter_var($event->getTicketUrl(), FILTER_VALIDATE_URL) ? $event->getTicketUrl() : null;
     $out['timezone'] = $event->getTimezone();
     $startLocal = clone $event->getStartAt();
     $startLocal->setTimeZone($this->localTimeZone);
     $startTimeZone = clone $event->getStartAt();
     $startTimeZone->setTimeZone(new \DateTimeZone($event->getTimezone()));
     $out['start'] = array('timestamp' => $event->getStartAt()->getTimestamp(), 'rfc2882utc' => $event->getStartAt()->format('r'), 'rfc2882local' => $startLocal->format('r'), 'displaylocal' => $startLocal->format('D j M Y h:ia'), 'yearlocal' => $startLocal->format('Y'), 'monthlocal' => $startLocal->format('n'), 'daylocal' => $startLocal->format('j'), 'hourlocal' => $startLocal->format('G'), 'minutelocal' => $startLocal->format('i'), 'rfc2882timezone' => $startTimeZone->format('r'), 'displaytimezone' => $startTimeZone->format('D j M Y h:ia'), 'yeartimezone' => $startTimeZone->format('Y'), 'monthtimezone' => $startTimeZone->format('n'), 'daytimezone' => $startTimeZone->format('j'), 'hourtimezone' => $startTimeZone->format('G'), 'minutetimezone' => $startTimeZone->format('i'));
     $endLocal = clone $event->getEndAt();
     $endLocal->setTimeZone($this->localTimeZone);
     $endTimeZone = clone $event->getEndAt();
     $endTimeZone->setTimeZone(new \DateTimeZone($event->getTimezone()));
     $out['end'] = array('timestamp' => $event->getEndAt()->getTimestamp(), 'rfc2882utc' => $event->getEndAt()->format('r'), 'rfc2882local' => $endLocal->format('r'), 'displaylocal' => $endLocal->format('D j M Y h:ia'), 'yearlocal' => $endLocal->format('Y'), 'monthlocal' => $endLocal->format('n'), 'daylocal' => $endLocal->format('j'), 'hourlocal' => $endLocal->format('G'), 'minutelocal' => $endLocal->format('i'), 'rfc2882timezone' => $endTimeZone->format('r'), 'displaytimezone' => $endTimeZone->format('D j M Y h:ia'), 'yeartimezone' => $endTimeZone->format('Y'), 'monthtimezone' => $endTimeZone->format('n'), 'daytimezone' => $endTimeZone->format('j'), 'hourtimezone' => $endTimeZone->format('G'), 'minutetimezone' => $endTimeZone->format('i'));
     if ($venue) {
         $out['venue'] = array('slug' => $venue->getSlug(), 'title' => $venue->getTitle(), 'description' => $venue->getDescription(), 'address' => $venue->getAddress(), 'addresscode' => $venue->getAddressCode(), 'lat' => $venue->getLat(), 'lng' => $venue->getLng());
     }
     if ($area) {
         $out['areas'] = array(array('slug' => $area->getSlug(), 'title' => $area->getTitle()));
     }
     if ($country) {
         $out['country'] = array('title' => $country->getTitle());
     }
     return $out;
 }