public function getForImportedEvent(ImportedEventModel $importedEventModel)
 {
     global $DB;
     $stat = $DB->prepare("SELECT event_recur_set.* FROM event_recur_set " . " JOIN event_information ON event_information.event_recur_set_id = event_recur_set.id " . " JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id " . " WHERE imported_event_is_event.imported_event_id = :id");
     $stat->execute(array('id' => $importedEventModel->getId()));
     if ($stat->rowCount() > 0) {
         $ers = new EventRecurSetModel();
         $ers->setFromDataBaseRow($stat->fetch());
         return $ers;
     }
 }
 public function fetchAll()
 {
     $this->buildStart();
     $this->build();
     $this->buildStat();
     $results = array();
     while ($data = $this->stat->fetch()) {
         $event = new ImportedEventModel();
         $event->setFromDataBaseRow($data);
         $results[] = $event;
     }
     return $results;
 }
 function __construct(ImportedEventModel $importedEvent)
 {
     $reoccur = $importedEvent->getReoccur();
     if (isset($reoccur) && isset($reoccur['ical_rrule']) && $reoccur['ical_rrule']) {
         $icaldata = new ICalData(clone $importedEvent->getStartAt(), clone $importedEvent->getEndAt(), $reoccur['ical_rrule'], $importedEvent->getTimezone());
         if (isset($reoccur['ical_exdates']) && is_array($reoccur['ical_exdates'])) {
             foreach ($reoccur['ical_exdates'] as $exdate) {
                 $icaldata->addExDateByString($exdate['values'], $exdate['properties']);
             }
         }
         $unraveler = new Unraveler($icaldata);
         $unraveler->setIncludeOriginalEvent(true);
         $unraveler->process();
         $results = $unraveler->getResults();
         foreach ($results as $wantedTimes) {
             $newImportedOccurrenceEvent = new ImportedEventOccurrenceModel();
             $newImportedOccurrenceEvent->setFromImportedEventModel($importedEvent);
             $newImportedOccurrenceEvent->setStartAt($wantedTimes->getStart());
             $newImportedOccurrenceEvent->setEndAt($wantedTimes->getEnd());
             $this->importedEventOccurrences[] = $newImportedOccurrenceEvent;
         }
         $this->toMultiples = true;
     } else {
         // If not a reoccuring event, there will still be 1 occurence .....
         $newImportedOccurrenceEvent = new ImportedEventOccurrenceModel();
         $newImportedOccurrenceEvent->setFromImportedEventModel($importedEvent);
         $this->importedEventOccurrences[] = $newImportedOccurrenceEvent;
         $this->toMultiples = false;
     }
 }
 public function delete(ImportedEventModel $importedEvent)
 {
     global $DB;
     $stat = $DB->prepare("UPDATE imported_event SET is_deleted='1' WHERE id=:id");
     $stat->execute(array('id' => $importedEvent->getId()));
 }
 protected function setImportedEventFromMeetupData(ImportedEventModel $importedEvent, $meetupData)
 {
     $changesToSave = false;
     if (property_exists($meetupData, 'description')) {
         $description = $meetupData->description;
         var_dump($description);
         if ($importedEvent->getDescription() != $description) {
             $importedEvent->setDescription($description);
             $changesToSave = true;
         }
     }
     $start = new \DateTime('', new \DateTimeZone('UTC'));
     $start->setTimestamp($meetupData->time / 1000);
     if (property_exists($meetupData, 'duration') && $meetupData->duration) {
         $end = new \DateTime('', new \DateTimeZone('UTC'));
         $end->setTimestamp($meetupData->time / 1000);
         $end->add(new \DateInterval("PT" . $meetupData->duration / 1000 . "S"));
     } else {
         $end = clone $start;
         $end->add(new \DateInterval("PT3H"));
     }
     if (!$importedEvent->getStartAt() || $importedEvent->getStartAt()->getTimeStamp() != $start->getTimeStamp()) {
         $importedEvent->setStartAt($start);
         $changesToSave = true;
     }
     if (!$importedEvent->getEndAt() || $importedEvent->getEndAt()->getTimeStamp() != $end->getTimeStamp()) {
         $importedEvent->setEndAt($end);
         $changesToSave = true;
     }
     if ($importedEvent->getTitle() != $meetupData->name) {
         $importedEvent->setTitle($meetupData->name);
         $changesToSave = true;
     }
     if ($importedEvent->getUrl() != $meetupData->event_url) {
         $importedEvent->setUrl($meetupData->event_url);
         $changesToSave = true;
     }
     if ($importedEvent->getTimezone() != $meetupData->timezone) {
         $importedEvent->setTimezone($meetupData->timezone);
         $changesToSave = true;
     }
     if ($importedEvent->getTicketUrl() != $meetupData->event_url) {
         $importedEvent->setTicketUrl($meetupData->event_url);
         $changesToSave = true;
     }
     return $changesToSave;
 }
 protected function setOurEventFromEventObject(ImportedEventModel $importedEvent, $event)
 {
     $changesToSave = false;
     if ($importedEvent->getTitle() != $event->eventTitle) {
         $importedEvent->setTitle($event->eventTitle);
         $changesToSave = true;
     }
     $description = $event->eventDetails . "\n\n";
     $description .= $event->additionalInfo . "\n\n";
     $description .= $event->practicalities . "\n\n";
     $description .= $event->contactName . "\n";
     $description .= $event->organisation . "\n";
     $description .= $event->contactEmail . "\n";
     $description .= $event->contactPhone . "\n";
     $description .= $event->organisedBy . "\n";
     $description .= $event->eventLocation . "\n";
     $description .= $event->constitName . "\n";
     $description .= $event->eventPostcode . "\n";
     $description .= $event->eventDate . " " . $event->eventTime . "\n";
     if ($importedEvent->getDescription() != $description) {
         $importedEvent->setDescription($description);
         $changesToSave = true;
     }
     if ($importedEvent->getUrl() != $event->url) {
         $importedEvent->setUrl($event->url);
         $changesToSave = true;
     }
     $importedEvent->setTimezone("Europe/London");
     $p = new ParseDateTimeRangeString(TimeSource::getDateTime(), "Europe/London");
     $r = $p->parse($event->eventDate . " " . $event->eventTime);
     if (!$importedEvent->getStartAt() || $importedEvent->getStartAt()->getTimeStamp() != $r->getStart()->getTimeStamp()) {
         $importedEvent->setStartAt(clone $r->getStart());
         $changesToSave = true;
     }
     if (!$importedEvent->getEndAt() || $importedEvent->getEndAt()->getTimeStamp() != $r->getEnd()->getTimeStamp()) {
         $importedEvent->setEndAt(clone $r->getEnd());
         $changesToSave = true;
     }
     return $changesToSave;
 }
 /**
  * @dataProvider dataForTestReoccurIfDifferentFalse
  */
 public function testReoccurIfDifferentFalse($first, $second)
 {
     $iem = new ImportedEventModel();
     $iem->setReoccur(array('ical_rrule' => $first));
     $this->assertTrue($iem->setReoccurIfDifferent(array('ical_rrule' => $second)));
 }
 /**
  * 
  * This is a bit broken - in theory this could return multiple events (in the case of a imported event with recurrence) 
  * But for now that can't happen so just return one event.
  * 
  * @global \repositories\type $DB
  * @param \models\ImportedEventModel $importedEvent
  * @return \models\EventModel
  */
 public function loadByImportedEvent(\models\ImportedEventModel $importedEvent)
 {
     global $DB;
     $stat = $DB->prepare("SELECT event_information.*, group_information.title AS group_title, group_information.id AS group_id  FROM event_information " . " JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id " . " 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' " . " LEFT JOIN group_information ON group_information.id = event_in_group.group_id " . " WHERE imported_event_is_event.imported_event_id = :id");
     $stat->execute(array('id' => $importedEvent->getId()));
     if ($stat->rowCount() > 0) {
         $event = new EventModel();
         $event->setFromDataBaseRow($stat->fetch());
         return $event;
     }
 }
 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()));
 }
 protected function setImportedEventFromFBData(ImportedEventModel $importedEvent, $fbData)
 {
     $changesToSave = false;
     if ($importedEvent->getDescription() != $fbData['description']) {
         $importedEvent->setDescription($fbData['description']);
         $changesToSave = true;
     }
     $start = new \DateTime($fbData['start_time'], new \DateTimeZone('UTC'));
     if ($fbData['end_time']) {
         $end = new \DateTime($fbData['end_time'], new \DateTimeZone('UTC'));
     } else {
         $end = clone $start;
     }
     if ($fbData['is_date_only']) {
         $start->setTime(0, 0, 0);
         $end->setTime(23, 59, 59);
     }
     if (!$importedEvent->getStartAt() || $importedEvent->getStartAt()->getTimeStamp() != $start->getTimeStamp()) {
         $importedEvent->setStartAt($start);
         $changesToSave = true;
     }
     if (!$importedEvent->getEndAt() || $importedEvent->getEndAt()->getTimeStamp() != $end->getTimeStamp()) {
         $importedEvent->setEndAt($end);
         $changesToSave = true;
     }
     if ($importedEvent->getTitle() != $fbData['name']) {
         $importedEvent->setTitle($fbData['name']);
         $changesToSave = true;
     }
     if ($importedEvent->getUrl() != $fbData['url']) {
         $importedEvent->setUrl($fbData['url']);
         $changesToSave = true;
     }
     if ($importedEvent->getTimezone() != $fbData['timezone']) {
         $importedEvent->setTimezone($fbData['timezone']);
         $changesToSave = true;
     }
     if ($importedEvent->getTicketUrl() != $fbData['ticket_uri']) {
         $importedEvent->setTicketUrl($fbData['ticket_uri']);
         $changesToSave = true;
     }
     return $changesToSave;
 }
 protected function setOurEventFromIcalEvent(ImportedEventModel $importedEvent, ICalEvent $icalevent)
 {
     $changesToSave = false;
     if ($importedEvent->getDescription() != $icalevent->getDescription()) {
         $importedEvent->setDescription($icalevent->getDescription());
         $changesToSave = true;
     }
     if ($importedEvent->getTimezone() != $this->icalParser->getTimeZoneIdentifier()) {
         $importedEvent->setTimezone($this->icalParser->getTimeZoneIdentifier());
         $changesToSave = true;
     }
     if (!$importedEvent->getStartAt() || $importedEvent->getStartAt()->getTimeStamp() != $icalevent->getStart()->getTimeStamp()) {
         $importedEvent->setStartAt(clone $icalevent->getStart());
         $changesToSave = true;
     }
     if (!$importedEvent->getEndAt() || $importedEvent->getEndAt()->getTimeStamp() != $icalevent->getEnd()->getTimeStamp()) {
         $importedEvent->setEndAt(clone $icalevent->getEnd());
         $changesToSave = true;
     }
     if ($importedEvent->getTitle() != $icalevent->getSummary()) {
         $importedEvent->setTitle($icalevent->getSummary());
         $changesToSave = true;
     }
     if ($importedEvent->getUrl() != $icalevent->getUrl()) {
         $importedEvent->setUrl($icalevent->getUrl());
         $changesToSave = true;
     }
     if ($this->importURLRun->hasFlag(ImportURLRun::$FLAG_SET_TICKET_URL_AS_URL) && $importedEvent->getTicketUrl() != $icalevent->getUrl()) {
         $importedEvent->setTicketUrl($icalevent->getUrl());
         $changesToSave = true;
     }
     if ($icalevent->getRRule()) {
         $reoccur = array('ical_rrule' => $icalevent->getRRule(), 'ical_exdates' => array());
         foreach ($icalevent->getExDates() as $exDate) {
             $reoccur['ical_exdates'][] = array('properties' => $exDate->getProperties(), 'values' => $exDate->getValues());
         }
     } else {
         $reoccur = array();
     }
     if ($importedEvent->setReoccurIfDifferent($reoccur)) {
         $changesToSave = true;
     }
     return $changesToSave;
 }