function test3()
 {
     TimeSource::mock(2013, 3, 1, 9, 0, 0);
     $event = new EventModel();
     $event->setStartAt($this->mktime(2013, 3, 1, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 3, 1, 21, 0, 0));
     $eventSet = new EventRecurSetModel();
     $eventSet->setTimeZoneName('Europe/London');
     $newEvents = $eventSet->getNewWeeklyEvents($event, 60);
     $this->assertTrue(count($newEvents) >= 8);
     $this->assertEquals($this->mktime(2013, 3, 8, 19, 0, 0)->format('r'), $newEvents[0]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 8, 21, 0, 0)->format('r'), $newEvents[0]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 15, 19, 0, 0)->format('r'), $newEvents[1]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 15, 21, 0, 0)->format('r'), $newEvents[1]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 22, 19, 0, 0)->format('r'), $newEvents[2]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 22, 21, 0, 0)->format('r'), $newEvents[2]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 29, 19, 0, 0)->format('r'), $newEvents[3]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 3, 29, 21, 0, 0)->format('r'), $newEvents[3]->getEndAt()->format('r'));
     ### at his point DST kicks in and since we are getting data times (in UTC) they shifn by an hour.
     $this->assertEquals($this->mktime(2013, 4, 5, 18, 0, 0)->format('r'), $newEvents[4]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 5, 20, 0, 0)->format('r'), $newEvents[4]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 12, 18, 0, 0)->format('r'), $newEvents[5]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 12, 20, 0, 0)->format('r'), $newEvents[5]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 19, 18, 0, 0)->format('r'), $newEvents[6]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 19, 20, 0, 0)->format('r'), $newEvents[6]->getEndAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 26, 18, 0, 0)->format('r'), $newEvents[7]->getStartAt()->format('r'));
     $this->assertEquals($this->mktime(2013, 4, 26, 20, 0, 0)->format('r'), $newEvents[7]->getEndAt()->format('r'));
 }
 /**
  * @dataProvider dataForTestSet
  */
 function testSet4($slug, $text, $result)
 {
     $event = new EventModel();
     $event->setSlug($slug);
     $event->setSummary($text);
     $this->assertEquals($result, $event->getSlugForUrl());
 }
 public function postInfoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Does not exist.");
     }
     $ourRequest = new \Request($request);
     $edits = false;
     if ($ourRequest->hasGetOrPost('summary') && $this->event->setSummaryIfDifferent($ourRequest->getGetOrPostString('summary', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('description') && $this->event->setDescriptionIfDifferent($ourRequest->getGetOrPostString('description', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('url') && $this->event->setUrlIfDifferent($ourRequest->getGetOrPostString('url', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('ticket_url') && $this->event->setTicketUrlIfDifferent($ourRequest->getGetOrPostString('ticket_url', ''))) {
         $edits = true;
     }
     if ($edits) {
         $repo = new EventRepository();
         $repo->edit($this->event, $app['apiUser']);
         $out = array('edited' => true);
     } else {
         $out = array('edited' => false);
     }
     return json_encode($out);
 }
 function testWinterTime()
 {
     TimeSource::mock(2014, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt($this->mktime(2014, 11, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt($this->mktime(2014, 11, 10, 21, 0, 0, 'Europe/London'));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals("test test", $event->getDescription());
     $this->assertEquals("test", $event->getSummary());
     $startAtShouldBe = $this->mktime(2014, 11, 10, 19, 0, 0, 'UTC');
     $startAtIs = clone $event->getStartAt();
     $startAtIs->setTimezone(new \DateTimeZone('UTC'));
     $this->assertEquals($startAtShouldBe->format("c"), $startAtIs->format("c"));
 }
 function testCustomFieldChange1()
 {
     TimeSource::mock(2013, 3, 1, 9, 0, 0);
     $customFieldDefinition1 = new EventCustomFieldDefinitionModel();
     $customFieldDefinition1->setId(1);
     $customFieldDefinition1->setExtensionId('org.openacalendar');
     $customFieldDefinition1->setType('TextSingleLine');
     $customFieldDefinition1->setKey('cats');
     $customFieldDefinition1->setLabel('cats');
     $event = new EventModel();
     $event->setStartAt(getUTCDateTime(2013, 3, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 3, 1, 21, 0, 0));
     $event->setCustomField($customFieldDefinition1, "MANY");
     $eventSet = new EventRecurSetModel();
     $eventSet->setTimeZoneName('Europe/London');
     $eventSet->setCustomFields(array($customFieldDefinition1));
     $newEvents = $eventSet->getNewWeeklyEvents($event, 60);
     $this->assertTrue(count($newEvents) >= 8);
     $this->assertTrue($newEvents[0]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[0]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[1]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[1]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[2]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[2]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[3]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[3]->getCustomField($customFieldDefinition1));
     // DST shift happens here! The cats do not care.
     $this->assertTrue($newEvents[4]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[4]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[5]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[5]->getCustomField($customFieldDefinition1));
 }
 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) . "%";
     }
 }
 function test1()
 {
     TimeSource::mock(2014, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventDupe = new EventModel();
     $eventDupe->setSummary("test");
     $eventDupe->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $eventDupe->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     $eventRepository->create($eventDupe, $site, $user, $group);
     TimeSource::mock(2014, 5, 1, 7, 1, 0);
     $eventRepository->markDuplicate($eventDupe, $event);
     $userAtEvent = new \models\UserAtEventModel();
     $userAtEvent->setEventId($event->getId());
     $userAtEvent->setUserAccountId($user->getId());
     $userAtEvent->setIsPlanAttending(true);
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $userAtEventRepo->create($userAtEvent);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $tag = new TagModel();
     $tag->setTitle("Test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $tagRepo->addTagToEvent($tag, $event, $user);
     ## TEST
     $this->assertNotNull($eventRepository->loadBySlug($site, $event->getSlug()));
     ## PURGE!
     $eventRepository->purge($event);
     ## TEST
     $this->assertNull($eventRepository->loadBySlug($site, $event->getSlug()));
 }
 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()
 {
     $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();
     }
 }
 function testEndAfterStart()
 {
     $event = new EventModel();
     $event->setStartAt(getUTCDateTime(2013, 8, 01, 18, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 01, 17, 0, 0));
     $this->assertEquals(false, $event->validate());
 }
 /**
  * @dataProvider dataForTestWithGroup
  */
 function testWithGroup($groupTitle, $eventSummary, $summaryDisplayOut)
 {
     $event = new EventModel();
     $event->setSummary($eventSummary);
     $event->setGroupTitle($groupTitle);
     $this->assertEquals($summaryDisplayOut, $event->getSummaryDisplay());
 }
 protected function build()
 {
     if ($this->event) {
         $this->where[] = " event_history.event_id = :event_id ";
         $this->params['event_id'] = $this->event->getId();
     }
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $user1 = new UserAccountModel();
     $user1->setEmail("*****@*****.**");
     $user1->setUsername("test");
     $user1->setPassword("password");
     $user2 = new UserAccountModel();
     $user2->setEmail("*****@*****.**");
     $user2->setUsername("test2");
     $user2->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user1);
     $userRepo->create($user2);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user1, array(), $this->getSiteQuotaUsedForTesting());
     $group1 = new GroupModel();
     $group1->setTitle("test1");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test this looks similar");
     $group2->setDescription("test test");
     $group2->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $groupRepo->create($group1, $site, $user1);
     $groupRepo->create($group2, $site, $user2);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user1, $group2);
     $uwgr = new UserWatchesGroupRepository();
     // Test before
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(0, count($erb->fetchAll()));
     $this->assertNull($uwgr->loadByUserAndGroup($user2, $group1));
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertFalse($group2->getIsDeleted());
     $this->assertNull($group2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $groupRepo->markDuplicate($group2, $group1, $user1);
     // Test Duplicate
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(1, count($erb->fetchAll()));
     $uwg = $uwgr->loadByUserAndGroup($user2, $group1);
     $this->assertNotNull($uwg);
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertTrue($group2->getIsDeleted());
     $this->assertEquals($group1->getId(), $group2->getIsDuplicateOfId());
 }
 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;
     }
 }
 public function loadForEvent(EventModel $event)
 {
     global $DB;
     if ($event->getEventRecurSetId()) {
         $stat = $DB->prepare("SELECT event_recur_set.* FROM event_recur_set WHERE id =:id");
         $stat->execute(array('id' => $event->getEventRecurSetId()));
         if ($stat->rowCount() > 0) {
             $eventRecurSet = new EventRecurSetModel();
             $eventRecurSet->setFromDataBaseRow($stat->fetch());
             return $eventRecurSet;
         }
     }
 }
 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' ";
     }
 }
 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();
 }
 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' ";
     }
 }
 function testAcrossBST1()
 {
     \TimeSource::mock(2015, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setTimezone('Europe/London');
     $start = new \DateTime("", new \DateTimeZone('Europe/London'));
     $start->setDate(2015, 5, 10);
     $start->setTime(19, 0, 0);
     $event->setStartAt($start);
     $end = new \DateTime("", new \DateTimeZone('Europe/London'));
     $end->setDate(2015, 5, 10);
     $end->setTime(21, 0, 0);
     $event->setEndAt($end);
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $eventRecurSetRepository = new EventRecurSetRepository();
     $eventRecurSet = $eventRecurSetRepository->getForEvent($event);
     $eventRecurSet->setTimeZoneName($event->getTimezone());
     $newStart = new \DateTime();
     $newStart->setDate(2015, 11, 1);
     $newEvent = $eventRecurSet->getNewEventOnArbitraryDate($event, $newStart);
     // What we are really testing here is start and end times set correctly
     $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInUTC()->format("c"));
     $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInTimezone()->format("c"));
     $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInTimezone()->format("c"));
 }
 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 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;
 }
 function test1()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOther = new UserAccountModel();
     $userOther->setEmail("*****@*****.**");
     $userOther->setUsername("test2");
     $userOther->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userOther);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEditorToCuratedList($userOther, $curatedList, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group, $curatedList, $user);
     ## Test
     $this->assertNotNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
     ## Purge!
     $clRepo->purge($curatedList);
     ## Test
     $this->assertNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
 }
 function testEventsVanish()
 {
     ## User, Site, Event
     \TimeSource::mock(2014, 1, 1, 1, 2, 3);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ## Event can be found
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(true);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(false);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     ## Close Site
     \TimeSource::mock(2014, 2, 1, 1, 2, 3);
     $site->setIsClosedBySysAdmin(true);
     $site->setClosedBySysAdminreason('Testing');
     $siteRepo->edit($site, $user);
     ## Event can not be found
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(true);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(false);
     $erb->fetchAll();
     $this->assertEquals(0, count($erb->fetchAll()));
 }
 function testFreeTextSearch()
 {
     TimeSource::mock(2014, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ///////////// Test No Search
     $erb = new EventRepositoryBuilder();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $this->assertEquals(1, $erb->fetchCount());
     ///////////// Test Search Pass
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("test");
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("test");
     $this->assertEquals(1, $erb->fetchCount());
     ///////////// Test Search Fail
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn");
     $this->assertEquals(0, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn");
     $this->assertEquals(0, $erb->fetchCount());
 }
 function test1()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 10, 1, 1, 1, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $areaRepo = new \repositories\AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venue->setAreaId($area->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $venueDuplicate = new VenueModel();
     $venueDuplicate->setTitle("test Duplicate");
     $venueRepo->create($venueDuplicate, $site, $user);
     \TimeSource::mock(2014, 10, 1, 1, 2, 0);
     $venueRepo->markDuplicate($venueDuplicate, $venue, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setVenueId($venue->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ## Test
     $this->assertNotNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue->getId(), $event->getVenueId());
     ## Now Purge!
     $venueRepo->purge($venue);
     ## Test
     $this->assertNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertNull($event->getVenueId());
 }
 function testLoadEventJustBeforeEdit()
 {
     \TimeSource::mock(2014, 1, 1, 1, 1, 1);
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $eventRepo = new EventRepository();
     $eventHistoryRepo = new EventHistoryRepository();
     #### Setup
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     #### Create Event
     \TimeSource::mock(2014, 1, 1, 1, 2, 1);
     $event = new EventModel();
     $event->setSummary("Cats");
     $event->setDescription("Go Miaow");
     $event->setStartAt(getUTCDateTime(2014, 1, 10, 9, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 1, 10, 17, 0, 0));
     $eventRepo->create($event, $site, $user);
     #### Edit Event
     \TimeSource::mock(2014, 1, 1, 1, 3, 1);
     $event = $eventRepo->loadBySlug($site, $event->getSlug());
     $event->setSummary("Lizards");
     $event->setDescription("Go ?");
     $eventRepo->edit($event, $user);
     #### Edit Event
     \TimeSource::mock(2014, 1, 1, 1, 4, 1);
     $event = $eventRepo->loadBySlug($site, $event->getSlug());
     $event->setSummary("Dogs");
     $event->setDescription("Go Woof");
     $eventRepo->edit($event, $user);
     #### test: Load Current State
     \TimeSource::mock(2014, 1, 1, 1, 5, 1);
     $event = $eventRepo->loadBySlug($site, $event->getSlug());
     $this->assertEquals("Dogs", $event->getSummary());
     $this->assertEquals("Go Woof", $event->getDescription());
     #### test: load state before last edit
     \TimeSource::mock(2014, 1, 1, 1, 6, 1);
     $history = $eventHistoryRepo->loadByEventAndlastEditByUser($event, $user);
     $event = $eventRepo->loadEventJustBeforeEdit($event, $history);
     $this->assertEquals("Lizards", $event->getSummary());
     $this->assertEquals("Go ?", $event->getDescription());
 }
 function testEventAndNotEvent1()
 {
     TimeSource::mock(2013, 7, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Test event not in group
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     ## Add event to group, test
     $groupRepo->addEventToGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     ## remove event from group
     $groupRepo->removeEventFromGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $venue1 = new VenueModel();
     $venue1->setTitle("test");
     $venue1->setDescription("test test");
     $venue1->setCountryId($gb->getId());
     $venue2 = new VenueModel();
     $venue2->setTitle("test this looks similar");
     $venue2->setDescription("test test");
     $venue2->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue1, $site, $user);
     $venueRepo->create($venue2, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setVenueId($venue2->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     // Test before
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue2->getId(), $event->getVenueId());
     $venue2 = $venueRepo->loadById($venue2->getId());
     $this->assertFalse($venue2->getIsDeleted());
     $this->assertNull($venue2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->markDuplicate($venue2, $venue1, $user);
     // Test Duplicate
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue1->getId(), $event->getVenueId());
     $venue2 = $venueRepo->loadById($venue2->getId());
     $this->assertTrue($venue2->getIsDeleted());
     $this->assertEquals($venue1->getId(), $venue2->getIsDuplicateOfId());
 }