protected function build()
 {
     if ($this->event) {
         $this->where[] = " event_history.event_id = :event_id ";
         $this->params['event_id'] = $this->event->getId();
     }
 }
 protected function build()
 {
     $this->select = array('group_information.*');
     if ($this->site) {
         $this->where[] = " group_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->event) {
         $this->joins[] = " JOIN event_in_group AS event_in_group ON event_in_group.group_id = group_information.id " . "AND event_in_group.removed_at IS NULL AND event_in_group.event_id = :event_id ";
         $this->params['event_id'] = $this->event->getId();
     } else {
         if ($this->notEvent) {
             $this->joins[] = " LEFT JOIN event_in_group AS event_in_group ON event_in_group.group_id = group_information.id " . "AND event_in_group.removed_at IS NULL AND event_in_group.event_id = :event_id ";
             $this->params['event_id'] = $this->notEvent->getId();
             $this->where[] = '  event_in_group.event_id IS NULL ';
         }
     }
     if ($this->freeTextSearch) {
         $this->where[] = '(CASE WHEN group_information.title IS NULL THEN \'\' ELSE group_information.title END )  || \' \' || ' . '(CASE WHEN group_information.description IS NULL THEN \'\' ELSE group_information.description END )' . ' ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
     if (!$this->include_deleted) {
         $this->where[] = " group_information.is_deleted = '0' ";
     }
     if ($this->includeMediasSlugs) {
         $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 " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_group.removal_approved_at IS NULL AND media_in_group.group_id = group_information.id " . " GROUP BY group_information.id ) AS media_group_slugs ";
     }
     if ($this->editedByUser) {
         $this->where[] = " group_information.id IN (SELECT group_id FROM group_history WHERE user_account_id = :editedByUser) ";
         $this->params['editedByUser'] = $this->editedByUser->getId();
     }
 }
 protected function build()
 {
     if ($this->site) {
         $this->where[] = " human_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->humansForEvent) {
         $this->joins[] = "  JOIN event_has_human ON event_has_human.human_id = human_information.id AND  event_has_human.event_id = :event_id AND event_has_human.removed_at IS NULL";
         $this->params['event_id'] = $this->humansForEvent->getId();
     } else {
         if ($this->humansNotForEvent) {
             $this->joins[] = " LEFT JOIN event_has_human ON event_has_human.human_id = human_information.id AND  event_has_human.event_id = :event_id AND event_has_human.removed_at IS NULL";
             $this->params['event_id'] = $this->humansNotForEvent->getId();
             $this->where[] = ' event_has_human.event_id IS NULL ';
         }
     }
     if ($this->area) {
         // TODO direct areas only, should do child areas to. But not now.
         $this->joins[] = "  JOIN human_in_area ON human_in_area.human_id = human_information.id AND  human_in_area.area_id = :area_id AND human_in_area.removed_at IS NULL";
         $this->params['area_id'] = $this->area->getId();
     }
     if (!$this->include_deleted) {
         $this->where[] = " human_information.is_deleted = '0' ";
     }
     if ($this->freeTextSearch) {
         $this->where[] = '(CASE WHEN human_information.title IS NULL THEN \'\' ELSE human_information.title END )  || \' \' || ' . '(CASE WHEN human_information.description IS NULL THEN \'\' ELSE human_information.description END )' . ' ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
 }
 public function setFromAppAndEventAndEmail(Application $app, EventModel $eventModel, $email)
 {
     $this->event_id = $eventModel->getId();
     $this->email = $email;
     $this->subject = "Can we check the details of your event?";
     $venueRepo = new VenueRepository();
     $venue = null;
     if ($eventModel->getVenueId()) {
         $venue = $venueRepo->loadById($eventModel->getVenueId());
     }
     $area = null;
     $areaRepo = new AreaRepository();
     if ($eventModel->getAreaId()) {
         $area = $areaRepo->loadById($eventModel->getAreaId());
     } else {
         if ($venue && $venue->getAreaId()) {
             $area = $areaRepo->loadById($venue->getAreaId());
         }
     }
     $hrb = new HumanRepositoryBuilder();
     $hrb->setHumansForEvent($eventModel);
     $hrb->setIncludeDeleted(false);
     $humans = $hrb->fetchAll();
     $this->body_html = $app['twig']->render('email/organiserEmail.html.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans));
     if ($app['config']->isDebug) {
         file_put_contents('/tmp/organiserEmail.html', $this->body_html);
     }
     $this->body_text = $app['twig']->render('email/organiserEmail.txt.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans));
     if ($app['config']->isDebug) {
         file_put_contents('/tmp/organiserEmail.txt', $this->body_text);
     }
     $this->created_at = $app['timesource']->getDateTime();
 }
 public function hasBeenSentToEvent(EventModel $eventModel)
 {
     global $DB;
     $stat = $DB->prepare("SELECT id FROM organiser_email WHERE event_id = :id");
     $stat->execute(array('id' => $eventModel->getId()));
     return $stat->rowCount() > 0;
 }
 protected function build()
 {
     if ($this->eventOnly) {
         $this->where[] = ' user_at_event_information.event_id = :event_id ';
         $this->params['event_id'] = $this->eventOnly->getId();
     }
     if ($this->planAttendingMaybeOnly) {
         $this->where[] = " user_at_event_information.is_plan_maybe_attending =  '1' ";
     } elseif ($this->planAttendingYesOnly) {
         $this->where[] = " user_at_event_information.is_plan_attending =  '1' ";
     }
     if ($this->planPublicOnly) {
         $this->where[] = " user_at_event_information.is_plan_public =  '1' ";
     } elseif ($this->planPrivateOnly) {
         $this->where[] = " user_at_event_information.is_plan_public =  '0' ";
     }
 }
 protected function build()
 {
     $this->select[] = ' curated_list_information.* ';
     if ($this->userAccount) {
         $this->joins[] = " JOIN user_in_curated_list_information ON user_in_curated_list_information.curated_list_id = curated_list_information.id " . "AND user_in_curated_list_information.user_account_id = :user_account_id ";
         $this->params['user_account_id'] = $this->userAccount->getId();
         $this->where[] = " (user_in_curated_list_information.is_owner = '1' OR user_in_curated_list_information.is_editor = '1'  ) ";
     }
     if ($this->site) {
         $this->where[] = " curated_list_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->containsEvent) {
         $this->params['event_id'] = $this->containsEvent->getId();
         // event directly in list?
         $this->joins[] = " LEFT JOIN event_in_curated_list ON event_in_curated_list.curated_list_id = curated_list_information.id AND   " . " event_in_curated_list.event_id = :event_id AND event_in_curated_list.removed_at IS NULL ";
         // event in list via group?
         $this->joins[] = " LEFT JOIN ( SELECT group_in_curated_list.curated_list_id, MAX(group_in_curated_list.group_id) AS group_id FROM group_in_curated_list " . " JOIN event_in_group ON event_in_group.group_id = group_in_curated_list.group_id " . " WHERE event_in_group.event_id = :event_id AND group_in_curated_list.removed_at IS NULL AND event_in_group.removed_at IS NULL " . " GROUP BY group_in_curated_list.curated_list_id ) AS event_in_curated_list_via_group_table ON event_in_curated_list_via_group_table.curated_list_id = curated_list_information.id ";
         $this->where[] = " (event_in_curated_list.added_at IS NOT NULL OR event_in_curated_list_via_group_table.group_id IS NOT NULL) ";
     } else {
         if ($this->eventInfo) {
             $this->params['event_id'] = $this->eventInfo->getId();
             // event directly in list?
             $this->joins[] = " LEFT JOIN event_in_curated_list ON event_in_curated_list.curated_list_id = curated_list_information.id AND   " . " event_in_curated_list.event_id = :event_id AND event_in_curated_list.removed_at IS NULL ";
             $this->select[] = " event_in_curated_list.added_at AS is_event_in_list ";
             // event in list via group?
             $this->joins[] = " LEFT JOIN ( SELECT group_in_curated_list.curated_list_id, MAX(group_in_curated_list.group_id) AS group_id FROM group_in_curated_list " . " JOIN event_in_group ON event_in_group.group_id = group_in_curated_list.group_id " . " WHERE event_in_group.event_id = :event_id AND group_in_curated_list.removed_at IS NULL AND event_in_group.removed_at IS NULL " . " GROUP BY group_in_curated_list.curated_list_id ) AS event_in_curated_list_via_group_table ON event_in_curated_list_via_group_table.curated_list_id = curated_list_information.id ";
             $this->select[] = " event_in_curated_list_via_group_table.group_id AS event_in_list_via_group_id ";
         }
     }
     if ($this->containsGroup) {
         $this->joins[] = " LEFT JOIN group_in_curated_list ON group_in_curated_list.curated_list_id = curated_list_information.id AND   " . " group_in_curated_list.group_id = :group_id AND group_in_curated_list.removed_at IS NULL ";
         $this->params['group_id'] = $this->containsGroup->getId();
         $this->where[] = " group_in_curated_list.added_at IS NOT NULL ";
     } else {
         if ($this->groupInfo) {
             $this->joins[] = " LEFT JOIN group_in_curated_list ON group_in_curated_list.curated_list_id = curated_list_information.id AND   " . " group_in_curated_list.group_id = :group_id AND group_in_curated_list.removed_at IS NULL ";
             $this->params['group_id'] = $this->groupInfo->getId();
             $this->select[] = " group_in_curated_list.added_at AS is_group_in_list ";
         }
     }
     if (!$this->include_deleted) {
         $this->where[] = " curated_list_information.is_deleted = '0' ";
     }
 }
 protected function build()
 {
     if ($this->site) {
         $this->where[] = " tag_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->tagsForEvent) {
         $this->joins[] = "  JOIN event_has_tag ON event_has_tag.tag_id = tag_information.id AND  event_has_tag.event_id = :event_id AND event_has_tag.removed_at IS NULL";
         $this->params['event_id'] = $this->tagsForEvent->getId();
     } else {
         if ($this->tagsNotForEvent) {
             $this->joins[] = " LEFT JOIN event_has_tag ON event_has_tag.tag_id = tag_information.id AND  event_has_tag.event_id = :event_id AND event_has_tag.removed_at IS NULL";
             $this->params['event_id'] = $this->tagsNotForEvent->getId();
             $this->where[] = ' event_has_tag.event_id IS NULL ';
         }
     }
     if (!$this->include_deleted) {
         $this->where[] = " tag_information.is_deleted = '0' ";
     }
 }
 public function create(EventCommentModel $eventComment, EventModel $event, UserAccountModel $creator)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("SELECT max(slug) AS c FROM event_comment_information WHERE event_id=:event_id");
         $stat->execute(array('event_id' => $event->getId()));
         $data = $stat->fetch();
         $eventComment->setSlug($data['c'] + 1);
         $stat = $DB->prepare("INSERT INTO event_comment_information (event_id, slug, title, comment, user_account_id, is_deleted, created_at, approved_at) " . "VALUES (:event_id, :slug, :title, :comment, :user_account_id, '0', :created_at, :approved_at) RETURNING id");
         $stat->execute(array('event_id' => $event->getId(), 'slug' => $eventComment->getSlug(), 'title' => substr($eventComment->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'comment' => $eventComment->getComment(), 'user_account_id' => $creator->getId(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase()));
         $data = $stat->fetch();
         $eventComment->setId($data['id']);
         $stat = $DB->prepare("INSERT INTO event_comment_history (event_comment_id, title, comment, user_account_id, is_deleted, created_at, approved_at, is_new) VALUES " . "(:event_comment_id, :title, :comment, :user_account_id, '0', :created_at, :approved_at, '1')");
         $stat->execute(array('event_comment_id' => $eventComment->getId(), 'title' => substr($eventComment->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'comment' => $eventComment->getComment(), 'user_account_id' => $creator->getId(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase()));
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 public function loadByEvent(EventModel $event)
 {
     global $DB;
     $stat = $DB->prepare("SELECT imported_event.* FROM imported_event " . " LEFT JOIN imported_event_is_event ON imported_event_is_event.imported_event_id = imported_event.id " . "WHERE imported_event_is_event.event_id = :id");
     $stat->execute(array('id' => $event->getId()));
     if ($stat->rowCount() > 0) {
         $event = new ImportedEventModel();
         $event->setFromDataBaseRow($stat->fetch());
         return $event;
     }
 }
 /** @return UserAtEventModel **/
 public function loadByUserIDAndEvent($userId, EventModel $event)
 {
     global $DB;
     $stat = $DB->prepare("SELECT user_at_event_information.* FROM user_at_event_information WHERE user_account_id =:user_account_id AND event_id=:event_id");
     $stat->execute(array('user_account_id' => $userId, 'event_id' => $event->getId()));
     if ($stat->rowCount() > 0) {
         $uaem = new UserAtEventModel();
         $uaem->setFromDataBaseRow($stat->fetch());
         return $uaem;
     }
 }
 protected function build()
 {
     if ($this->site) {
         $this->where[] = " media_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->group) {
         $this->joins[] = " JOIN media_in_group AS media_in_group ON media_in_group.media_id = media_information.id " . "AND media_in_group.removed_at IS NULL AND media_in_group.group_id = :group_id ";
         $this->params['group_id'] = $this->group->getId();
     } else {
         if ($this->groupNotIn) {
             $this->joins[] = " LEFT JOIN media_in_group AS media_in_group ON media_in_group.media_id = media_information.id " . "AND media_in_group.removed_at IS NULL AND media_in_group.group_id = :group_id ";
             $this->where[] = " media_in_group.added_at IS NULL ";
             $this->params['group_id'] = $this->groupNotIn->getId();
         }
     }
     if ($this->venue) {
         $this->joins[] = " JOIN media_in_venue AS media_in_venue ON media_in_venue.media_id = media_information.id " . "AND media_in_venue.removed_at IS NULL AND media_in_venue.venue_id = :venue_id ";
         $this->params['venue_id'] = $this->venue->getId();
     } else {
         if ($this->venueNotIn) {
             $this->joins[] = " LEFT JOIN media_in_venue AS media_in_venue ON media_in_venue.media_id = media_information.id " . "AND media_in_venue.removed_at IS NULL AND media_in_venue.venue_id = :venue_id ";
             $this->where[] = " media_in_venue.added_at IS NULL ";
             $this->params['venue_id'] = $this->venueNotIn->getId();
         }
     }
     if ($this->event) {
         $this->joins[] = " JOIN media_in_event AS media_in_event ON media_in_event.media_id = media_information.id " . "AND media_in_event.removed_at IS NULL AND media_in_event.event_id = :event_id ";
         $this->params['event_id'] = $this->event->getId();
     } else {
         if ($this->eventNotIn) {
             $this->joins[] = " LEFT JOIN media_in_event AS media_in_event ON media_in_event.media_id = media_information.id " . "AND media_in_event.removed_at IS NULL AND media_in_event.event_id = :event_id ";
             $this->where[] = " media_in_event.added_at IS NULL ";
             $this->params['event_id'] = $this->eventNotIn->getId();
         }
     }
     if (!$this->include_deleted) {
         $this->where[] = " media_information.deleted_at IS NULL ";
     }
 }
 public function removeEventFromCuratedList(EventModel $event, CuratedListModel $curatedList, UserAccountModel $user)
 {
     global $DB;
     $stat = $DB->prepare("UPDATE event_in_curated_list SET removed_by_user_account_id=:removed_by_user_account_id," . " removed_at=:removed_at WHERE " . " event_id=:event_id AND curated_list_id=:curated_list_id AND removed_at IS NULL ");
     $stat->execute(array('event_id' => $event->getId(), 'curated_list_id' => $curatedList->getId(), 'removed_at' => \TimeSource::getFormattedForDataBase(), 'removed_by_user_account_id' => $user->getId()));
 }
 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 createLink(ImportedEventModel $importedEvent, EventModel $event)
 {
     global $DB;
     $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()));
 }
 public function remove(MediaModel $media, EventModel $event, UserAccountModel $user)
 {
     global $DB;
     $stat = $DB->prepare("UPDATE media_in_event SET removed_by_user_account_id=:removed_by_user_account_id," . " removed_at=:removed_at, removal_approved_at=:removal_approved_at WHERE " . " event_id=:event_id AND media_id=:media_id AND removed_at IS NULL ");
     $stat->execute(array('event_id' => $event->getId(), 'media_id' => $media->getId(), 'removed_at' => \TimeSource::getFormattedForDataBase(), 'removal_approved_at' => \TimeSource::getFormattedForDataBase(), 'removed_by_user_account_id' => $user->getId()));
 }
 public function removeHumanFromEvent(HumanModel $human, EventModel $event, UserAccountModel $user = null)
 {
     global $DB;
     $stat = $DB->prepare("UPDATE event_has_human SET removed_by_user_account_id=:removed_by_user_account_id," . " removed_at=:removed_at, removal_approved_at=:removal_approved_at WHERE " . " event_id=:event_id AND human_id=:human_id AND removed_at IS NULL ");
     $stat->execute(array('event_id' => $event->getId(), 'human_id' => $human->getId(), 'removed_at' => \TimeSource::getFormattedForDataBase(), 'removal_approved_at' => \TimeSource::getFormattedForDataBase(), 'removed_by_user_account_id' => $user ? $user->getId() : null));
 }
 public function purge(EventModel $event)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("UPDATE event_history SET is_duplicate_of_id=NULL, is_duplicate_of_id_changed=0 WHERE is_duplicate_of_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("UPDATE event_information SET is_duplicate_of_id=NULL WHERE is_duplicate_of_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM event_in_group WHERE event_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM user_at_event_information WHERE event_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM event_in_curated_list WHERE event_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM event_has_tag WHERE event_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM event_history WHERE event_id=:id");
         $stat->execute(array('id' => $event->getId()));
         $stat = $DB->prepare("DELETE FROM event_information WHERE id=:id");
         $stat->execute(array('id' => $event->getId()));
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
         throw $e;
     }
 }
 public function markIsDuplicateOf(NewEventDraftModel $newEventDraftModel, EventModel $eventModel)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("UPDATE new_event_draft_information SET was_existing_event_id=:was_existing_event_id, updated_at=:updated_at WHERE id=:id");
         $stat->execute(array('id' => $newEventDraftModel->getId(), 'was_existing_event_id' => $eventModel->getId(), 'updated_at' => \TimeSource::getFormattedForDataBase()));
         $stat = $DB->prepare("INSERT INTO new_event_draft_history (new_event_draft_id, was_existing_event_id, user_account_id,created_at,details_changed,event_id_changed,not_duplicate_events_changed) " . "VALUES (:new_event_draft_id, :was_existing_event_id, :user_account_id,:created_at,-2,-2,-2 )");
         $stat->execute(array('new_event_draft_id' => $newEventDraftModel->getId(), 'was_existing_event_id' => $eventModel->getId(), 'user_account_id' => $newEventDraftModel->getUserAccountId() ? $newEventDraftModel->getUserAccountId() : null, 'created_at' => \TimeSource::getFormattedForDataBase()));
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 public function loadByEventAndlastEditByUser(EventModel $event, UserAccountModel $user)
 {
     global $DB;
     $stat = $DB->prepare("SELECT event_history.* FROM event_history " . " WHERE event_history.event_id = :id AND event_history.user_account_id = :user " . " ORDER BY event_history.created_at DESc");
     $stat->execute(array('id' => $event->getId(), 'user' => $user->getId()));
     if ($stat->rowCount() > 0) {
         $event = new EventHistoryModel();
         $event->setFromDataBaseRow($stat->fetch());
         return $event;
     }
 }
 public function setMainGroupForEvent(GroupModel $group, EventModel $event, UserAccountModel $user = null)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         // check group in event first
         $stat = $DB->prepare("SELECT * FROM event_in_group WHERE group_id=:group_id AND " . " event_id=:event_id AND removed_at IS NULL ");
         $stat->execute(array('group_id' => $group->getId(), 'event_id' => $event->getId()));
         if ($stat->rowCount() > 0) {
             // set main group
             $stat = $DB->prepare("UPDATE event_in_group SET is_main_group='1' WHERE event_id=:event_id AND removed_at IS NULL " . "AND group_id = :group_id");
             $stat->execute(array('event_id' => $event->getId(), 'group_id' => $group->getId()));
             // remove others
             $stat = $DB->prepare("UPDATE event_in_group SET is_main_group='0' WHERE event_id=:event_id AND removed_at IS NULL " . "AND group_id != :group_id");
             $stat->execute(array('event_id' => $event->getId(), 'group_id' => $group->getId()));
         }
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }