/**
  * @dataProvider dataForTestSet
  */
 function testSet5($slug, $text, $result)
 {
     $curatedlist = new CuratedListModel();
     $curatedlist->setSlug($slug);
     $curatedlist->setTitle($text);
     $this->assertEquals($result, $curatedlist->getSlugForUrl());
 }
 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 loadByOwnerOfCuratedList(CuratedListModel $curatedList)
 {
     global $DB;
     $stat = $DB->prepare("SELECT user_account_information.* FROM user_account_information " . " JOIN user_in_curated_list_information ON user_in_curated_list_information.user_account_id = user_account_information.id " . "WHERE user_in_curated_list_information.curated_list_id = :id AND user_in_curated_list_information.is_owner = 't'");
     $stat->execute(array('id' => $curatedList->getId()));
     if ($stat->rowCount() > 0) {
         $user = new UserAccountModel();
         $user->setFromDataBaseRow($stat->fetch());
         return $user;
     }
 }
 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()));
 }
 public function fetchAll()
 {
     $this->buildStart();
     $this->build();
     $this->buildStat();
     $results = array();
     while ($data = $this->stat->fetch()) {
         $cList = new CuratedListModel();
         $cList->setFromDataBaseRow($data);
         $results[] = $cList;
     }
     return $results;
 }
 protected function build()
 {
     global $DB;
     $this->select[] = 'event_information.*';
     $this->select[] = " group_information.title AS group_title ";
     $this->select[] = " group_information.id AS group_id ";
     $this->joins[] = " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL AND event_in_group.is_main_group = '1' ";
     $this->joins[] = " LEFT JOIN group_information ON group_information.id = event_in_group.group_id ";
     $joinsVenueInfoSQL = " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id ";
     if ($this->site) {
         $this->where[] = " event_information.site_id = :site_id ";
         $this->params['site_id'] = $this->site->getId();
     }
     if ($this->group) {
         // We use a seperate table here so if event is in 2 groups and we select events in 1 group that isn't the main group only,
         // the normal event_in_group table still shows the main group.
         $this->joins[] = " JOIN event_in_group AS event_in_group_select ON event_in_group_select.event_id = event_information.id " . "AND event_in_group_select.removed_at IS NULL AND event_in_group_select.group_id = :group_id ";
         $this->params['group_id'] = $this->group->getId();
     }
     if ($this->country) {
         $this->where[] = " event_information.country_id = :country_id ";
         $this->params['country_id'] = $this->country->getId();
     }
     if ($this->area) {
         // We were doing
         // $this->joins[] = " LEFT JOIN cached_area_has_parent ON cached_area_has_parent.area_id = venue_information.area_id";
         // $this->where[] =  " (venue_information.area_id = :area_id OR  cached_area_has_parent.has_parent_area_id = :area_id )";
         // but then we got duplicates
         $areaids = array($this->area->getId());
         $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id");
         $this->statAreas->execute(array('id' => $this->area->getId()));
         while ($d = $this->statAreas->fetch()) {
             $areaids[] = $d['area_id'];
         }
         $this->joins[] = $joinsVenueInfoSQL;
         $this->where[] = " (venue_information.area_id IN (" . implode(",", $areaids) . ") " . "OR event_information.area_id IN (" . implode(",", $areaids) . ")) ";
     }
     if ($this->venue) {
         $this->where[] = " event_information.venue_id = :venue_id ";
         $this->params['venue_id'] = $this->venue->getId();
     }
     if ($this->importURL) {
         $this->joins[] = " LEFT JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id ";
         $this->joins[] = " LEFT JOIN imported_event ON imported_event.id = imported_event_is_event.imported_event_id ";
         $this->where[] = " (imported_event.import_url_id = :import_url_id OR event_information.import_url_id = :import_url_id )";
         $this->params['import_url_id'] = $this->importURL->getId();
     }
     if ($this->importedEvent) {
         $this->joins[] = " JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id AND imported_event_is_event.imported_event_id = :imported_event_id ";
         $this->params['imported_event_id'] = $this->importedEvent->getId();
     }
     if (!$this->site && !$this->group) {
         $this->joins[] = " JOIN site_information ON event_information.site_id = site_information.id ";
         $this->select[] = " site_information.slug AS site_slug ";
         if (!$this->includeEventsFromClosedSites) {
             $this->where[] = " site_information.is_closed_by_sys_admin = '0' ";
         }
     }
     if ($this->curatedList) {
         $this->joins[] = " LEFT JOIN event_in_curated_list ON event_in_curated_list.event_id = event_information.id " . " AND event_in_curated_list.removed_at IS NULL AND event_in_curated_list.curated_list_id = :curated_list";
         $this->joins[] = " LEFT JOIN  ( SELECT event_in_group.event_id, MAX(event_in_group.group_id) AS group_id" . " FROM event_in_group " . " JOIN group_in_curated_list ON group_in_curated_list.group_id = event_in_group.group_id " . " WHERE group_in_curated_list.curated_list_id = :curated_list AND group_in_curated_list.removed_at IS NULL AND event_in_group.removed_at IS NULL " . " GROUP BY event_in_group.event_id " . ") AS event_in_group_in_curated_list ON event_in_group_in_curated_list.event_id = event_information.id ";
         $this->where[] = " ( event_in_curated_list.curated_list_id IS NOT NULL OR event_in_group_in_curated_list.event_id IS NOT NULL )";
         $this->params['curated_list'] = $this->curatedList->getId();
         if ($this->curatedListInformation) {
             $this->joins[] = " LEFT JOIN group_information AS group_information_cl ON group_information_cl.id = event_in_group_in_curated_list.group_id ";
             $this->select[] = " (CASE WHEN event_in_curated_list.event_id IS NULL THEN 0 ELSE 1 END) AS is_event_in_curated_list ";
             $this->select[] = " group_information_cl.id AS in_curated_list_group_id ";
             $this->select[] = " group_information_cl.slug AS in_curated_list_group_slug ";
             $this->select[] = " group_information_cl.title AS in_curated_list_group_title ";
         }
     }
     if ($this->end) {
         $this->where[] = ' event_information.end_at = :end';
         $this->params['end'] = $this->end->format("Y-m-d H:i:s");
     } else {
         if ($this->after) {
             $this->where[] = ' event_information.end_at > :after';
             $this->params['after'] = $this->after->format("Y-m-d H:i:s");
         } else {
             if ($this->endBefore) {
                 $this->where[] = ' event_information.end_at < :before';
                 $this->params['before'] = $this->endBefore->format("Y-m-d H:i:s");
             }
         }
     }
     if ($this->start) {
         $this->where[] = ' event_information.start_at = :start';
         $this->params['start'] = $this->start->format("Y-m-d H:i:s");
     } else {
         if ($this->before) {
             $this->where[] = ' event_information.start_at < :before';
             $this->params['before'] = $this->before->format("Y-m-d H:i:s");
         } else {
             if ($this->startAfter) {
                 $this->where[] = ' event_information.start_at > :startAfter';
                 $this->params['startAfter'] = $this->startAfter->format("Y-m-d H:i:s");
             }
         }
     }
     if (!$this->include_deleted) {
         $this->where[] = " event_information.is_deleted = '0' ";
     }
     if (!$this->include_cancelled) {
         $this->where[] = " event_information.is_cancelled = '0' ";
     }
     if (!$this->include_imported) {
         $this->where[] = " event_information.import_url_id is null ";
     }
     if ($this->userAccount) {
         // user at event. we want info on this always for the extra selects, so outside if statement
         $this->joins[] = "  LEFT JOIN user_at_event_information ON user_at_event_information.event_id = event_information.id " . "AND user_at_event_information.user_account_id = :user_account_id ";
         $this->select[] = " user_at_event_information.is_plan_attending AS user_is_plan_attending ";
         $this->select[] = " user_at_event_information.is_plan_maybe_attending AS user_is_plan_maybe_attending ";
         if (!$this->userAccountIncludeAll) {
             $w = array();
             if ($this->userAccountIncludeWatching) {
                 $w[] = "  event_information.id IN (SELECT event_information.id FROM event_information " . " LEFT JOIN user_watches_site_information ON  user_watches_site_information.site_id = event_information.site_id " . "AND user_watches_site_information.user_account_id = :user_account_id AND user_watches_site_information.is_watching='1' " . "  LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL " . " LEFT JOIN user_watches_group_information ON user_watches_group_information.group_id = event_in_group.group_id " . "AND user_watches_group_information.user_account_id = :user_account_id AND user_watches_group_information.is_watching='1' " . " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id " . " LEFT JOIN cached_area_has_parent ON ( venue_information.area_id = cached_area_has_parent.area_id OR event_information.area_id = cached_area_has_parent.area_id) " . " LEFT JOIN user_watches_area_information ON ( " . "user_watches_area_information.area_id = event_information.area_id OR user_watches_area_information.area_id = venue_information.area_id " . " OR user_watches_area_information.area_id = cached_area_has_parent.has_parent_area_id " . ") " . "AND user_watches_area_information.user_account_id = :user_account_id AND user_watches_area_information.is_watching='1' " . " WHERE user_watches_site_information.is_watching='1' OR user_watches_group_information.is_watching='1'  OR user_watches_area_information.is_watching='1'" . " )  ";
             }
             if ($this->userAccountIncludeAttending) {
                 if ($this->userAccountIncludePrivate) {
                     $w[] = " user_at_event_information.is_plan_attending = '1' ";
                     $w[] = " user_at_event_information.is_plan_maybe_attending = '1' ";
                 } else {
                     $w[] = " (user_at_event_information.is_plan_attending = '1' AND user_at_event_information.is_plan_public  = '1' )";
                     $w[] = " (user_at_event_information.is_plan_maybe_attending = '1' AND user_at_event_information.is_plan_public  = '1' )";
                 }
             }
             $this->where[] = "  (  " . implode(" OR ", $w) . ") ";
         }
         $this->params['user_account_id'] = $this->userAccount->getId();
     }
     if ($this->include_venue_information || $this->include_area_information || $this->must_have_lat_lng) {
         if (!in_array($joinsVenueInfoSQL, $this->joins)) {
             $this->joins[] = $joinsVenueInfoSQL;
         }
         if ($this->include_venue_information) {
             $this->select[] = "  venue_information.lng AS venue_lng";
             $this->select[] = "  venue_information.lat AS venue_lat";
             $this->select[] = "  venue_information.title AS venue_title";
             $this->select[] = "  venue_information.slug AS venue_slug";
             $this->select[] = "  venue_information.description AS venue_description";
             $this->select[] = "  venue_information.address AS venue_address";
             $this->select[] = "  venue_information.address_code AS venue_address_code";
         }
         if ($this->include_area_information) {
             $this->joins[] = " LEFT JOIN area_information ON area_information.id = event_information.area_id OR area_information.id = venue_information.area_id";
             $this->select[] = "  area_information.title AS area_title";
             $this->select[] = "  area_information.slug AS area_slug";
             $this->select[] = "  area_information.id AS area_information_id";
             // we already have a area_id so called something different
         }
         if ($this->must_have_lat_lng) {
             $this->where[] = " venue_information.lat IS NOT NULL ";
             $this->where[] = " venue_information.lng IS NOT NULL ";
         }
     }
     if ($this->include_country_information) {
         $this->joins[] = " LEFT JOIN country ON country.id = event_information.country_id  ";
         $this->select[] = "  country.two_char_code AS country_two_char_code";
         $this->select[] = "  country.title AS country_title";
     }
     if ($this->venueVirtualOnly) {
         $this->where[] = " event_information.is_virtual = '1' ";
     }
     if ($this->event_recur_set_id) {
         $this->where[] = " event_information.event_recur_set_id = :event_recur_set_id ";
         $this->params['event_recur_set_id'] = $this->event_recur_set_id;
     }
     if ($this->tag) {
         $this->joins[] = "  JOIN event_has_tag ON event_has_tag.event_id = event_information.id AND  event_has_tag.tag_id = :tag_id AND event_has_tag.removed_at IS NULL";
         $this->params['tag_id'] = $this->tag->getId();
     }
     if ($this->freeTextSearch) {
         $this->where[] = '(CASE WHEN event_information.summary IS NULL THEN \'\' ELSE event_information.summary END)   || ' . '\' \' || ' . '(CASE WHEN event_information.description IS NULL THEN \'\' ELSE event_information.description END) || ' . '\' \' || ' . '(CASE WHEN group_information.title IS NULL THEN \'\' ELSE group_information.title END)' . ' ILIKE :free_text_search ';
         $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%";
     }
     if ($this->includeMediasSlugs) {
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_event ON media_information.id = media_in_event.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_event.removal_approved_at IS NULL AND media_in_event.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_event_slugs ";
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_group ON media_information.id = media_in_group.media_id " . " JOIN event_in_group ON event_in_group.group_id = media_in_group.group_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_group.removal_approved_at IS NULL " . " AND event_in_group.removal_approved_at IS NULL AND event_in_group.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_group_slugs ";
         $this->select[] = "  (SELECT  array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_venue ON media_information.id = media_in_venue.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_venue.removal_approved_at IS NULL AND media_in_venue.venue_id = event_information.venue_id " . " GROUP BY event_information.venue_id ) AS media_venue_slugs ";
     }
     if ($this->editedByUser) {
         $this->where[] = " event_information.id IN (SELECT event_id FROM event_history WHERE user_account_id = :editedByUser) ";
         $this->params['editedByUser'] = $this->editedByUser->getId();
     }
 }
 function testEventInTwoGroupsAddedDirectlyThenOneGroupAdded()
 {
     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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("I don't need no stinking tests");
     $group2->setDescription("works first time");
     $group2->setUrl("http://www.soveryperfect.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group1, array($group2));
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Add group to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group1, $curatedList, $user);
     // Test After
     // .... we don't ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertFalse($eventWithInfo->getIsEventInCuratedList());
     // .... we Do ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList, true);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertEquals($group1->getId(), $eventWithInfo->getInCuratedListGroupId());
     $this->assertEquals($group1->getSlug(), $eventWithInfo->getInCuratedListGroupSlug());
     $this->assertEquals($group1->getTitle(), $eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->isEventInListViaGroup());
     $this->assertEquals($group1->getId(), $curatedListWithInfo->getEventInListViaGroupId());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Remove group from list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $clRepo->removeGroupFromCuratedList($group1, $curatedList, $user);
     $clRepo->removeEventFromCuratedList($event, $curatedList, $user);
     // Test After
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
 }
 public function update(CuratedListModel $curatedList, $fields, UserAccountModel $user = null)
 {
     $alreadyInTransaction = $this->db->inTransaction();
     // Make Information Data
     $fieldsSQL1 = array();
     $fieldsParams1 = array('id' => $curatedList->getId());
     foreach ($fields as $field) {
         $fieldsSQL1[] = " " . $field . "=:" . $field . " ";
         if ($field == 'title') {
             $fieldsParams1['title'] = substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
         } else {
             if ($field == 'description') {
                 $fieldsParams1['description'] = $curatedList->getDescription();
             } else {
                 if ($field == 'parent_area_id') {
                     $fieldsParams1['parent_area_id'] = $curatedList->getParentAreaId();
                 } else {
                     if ($field == 'is_deleted') {
                         $fieldsParams1['is_deleted'] = $curatedList->getIsDeleted() ? 1 : 0;
                     }
                 }
             }
         }
     }
     // Make History Data
     $fieldsSQL2 = array('curated_list_id', 'user_account_id', 'created_at');
     $fieldsSQLParams2 = array(':curated_list_id', ':user_account_id', ':created_at');
     $fieldsParams2 = array('curated_list_id' => $curatedList->getId(), 'user_account_id' => $user ? $user->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase());
     foreach ($this->possibleFields as $field) {
         if (in_array($field, $fields) || $field == 'title') {
             $fieldsSQL2[] = " " . $field . " ";
             $fieldsSQLParams2[] = " :" . $field . " ";
             if ($field == 'title') {
                 $fieldsParams2['title'] = substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'description') {
                     $fieldsParams2['description'] = $curatedList->getDescription();
                 } else {
                     if ($field == 'is_deleted') {
                         $fieldsParams2['is_deleted'] = $curatedList->getIsDeleted() ? 1 : 0;
                     }
                 }
             }
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " 0 ";
         } else {
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " -2 ";
         }
     }
     try {
         if (!$alreadyInTransaction) {
             $this->db->beginTransaction();
         }
         // Information SQL
         $stat = $this->db->prepare("UPDATE curated_list_information  SET " . implode(",", $fieldsSQL1) . " WHERE id=:id");
         $stat->execute($fieldsParams1);
         // History SQL
         $stat = $this->db->prepare("INSERT INTO curated_list_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")");
         $stat->execute($fieldsParams2);
         if (!$alreadyInTransaction) {
             $this->db->commit();
         }
     } catch (Exception $e) {
         if (!$alreadyInTransaction) {
             $this->db->rollBack();
         }
         throw $e;
     }
 }
 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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     // Add event to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     // Test After
     // ... we don't ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertFalse($eventWithInfo->getIsEventInCuratedList());
     // ... we DO ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList, true);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     // Remove event to list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $clRepo->removeEventFromCuratedList($event, $curatedList, $user);
     // Test After
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
 }
 public function purge(CuratedListModel $curatedList)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("DELETE FROM event_in_curated_list WHERE curated_list_id=:id");
         $stat->execute(array('id' => $curatedList->getId()));
         $stat = $DB->prepare("DELETE FROM group_in_curated_list WHERE curated_list_id=:id");
         $stat->execute(array('id' => $curatedList->getId()));
         $stat = $DB->prepare("DELETE FROM user_in_curated_list_information WHERE curated_list_id=:id");
         $stat->execute(array('id' => $curatedList->getId()));
         $stat = $DB->prepare("DELETE FROM curated_list_history WHERE curated_list_id=:id");
         $stat->execute(array('id' => $curatedList->getId()));
         $stat = $DB->prepare("DELETE FROM curated_list_information WHERE id=:id");
         $stat->execute(array('id' => $curatedList->getId()));
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
         throw $e;
     }
 }
 protected function checkCuratedListInTest1(CuratedListModel $curatedList)
 {
     $this->assertEquals("test this!", $curatedList->getDescription());
     $this->assertEquals("test", $curatedList->getTitle());
 }