function eventMyAttendanceJson($siteSlug, $eventSlug, Request $request, Application $app)
 {
     if (!$this->build($siteSlug, $request, $app)) {
         $app->abort(404, "Site does not exist.");
     }
     $repo = new \repositories\EventRepository();
     $this->parameters['event'] = $repo->loadBySlug($this->parameters['site'], $eventSlug);
     if (!$this->parameters['event']) {
         $app->abort(404, "Event does not exist.");
     }
     $uaer = new UserAtEventRepository();
     $userAtEvent = $uaer->loadByUserAndEventOrInstanciate($app['currentUser'], $this->parameters['event']);
     $data = array();
     if ($request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && !$this->parameters['event']->isInPast()) {
         if ($request->request->get('privacy') == 'public') {
             $userAtEvent->setIsPlanPublic(true);
         } else {
             if ($request->request->get('privacy') == 'private') {
                 $userAtEvent->setIsPlanPublic(false);
             }
         }
         if ($request->request->get('attending') == 'no') {
             $userAtEvent->setIsPlanAttending(false);
             $userAtEvent->setIsPlanMaybeAttending(false);
         } else {
             if ($request->request->get('attending') == 'maybe') {
                 $userAtEvent->setIsPlanAttending(false);
                 $userAtEvent->setIsPlanMaybeAttending(true);
             } else {
                 if ($request->request->get('attending') == 'yes') {
                     $userAtEvent->setIsPlanAttending(true);
                     $userAtEvent->setIsPlanMaybeAttending(false);
                 }
             }
         }
         $uaer->save($userAtEvent);
     }
     $data['attending'] = $userAtEvent->getIsPlanAttending() ? 'yes' : ($userAtEvent->getIsPlanMaybeAttending() ? 'maybe' : 'no');
     $data['privacy'] = $userAtEvent->getIsPlanPublic() ? 'public' : 'private';
     $data['inPast'] = $this->parameters['event']->isInPast() ? 1 : 0;
     $data['CSFRToken'] = $app['websession']->getCSFRToken();
     $response = new Response(json_encode($data));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 public function markDuplicateWithMetaData(EventModel $duplicateEvent, EventModel $originalEvent, EventEditMetaDataModel $eventEditMetaDataModel)
 {
     global $DB;
     if ($duplicateEvent->getId() == $originalEvent->getId()) {
         return;
     }
     try {
         $DB->beginTransaction();
         $duplicateEvent->setIsDeleted(true);
         $duplicateEvent->setIsDuplicateOfId($originalEvent->getId());
         $this->eventDBAccess->update($duplicateEvent, array('is_deleted', 'is_duplicate_of_id'), $eventEditMetaDataModel);
         $uaeRepo = new UserAtEventRepository();
         $uaerb = new UserAtEventRepositoryBuilder();
         $uaerb->setEventOnly($duplicateEvent);
         foreach ($uaerb->fetchAll() as $uaeDuplicate) {
             if ($uaeDuplicate->getIsPlanAttending() || $uaeDuplicate->getIsPlanMaybeAttending()) {
                 $uaeOriginal = $uaeRepo->loadByUserIDAndEventOrInstanciate($uaeDuplicate->getUserAccountId(), $originalEvent);
                 // does user already have plans for this event? If so leave them.
                 if (!$uaeOriginal->getIsPlanAttending() && !$uaeOriginal->getIsPlanMaybeAttending()) {
                     $uaeOriginal->setIsPlanAttending($uaeDuplicate->getIsPlanAttending());
                     $uaeOriginal->setIsPlanMaybeAttending($uaeDuplicate->getIsPlanMaybeAttending());
                     $uaeOriginal->setIsPlanPublic($uaeDuplicate->getIsPlanPublic());
                     $uaeRepo->save($uaeOriginal);
                 }
             }
         }
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 /**
  * @dataProvider dataForTest1
  */
 function test1($emailOption, $goingOption, $result)
 {
     TimeSource::mock(2013, 8, 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(2013, 8, 2, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 8, 2, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $user->setEmailUpcomingEventsDaysNotice(1);
     $user->setEmailUpcomingEvents($emailOption);
     $userRepo->editEmailsOptions($user);
     if ($goingOption == 'a') {
         $userAtEvent = new UserAtEventModel();
         $userAtEvent->setUserAccountId($user->getId());
         $userAtEvent->setEventId($event->getId());
         $userAtEvent->setIsPlanAttending(true);
         $uaeRepo = new UserAtEventRepository();
         $uaeRepo->save($userAtEvent);
     } else {
         if ($goingOption == 'm') {
             $userAtEvent = new UserAtEventModel();
             $userAtEvent->setUserAccountId($user->getId());
             $userAtEvent->setEventId($event->getId());
             $userAtEvent->setIsPlanMaybeAttending(true);
             $uaeRepo = new UserAtEventRepository();
             $uaeRepo->save($userAtEvent);
         }
     }
     list($upcomingEvents, $allEvents, $userAtEvent, $flag) = $user->getDataForUpcomingEventsEmail();
     $this->assertEquals($result, $flag);
 }
 protected function actionThingsToDoAfterGetUser(Application $app, UserAccountModel $user)
 {
     // events
     $uaerepo = new UserAtEventRepository();
     $eventsAdded = false;
     foreach ($this->parameters['afterGetUserAddEvents'] as $event) {
         if ($event->getIsAllowedForAfterGetUser()) {
             $uae = $uaerepo->loadByUserAndEventOrInstanciate($user, $event);
             if (!$uae->getIsPlanAttending() && !$uae->getIsPlanMaybeAttending()) {
                 $uae->setIsPlanMaybeAttending(true);
                 $uaerepo->save($uae);
                 $eventsAdded = true;
             }
         }
     }
     if ($eventsAdded) {
         $app['flashmessages']->addMessage("Check out your personal calendar for events you are interested in!");
         // TODO add link
     }
     // areas
     $uwarepo = new UserWatchesAreaRepository();
     foreach ($this->parameters['afterGetUserAddAreas'] as $area) {
         if ($area->getIsAllowedForAfterGetUser()) {
             $uwarepo->startUserWatchingArea($user, $area);
         }
     }
     // reset
     $app['websession']->setArray("afterGetUserAddEvents", array());
     $app['websession']->setArray("afterGetUserAddAreas", array());
 }