public function isCountryInSite(CountryModel $country, SiteModel $site)
 {
     global $DB;
     $stat = $DB->prepare("SELECT * FROM country_in_site_information WHERE site_id =:site_id AND country_id =:country_id AND is_in= '1'");
     $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId()));
     return $stat->rowCount() == 1;
 }
 protected function build()
 {
     $this->select[] = 'area_information.*';
     if ($this->site) {
         $this->where[] = " area_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->country) {
         $this->where[] = " area_information.country_id = :country_id ";
         $this->params['country_id'] = $this->country->getId();
     }
     if (!$this->include_deleted) {
         $this->where[] = " area_information.is_deleted = '0' ";
     }
     if ($this->noParentArea) {
         $this->where[] = ' area_information.parent_area_id IS null ';
     } else {
         if ($this->parentArea) {
             $this->where[] = " area_information.parent_area_id = :parent_id ";
             $this->params['parent_id'] = $this->parentArea->getId();
         }
     }
     if ($this->cacheNeedsBuildingOnly) {
         $this->where[] = " area_information.cache_area_has_parent_generated = '0'";
     }
     if ($this->freeTextSearch) {
         $this->where[] = ' area_information.title ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
     if ($this->include_parent_levels > 0) {
         $this->joins[] = " LEFT JOIN area_information AS area_information_parent_1 ON area_information.parent_area_id = area_information_parent_1.id ";
         $this->select[] = " area_information_parent_1.title AS parent_1_title";
     }
 }
 public function infoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Does not exist.");
     }
     $out = array('country' => array('title' => $this->country->getTitle()));
     return json_encode($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);
 }
 /**
  * This will return one country only. It is intended for sites with one country only.
  **/
 public function loadBySite(SiteModel $site)
 {
     global $DB;
     $stat = $DB->prepare("SELECT country.* FROM country " . " JOIN country_in_site_information ON country_in_site_information.country_id = country.id AND country_in_site_information.is_in = '1' " . " WHERE country_in_site_information.site_id=:id ");
     $stat->execute(array('id' => $site->getId()));
     if ($stat->rowCount() > 0) {
         $country = new CountryModel();
         $country->setFromDataBaseRow($stat->fetch());
         return $country;
     }
 }
 public function fetchAll()
 {
     $this->buildStart();
     $this->build();
     $this->buildStat();
     $results = array();
     while ($data = $this->stat->fetch()) {
         $country = new CountryModel();
         $country->setFromDataBaseRow($data);
         $results[] = $country;
     }
     return $results;
 }
 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;
 }
 protected function build()
 {
     global $DB;
     $this->select[] = "  venue_information.* ";
     if ($this->site) {
         $this->where[] = " venue_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->country) {
         $this->where[] = " venue_information.country_id = :country_id ";
         $this->params['country_id'] = $this->country->getId();
     }
     if ($this->area) {
         $areaids = array($this->area->getId());
         $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id");
         $this->statAreas->execute(array('id' => $this->area->getId()));
         while ($d = $this->statAreas->fetch()) {
             $areaids[] = $d['area_id'];
         }
         $this->where[] = " venue_information.area_id IN (" . implode(",", $areaids) . ")";
     }
     if ($this->freeTextSearch) {
         $this->where[] = '(CASE WHEN venue_information.title IS NULL THEN \'\' ELSE venue_information.title END )  || \' \' || ' . '(CASE WHEN venue_information.description IS NULL THEN \'\' ELSE venue_information.description END ) || \' \' || ' . '(CASE WHEN venue_information.address IS NULL THEN \'\' ELSE venue_information.address END ) || \' \' || ' . '(CASE WHEN venue_information.address_code IS NULL THEN \'\' ELSE venue_information.address_code END ) ' . ' ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
     if ($this->freeTextSearchAddressCode) {
         $this->where[] = ' venue_information.address_code ILIKE :free_text_search_address_code ';
         $this->params['free_text_search_address_code'] = "%" . strtolower($this->freeTextSearchAddressCode) . "%";
     }
     if ($this->freeTextSearchAddress) {
         $this->where[] = 'venue_information.address ILIKE :free_text_search_address ';
         $this->params['free_text_search_address'] = "%" . strtolower($this->freeTextSearchAddress) . "%";
     }
     if ($this->freeTextSearchTitle) {
         $this->where[] = 'venue_information.title ILIKE :free_text_search_title ';
         $this->params['free_text_search_title'] = "%" . strtolower($this->freeTextSearchTitle) . "%";
     }
     if (!$this->include_deleted) {
         $this->where[] = " venue_information.is_deleted = '0' ";
     }
     if ($this->includeMediasSlugs) {
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_venue ON media_information.id = media_in_venue.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_venue.removal_approved_at IS NULL AND media_in_venue.venue_id = venue_information.id " . " GROUP BY venue_information.id ) AS media_venue_slugs ";
     }
     if ($this->must_have_lat_lng) {
         $this->where[] = " venue_information.lat IS NOT NULL ";
         $this->where[] = " venue_information.lng IS NOT NULL ";
     }
     if ($this->editedByUser) {
         $this->where[] = " venue_information.id IN (SELECT venue_id FROM venue_history WHERE user_account_id = :editedByUser) ";
         $this->params['editedByUser'] = $this->editedByUser->getId();
     }
 }
 public function go()
 {
     $event = new EventModel();
     $event->setSummary($this->summary);
     $event->setDescription($this->description);
     $event->setUrl($this->url);
     $event->setTimezone($this->timezone);
     $event->setStartAt($this->start_at);
     $event->setEndAt($this->end_at);
     $event->setCountryId($this->country->getId());
     $eventRepo = new EventRepository();
     $eventRepo->create($event, $this->site, $this->user, $this->group);
 }
 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;
 }
 protected function build()
 {
     global $DB;
     $this->select[] = 'event_information.*';
     $this->select[] = " group_information.title AS group_title ";
     $this->select[] = " group_information.id AS group_id ";
     $this->joins[] = " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL AND event_in_group.is_main_group = '1' ";
     $this->joins[] = " LEFT JOIN group_information ON group_information.id = event_in_group.group_id ";
     $joinsVenueInfoSQL = " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id ";
     if ($this->site) {
         $this->where[] = " event_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->group) {
         // We use a seperate table here so if event is in 2 groups and we select events in 1 group that isn't the main group only,
         // the normal event_in_group table still shows the main group.
         $this->joins[] = " JOIN event_in_group AS event_in_group_select ON event_in_group_select.event_id = event_information.id " . "AND event_in_group_select.removed_at IS NULL AND event_in_group_select.group_id = :group_id ";
         $this->params['group_id'] = $this->group->getId();
     }
     if ($this->country) {
         $this->where[] = " event_information.country_id = :country_id ";
         $this->params['country_id'] = $this->country->getId();
     }
     if ($this->area) {
         // We were doing
         // $this->joins[] = " LEFT JOIN cached_area_has_parent ON cached_area_has_parent.area_id = venue_information.area_id";
         // $this->where[] =  " (venue_information.area_id = :area_id OR  cached_area_has_parent.has_parent_area_id = :area_id )";
         // but then we got duplicates
         $areaids = array($this->area->getId());
         $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id");
         $this->statAreas->execute(array('id' => $this->area->getId()));
         while ($d = $this->statAreas->fetch()) {
             $areaids[] = $d['area_id'];
         }
         $this->joins[] = $joinsVenueInfoSQL;
         $this->where[] = " (venue_information.area_id IN (" . implode(",", $areaids) . ") " . "OR event_information.area_id IN (" . implode(",", $areaids) . ")) ";
     }
     if ($this->venue) {
         $this->where[] = " event_information.venue_id = :venue_id ";
         $this->params['venue_id'] = $this->venue->getId();
     }
     if ($this->importURL) {
         $this->joins[] = " LEFT JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id ";
         $this->joins[] = " LEFT JOIN imported_event ON imported_event.id = imported_event_is_event.imported_event_id ";
         $this->where[] = " (imported_event.import_url_id = :import_url_id OR event_information.import_url_id = :import_url_id )";
         $this->params['import_url_id'] = $this->importURL->getId();
     }
     if ($this->importedEvent) {
         $this->joins[] = " JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id AND imported_event_is_event.imported_event_id = :imported_event_id ";
         $this->params['imported_event_id'] = $this->importedEvent->getId();
     }
     if (!$this->site && !$this->group) {
         $this->joins[] = " JOIN site_information ON event_information.site_id = site_information.id ";
         $this->select[] = " site_information.slug AS site_slug ";
         if (!$this->includeEventsFromClosedSites) {
             $this->where[] = " site_information.is_closed_by_sys_admin = '0' ";
         }
     }
     if ($this->curatedList) {
         $this->joins[] = " LEFT JOIN event_in_curated_list ON event_in_curated_list.event_id = event_information.id " . " AND event_in_curated_list.removed_at IS NULL AND event_in_curated_list.curated_list_id = :curated_list";
         $this->joins[] = " LEFT JOIN  ( SELECT event_in_group.event_id, MAX(event_in_group.group_id) AS group_id" . " FROM event_in_group " . " JOIN group_in_curated_list ON group_in_curated_list.group_id = event_in_group.group_id " . " WHERE group_in_curated_list.curated_list_id = :curated_list AND group_in_curated_list.removed_at IS NULL AND event_in_group.removed_at IS NULL " . " GROUP BY event_in_group.event_id " . ") AS event_in_group_in_curated_list ON event_in_group_in_curated_list.event_id = event_information.id ";
         $this->where[] = " ( event_in_curated_list.curated_list_id IS NOT NULL OR event_in_group_in_curated_list.event_id IS NOT NULL )";
         $this->params['curated_list'] = $this->curatedList->getId();
         if ($this->curatedListInformation) {
             $this->joins[] = " LEFT JOIN group_information AS group_information_cl ON group_information_cl.id = event_in_group_in_curated_list.group_id ";
             $this->select[] = " (CASE WHEN event_in_curated_list.event_id IS NULL THEN 0 ELSE 1 END) AS is_event_in_curated_list ";
             $this->select[] = " group_information_cl.id AS in_curated_list_group_id ";
             $this->select[] = " group_information_cl.slug AS in_curated_list_group_slug ";
             $this->select[] = " group_information_cl.title AS in_curated_list_group_title ";
         }
     }
     if ($this->end) {
         $this->where[] = ' event_information.end_at = :end';
         $this->params['end'] = $this->end->format("Y-m-d H:i:s");
     } else {
         if ($this->after) {
             $this->where[] = ' event_information.end_at > :after';
             $this->params['after'] = $this->after->format("Y-m-d H:i:s");
         } else {
             if ($this->endBefore) {
                 $this->where[] = ' event_information.end_at < :before';
                 $this->params['before'] = $this->endBefore->format("Y-m-d H:i:s");
             }
         }
     }
     if ($this->start) {
         $this->where[] = ' event_information.start_at = :start';
         $this->params['start'] = $this->start->format("Y-m-d H:i:s");
     } else {
         if ($this->before) {
             $this->where[] = ' event_information.start_at < :before';
             $this->params['before'] = $this->before->format("Y-m-d H:i:s");
         } else {
             if ($this->startAfter) {
                 $this->where[] = ' event_information.start_at > :startAfter';
                 $this->params['startAfter'] = $this->startAfter->format("Y-m-d H:i:s");
             }
         }
     }
     if (!$this->include_deleted) {
         $this->where[] = " event_information.is_deleted = '0' ";
     }
     if (!$this->include_cancelled) {
         $this->where[] = " event_information.is_cancelled = '0' ";
     }
     if (!$this->include_imported) {
         $this->where[] = " event_information.import_url_id is null ";
     }
     if ($this->userAccount) {
         // user at event. we want info on this always for the extra selects, so outside if statement
         $this->joins[] = "  LEFT JOIN user_at_event_information ON user_at_event_information.event_id = event_information.id " . "AND user_at_event_information.user_account_id = :user_account_id ";
         $this->select[] = " user_at_event_information.is_plan_attending AS user_is_plan_attending ";
         $this->select[] = " user_at_event_information.is_plan_maybe_attending AS user_is_plan_maybe_attending ";
         if (!$this->userAccountIncludeAll) {
             $w = array();
             if ($this->userAccountIncludeWatching) {
                 $w[] = "  event_information.id IN (SELECT event_information.id FROM event_information " . " LEFT JOIN user_watches_site_information ON  user_watches_site_information.site_id = event_information.site_id " . "AND user_watches_site_information.user_account_id = :user_account_id AND user_watches_site_information.is_watching='1' " . "  LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL " . " LEFT JOIN user_watches_group_information ON user_watches_group_information.group_id = event_in_group.group_id " . "AND user_watches_group_information.user_account_id = :user_account_id AND user_watches_group_information.is_watching='1' " . " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id " . " LEFT JOIN cached_area_has_parent ON ( venue_information.area_id = cached_area_has_parent.area_id OR event_information.area_id = cached_area_has_parent.area_id) " . " LEFT JOIN user_watches_area_information ON ( " . "user_watches_area_information.area_id = event_information.area_id OR user_watches_area_information.area_id = venue_information.area_id " . " OR user_watches_area_information.area_id = cached_area_has_parent.has_parent_area_id " . ") " . "AND user_watches_area_information.user_account_id = :user_account_id AND user_watches_area_information.is_watching='1' " . " WHERE user_watches_site_information.is_watching='1' OR user_watches_group_information.is_watching='1'  OR user_watches_area_information.is_watching='1'" . " )  ";
             }
             if ($this->userAccountIncludeAttending) {
                 if ($this->userAccountIncludePrivate) {
                     $w[] = " user_at_event_information.is_plan_attending = '1' ";
                     $w[] = " user_at_event_information.is_plan_maybe_attending = '1' ";
                 } else {
                     $w[] = " (user_at_event_information.is_plan_attending = '1' AND user_at_event_information.is_plan_public  = '1' )";
                     $w[] = " (user_at_event_information.is_plan_maybe_attending = '1' AND user_at_event_information.is_plan_public  = '1' )";
                 }
             }
             $this->where[] = "  (  " . implode(" OR ", $w) . ") ";
         }
         $this->params['user_account_id'] = $this->userAccount->getId();
     }
     if ($this->include_venue_information || $this->include_area_information || $this->must_have_lat_lng) {
         if (!in_array($joinsVenueInfoSQL, $this->joins)) {
             $this->joins[] = $joinsVenueInfoSQL;
         }
         if ($this->include_venue_information) {
             $this->select[] = "  venue_information.lng AS venue_lng";
             $this->select[] = "  venue_information.lat AS venue_lat";
             $this->select[] = "  venue_information.title AS venue_title";
             $this->select[] = "  venue_information.slug AS venue_slug";
             $this->select[] = "  venue_information.description AS venue_description";
             $this->select[] = "  venue_information.address AS venue_address";
             $this->select[] = "  venue_information.address_code AS venue_address_code";
         }
         if ($this->include_area_information) {
             $this->joins[] = " LEFT JOIN area_information ON area_information.id = event_information.area_id OR area_information.id = venue_information.area_id";
             $this->select[] = "  area_information.title AS area_title";
             $this->select[] = "  area_information.slug AS area_slug";
             $this->select[] = "  area_information.id AS area_information_id";
             // we already have a area_id so called something different
         }
         if ($this->must_have_lat_lng) {
             $this->where[] = " venue_information.lat IS NOT NULL ";
             $this->where[] = " venue_information.lng IS NOT NULL ";
         }
     }
     if ($this->include_country_information) {
         $this->joins[] = " LEFT JOIN country ON country.id = event_information.country_id  ";
         $this->select[] = "  country.two_char_code AS country_two_char_code";
         $this->select[] = "  country.title AS country_title";
     }
     if ($this->venueVirtualOnly) {
         $this->where[] = " event_information.is_virtual = '1' ";
     }
     if ($this->event_recur_set_id) {
         $this->where[] = " event_information.event_recur_set_id = :event_recur_set_id ";
         $this->params['event_recur_set_id'] = $this->event_recur_set_id;
     }
     if ($this->tag) {
         $this->joins[] = "  JOIN event_has_tag ON event_has_tag.event_id = event_information.id AND  event_has_tag.tag_id = :tag_id AND event_has_tag.removed_at IS NULL";
         $this->params['tag_id'] = $this->tag->getId();
     }
     if ($this->freeTextSearch) {
         $this->where[] = '(CASE WHEN event_information.summary IS NULL THEN \'\' ELSE event_information.summary END)   || ' . '\' \' || ' . '(CASE WHEN event_information.description IS NULL THEN \'\' ELSE event_information.description END) || ' . '\' \' || ' . '(CASE WHEN group_information.title IS NULL THEN \'\' ELSE group_information.title END)' . ' ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
     if ($this->includeMediasSlugs) {
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_event ON media_information.id = media_in_event.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_event.removal_approved_at IS NULL AND media_in_event.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_event_slugs ";
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_group ON media_information.id = media_in_group.media_id " . " JOIN event_in_group ON event_in_group.group_id = media_in_group.group_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_group.removal_approved_at IS NULL " . " AND event_in_group.removal_approved_at IS NULL AND event_in_group.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_group_slugs ";
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_venue ON media_information.id = media_in_venue.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_venue.removal_approved_at IS NULL AND media_in_venue.venue_id = event_information.venue_id " . " GROUP BY event_information.venue_id ) AS media_venue_slugs ";
     }
     if ($this->editedByUser) {
         $this->where[] = " event_information.id IN (SELECT event_id FROM event_history WHERE user_account_id = :editedByUser) ";
         $this->params['editedByUser'] = $this->editedByUser->getId();
     }
 }
 public function doesCountryHaveAnyNotDeletedAreas(SiteModel $site, CountryModel $country)
 {
     global $DB;
     $stat = $DB->prepare("SELECT id FROM area_information WHERE site_id=:site_id AND country_id=:country_id AND is_deleted='0'");
     $stat->execute(array('site_id' => $site->getId(), 'country_id' => $country->getId()));
     return $stat->rowCount() > 0;
 }
 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;
 }