/**
  * @dataProvider dataForTestIsDateToLateForArbitraryDate
  */
 function testIsDateToLateForArbitraryDate($year, $month, $day, $days, $result)
 {
     $timeSource = new \TimeSource();
     $timeSource->mock(2015, 03, 01, 10, 0, 0);
     $eventSet = new EventRecurSetModel();
     $eventSet->setTimeZoneName('Europe/London');
     $newDate = new \DateTime();
     $newDate->setDate($year, $month, $day);
     $this->assertEquals($result, $eventSet->isDateToLateForArbitraryDate($newDate, $timeSource, $days));
 }
 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'));
 }
 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 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()));
 }
 function test2()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userAccountResetRepository = new UserAccountResetRepository();
     # Test1: recently unused is null
     TimeSource::mock(2013, 1, 1, 1, 0, 1);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertNull($x);
     # Test2: Request one
     TimeSource::mock(2013, 1, 1, 1, 0, 2);
     $userAccountReset = $userAccountResetRepository->create($user);
     #Test 3: recently unused has one
     TimeSource::mock(2013, 1, 1, 1, 0, 3);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertTrue($x != null);
     # Test4: days pass. recently unused is null again
     TimeSource::mock(2013, 1, 5, 1, 0, 5);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertNull($x);
 }
 public function setFeature(SiteModel $site, \BaseSiteFeature $siteFeature, $value, UserAccountModel $userAccountModel = null)
 {
     try {
         $this->app['db']->beginTransaction();
         $changeMade = false;
         $stat = $this->app['db']->prepare("SELECT is_on FROM site_feature_information WHERE site_id=:site_id AND extension_id =:extension_id AND feature_id =:feature_id");
         $stat->execute(array('site_id' => $site->getId(), 'extension_id' => $siteFeature->getExtensionId(), 'feature_id' => $siteFeature->getFeatureId()));
         if ($stat->rowCount() == 1) {
             $data = $stat->fetch();
             if ($data['is_on'] != $value) {
                 $stat = $this->app['db']->prepare("UPDATE site_feature_information SET  is_on=:is_on " . " WHERE site_id=:site_id AND extension_id =:extension_id AND feature_id =:feature_id ");
                 $stat->execute(array('site_id' => $site->getId(), 'extension_id' => $siteFeature->getExtensionId(), 'feature_id' => $siteFeature->getFeatureId(), 'is_on' => $value ? 1 : 0));
                 $changeMade = true;
             }
         } else {
             $stat = $this->app['db']->prepare("INSERT INTO site_feature_information (site_id, extension_id, feature_id, is_on) " . " VALUES(:site_id, :extension_id, :feature_id, :is_on) ");
             $stat->execute(array('site_id' => $site->getId(), 'extension_id' => $siteFeature->getExtensionId(), 'feature_id' => $siteFeature->getFeatureId(), 'is_on' => $value ? 1 : 0));
             $changeMade = true;
         }
         if ($changeMade) {
             $stat = $this->app['db']->prepare("INSERT INTO site_feature_history (site_id, extension_id, feature_id, is_on, user_account_id, created_at) " . " VALUES (:site_id, :extension_id, :feature_id, :is_on, :user_account_id, :created_at)");
             $stat->execute(array('site_id' => $site->getId(), 'extension_id' => $siteFeature->getExtensionId(), 'feature_id' => $siteFeature->getFeatureId(), 'is_on' => $value ? 1 : 0, 'user_account_id' => $userAccountModel ? $userAccountModel->getId() : null, 'created_at' => \TimeSource::getFormattedForDataBase()));
         }
         $this->app['db']->commit();
     } catch (Exception $e) {
         $this->app['db']->rollBack();
     }
 }
 protected function run()
 {
     $siteRepoBuilder = new SiteRepositoryBuilder();
     $siteRepoBuilder->setIsOpenBySysAdminsOnly(true);
     $countCheck = 0;
     $countSend = 0;
     foreach ($siteRepoBuilder->fetchAll() as $site) {
         $this->logVerbose("Site " . $site->getSlug());
         $userRepoBuilder = new UserAccountRepositoryBuilder();
         $userRepoBuilder->setIsOpenBySysAdminsOnly(true);
         foreach ($userRepoBuilder->fetchAll() as $userAccount) {
             $this->logVerbose("User " . $userAccount->getId());
             ++$countCheck;
             $checkTime = \TimeSource::getDateTime();
             $contentsToSend = array();
             foreach ($this->app['extensions']->getExtensionsIncludingCore() as $extension) {
                 $contentsToSend = array_merge($contentsToSend, $extension->getUserNotifyContents($site, $userAccount));
             }
             if ($contentsToSend) {
                 $this->logVerbose("Found contents!");
                 ++$countSend;
                 $this->makeSureHistoriesAreCorrect($contentsToSend);
                 $this->sendFor($site, $userAccount, $contentsToSend);
                 foreach ($contentsToSend as $contentToSend) {
                     $contentToSend->markNotificationSent($checkTime);
                 }
             } else {
                 $this->logVerbose("found nothing");
             }
         }
     }
     return array('result' => 'ok', 'countCheck' => $countCheck, 'countSend' => $countSend);
 }
 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');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->delete($venue, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(true);
     $this->assertEquals(1, count($vrb->fetchAll()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(false);
     $this->assertEquals(0, count($vrb->fetchAll()));
 }
 function __construct(BaseValueReport $report, \DateTime $start, $end = null, $timeperiod = "P1M")
 {
     $this->end = $end ? $end : \TimeSource::getDateTime();
     $this->report = $report;
     $this->start = $start;
     $this->timeperiod = $timeperiod;
 }
 function testIntegration1()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 1, 1, 12, 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());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     ## Create area
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $area->setCountryId($gb->getId());
     $areaRepo = new AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     ## Edit area
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $area = $areaRepo->loadById($area->getId());
     $area->setDescription("testy");
     $areaRepo->edit($area, $user);
     ## Now save changed flags on these .....
     $areaHistoryRepo = new AreaHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM area_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $areaHistory = new AreaHistoryModel();
         $areaHistory->setFromDataBaseRow($data);
         $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeAreaHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(true, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(false, $histories[0]->getParentAreaIdChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(true, $histories[1]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getParentAreaIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 public function timeSinceInWords($data)
 {
     $diff = \TimeSource::time() - $data->getTimestamp();
     if ($diff < 0) {
         return "in the future";
     } elseif ($diff == 0) {
         return "now";
     } elseif ($diff == 1) {
         return "1 second ago";
     } elseif ($diff < 60) {
         return $diff . " seconds ago";
     } elseif ($diff < 60 * 2) {
         return "1 minute ago";
     } elseif ($diff < 60 * 60) {
         return round($diff / 60) . " minutes ago";
     } elseif ($diff < 60 * 60 * 2) {
         return "1 hour ago";
     } elseif ($diff < 60 * 60 * 24) {
         return round($diff / (60 * 60)) . " hours ago";
     } elseif ($diff < 60 * 60 * 24 * 2) {
         return "1 day ago";
     } else {
         return round($diff / (60 * 60 * 24)) . " days ago";
     }
 }
 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 build()
 {
     // We only want events in X days before now and onwards
     $time = \TimeSource::getDateTime();
     $time->add(new \DateInterval("P" . $this->daysBefore . "D"));
     $this->eventRepositoryBuilder->setBefore($time);
     parent::build();
 }
 public function hasRunToday()
 {
     $start = \TimeSource::getDateTime();
     $start->setTime(0, 0, 0);
     $stat = $this->app['db']->prepare("SELECT ended_at FROM task_log " . "WHERE extension_id=:extension_id AND task_id=:task_id AND started_at > :started_at " . "ORDER BY ended_at DESC LIMIT 1");
     $stat->execute(array('extension_id' => $this->getExtensionId(), 'task_id' => $this->getTaskId(), 'started_at' => $start->format("Y-m-d H:i:s")));
     return $stat->rowCount() > 0;
 }
 public function create(ContactSupportModel $contact)
 {
     global $DB;
     $stat = $DB->prepare("INSERT INTO contact_support (subject, message, email, user_account_id, ip, browser, created_at, is_spam_honeypot_field_detected) " . "VALUES (:subject, :message, :email, :user_account_id, :ip, :browser, :created_at, :is_spam_honeypot_field_detected) RETURNING id");
     $stat->execute(array('subject' => substr($contact->getSubject(), 0, VARCHAR_COLUMN_LENGTH_USED), 'message' => $contact->getMessage(), 'email' => substr($contact->getEmail(), 0, VARCHAR_COLUMN_LENGTH_USED), 'user_account_id' => $contact->getUserAccountId(), 'ip' => substr($contact->getIp(), 0, VARCHAR_COLUMN_LENGTH_USED), 'browser' => $contact->getBrowser(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'is_spam_honeypot_field_detected' => $contact->getIsSpamHoneypotFieldDetected() ? 1 : 0));
     $data = $stat->fetch();
     $contact->setId($data['id']);
 }
 public function __construct(SiteModel $site = null, $timeZone = null, $title = null)
 {
     parent::__construct($site, $timeZone, $title);
     // We go back a month, just so calendars have a bit of the past available.
     $time = \TimeSource::getDateTime();
     $time->sub(new \DateInterval("P30D"));
     $this->eventRepositoryBuilder->setAfter($time);
 }
 public function create(ImportedEventModel $importedEvent)
 {
     global $DB;
     $stat = $DB->prepare("INSERT INTO imported_event ( import_url_id, import_id, title, " . "description, start_at, end_at, timezone, is_deleted, url, ticket_url, created_at, reoccur ) " . " VALUES (  :import_url_id, :import_id, :title, " . ":description, :start_at, :end_at, :timezone,  '0', :url, :ticket_url, :created_at, :reoccur ) RETURNING id");
     $stat->execute(array('import_url_id' => $importedEvent->getImportUrlId(), 'import_id' => $importedEvent->getImportId(), 'title' => substr($importedEvent->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'description' => $importedEvent->getDescription(), 'start_at' => $importedEvent->getStartAtInUTC()->format("Y-m-d H:i:s"), 'end_at' => $importedEvent->getEndAtInUTC()->format("Y-m-d H:i:s"), 'timezone' => $importedEvent->getTimezone(), 'url' => $importedEvent->getUrl(), 'ticket_url' => $importedEvent->getTicketUrl(), 'reoccur' => $importedEvent->getReoccur() ? json_encode($importedEvent->getReoccur()) : null, 'created_at' => \TimeSource::getFormattedForDataBase()));
     $data = $stat->fetch();
     $importedEvent->setId($data['id']);
 }
 function testInChildArea()
 {
     $this->addCountriesToTestDB();
     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());
     $area1 = new AreaModel();
     $area1->setTitle("scotland");
     $area1child = new AreaModel();
     $area1child->setTitle("edinburgh");
     $area2 = new AreaModel();
     $area2->setTitle("england");
     $areaRepo = new AreaRepository();
     $countryRepo = new CountryRepository();
     $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1);
     $areaRepo->create($area1child, $area1, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1child);
     $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area2);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0));
     $event->setAreaId($area1child->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1child);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - don't find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area2);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
 }
 function testIntegration1()
 {
     \TimeSource::mock(2014, 1, 1, 12, 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());
     ## Create group
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Edit group
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $group = $groupRepo->loadById($group->getId());
     $group->setTwitterUsername("testy");
     $groupRepo->edit($group, $user);
     ## Now save changed flags on these .....
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setGroup($group);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getUrlChanged());
     $this->assertEquals(true, $histories[0]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(true, $histories[1]->getUrlChanged());
     $this->assertEquals(false, $histories[1]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 /**
  * 
  * @return \models\API2ApplicationRequestTokenModel
  */
 public function create(API2ApplicationModel $app, API2ApplicationRequestTokenModel $requestToken)
 {
     global $DB;
     $requestToken->setRequestToken(createKey(1, 255));
     // TODO make sure token is unique!!!!!
     $stat = $DB->prepare("INSERT INTO api2_application_request_token (api2_application_id, request_token, created_at, user_id, " . "callback_url, is_callback_display, is_callback_javascript, is_editor, state_from_user) " . "VALUES (:api2_application_id, :request_token, :created_at,  :user_id, :callback_url, " . ":is_callback_display, :is_callback_javascript, :is_editor, :state_from_user)");
     $stat->execute(array('api2_application_id' => $app->getId(), 'request_token' => $requestToken->getRequestToken(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'user_id' => null, 'callback_url' => $app->getIsCallbackUrl() ? $requestToken->getCallbackUrl() : null, 'is_callback_display' => $app->getIsCallbackDisplay() && $requestToken->getIsCallbackDisplay() ? 1 : 0, 'is_callback_javascript' => $app->getIsCallbackJavascript() && $requestToken->getIsCallbackJavascript() ? 1 : 0, 'is_editor' => $requestToken->getIsEditor() && $app->getIsEditor() ? 1 : 0, 'state_from_user' => $requestToken->getStateFromUser()));
     return $requestToken;
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->getId());
     $importURL->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Lanyrd1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $event = $events[0];
     $this->assertEquals("State of the Map Scotland 2013", $event->getSummary());
     $this->assertEquals('2013-10-11 00:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-14 23:59:59', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("http://sotms.eventbrite.com/\n\nhttp://lanyrd.com/crkmt", $event->getDescription());
     $this->assertEquals('http://lanyrd.com/2013/sotmscot2013/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
     // Look for event
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setImportURL($importURL);
     $this->assertEquals(1, count($erb->fetchAll()));
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->getId());
     $importURL->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Eventbrite1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $importURLRun->setFlag(ImportURLRun::$FLAG_SET_TICKET_URL_AS_URL);
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $event = $events[0];
     $this->assertEquals("Computing At School Scotland Conference 2013", $event->getSummary());
     $this->assertEquals('2013-10-26 07:30:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-26 16:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('For details, click here: https://casscot13.eventbrite.co.uk', $event->getDescription());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getURL());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getTicketURL());
     $this->assertFalse($event->getIsDeleted());
 }
 public function createForAppAndUserId(API2ApplicationModel $app, $userID)
 {
     global $DB;
     $stat = $DB->prepare("SELECT api2_application_user_token_information.* FROM api2_application_user_token_information WHERE " . "api2_application_id =:api2_application_id AND user_id =:user_id");
     $stat->execute(array('api2_application_id' => $app->getId(), 'user_id' => $userID));
     if ($stat->rowCount() == 0) {
         $stat = $DB->prepare("INSERT INTO api2_application_user_token_information " . "(api2_application_id, user_id, user_token, user_secret, created_at) " . "VALUES (:api2_application_id, :user_id, :user_token, :user_secret, :created_at)");
         $stat->execute(array('api2_application_id' => $app->getId(), 'user_id' => $userID, 'user_token' => createKey(1, 255), 'user_secret' => createKey(1, 255), 'created_at' => \TimeSource::getFormattedForDataBase()));
         // TODO check for unique user_token
     }
 }
 function calendarNow(Application $app)
 {
     $cal = new \RenderCalendar();
     $cal->getEventRepositoryBuilder()->setSite($app['currentSite']);
     $cal->getEventRepositoryBuilder()->setIncludeDeleted(false);
     if ($app['currentUser']) {
         $cal->getEventRepositoryBuilder()->setUserAccount($app['currentUser'], true);
     }
     $cal->byDate(\TimeSource::getDateTime(), 31, true);
     list($prevYear, $prevMonth, $nextYear, $nextMonth) = $cal->getPrevNextLinksByMonth();
     return $app['twig']->render('/site/calendarPage.html.twig', array('calendar' => $cal, 'prevYear' => $prevYear, 'prevMonth' => $prevMonth, 'nextYear' => $nextYear, 'nextMonth' => $nextMonth, 'pageTitle' => 'Calendar', 'showCurrentUserOptions' => true));
 }
 public function create(UserAccountModel $user)
 {
     global $DB;
     $uarm = new UserAccountRememberMeModel();
     $uarm->setUserAccountId($user->getId());
     $uarm->setAccessKey(createKey(2, 250));
     // TODO check not already used
     $stat = $DB->prepare("INSERT INTO user_account_remember_me (user_account_id, access_key, created_at) " . "VALUES (:user_account_id, :access_key, :created_at)");
     $stat->execute(array('user_account_id' => $uarm->getUserAccountId(), 'access_key' => $uarm->getAccessKey(), 'created_at' => \TimeSource::getFormattedForDataBase()));
     $data = $stat->fetch();
     return $uarm;
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->getId());
     $importURL->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Meetup1.ics');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $event = $events[0];
     $this->assertEquals("Talk & Build AngularJS", $event->getSummary());
     $this->assertEquals('2013-10-17 18:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-17 21:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("AngularJS - Edinburgh\nThursday, October 17 at 7:00 PM\n\nDetails: http://www.meetup.com/AngularJS-Edinburgh/events/141654792/", $event->getDescription());
     $this->assertEquals('http://www.meetup.com/AngularJS-Edinburgh/events/141654792/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
 }
 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());
 }
 /**
  * 
  * @return \models\UserAccountResetModel A single one or NULL. Technically it may load multiple ones, but we only return one.
  */
 public function loadRecentlyUnusedSentForUserAccountId($id, $seconds = 60)
 {
     global $DB;
     $stat = $DB->prepare("SELECT user_account_reset.* FROM user_account_reset WHERE reset_at IS NULL AND user_account_id =:user_account_id AND created_at > :since");
     $time = \TimeSource::getDateTime();
     $time->setTimestamp($time->getTimestamp() - $seconds);
     $stat->execute(array('user_account_id' => $id, 'since' => $time->format('Y-m-d H:i:s')));
     if ($stat->rowCount() > 0) {
         $uar = new UserAccountResetModel();
         $uar->setFromDataBaseRow($stat->fetch());
         return $uar;
     }
 }
 /**
  * 
  * @return \models\API2ApplicationModel
  */
 public function create(UserAccountModel $user, $title)
 {
     global $DB;
     $app = new API2ApplicationModel();
     $app->setTitle($title);
     $app->setAppSecret(createKey(1, 255));
     $app->setAppToken(createKey(1, 255));
     $stat = $DB->prepare("INSERT INTO  api2_application_information (user_id,title,app_token,app_secret,created_at) " . "VALUES (:user_id,:title,:app_token,:app_secret,:created_at) RETURNING id");
     $stat->execute(array('user_id' => $user->getId(), 'title' => $title, 'app_token' => $app->getAppToken(), 'app_secret' => $app->getAppSecret(), 'created_at' => \TimeSource::getFormattedForDataBase()));
     $data = $stat->fetch();
     $app->setId($data['id']);
     return $app;
 }
 public function addCountryToSite(CountryModel $country, SiteModel $site, UserAccountModel $user)
 {
     global $DB;
     $stat = $DB->prepare("SELECT * FROM country_in_site_information WHERE site_id =:site_id AND country_id =:country_id");
     $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId()));
     if ($stat->rowCount() == 1) {
         $stat = $DB->prepare("UPDATE country_in_site_information SET is_in='1' WHERE site_id =:site_id AND country_id =:country_id");
         $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId()));
     } else {
         $stat = $DB->prepare("INSERT INTO country_in_site_information (site_id,country_id,is_in,is_previously_in,created_at) VALUES (:site_id,:country_id,'1','1',:created_at)");
         $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId(), 'created_at' => \TimeSource::getFormattedForDataBase()));
     }
 }