コード例 #1
0
 function newComment($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Area does not exist.");
     }
     if ($this->parameters['area']->getIsDeleted()) {
         die("No");
         // TODO
     }
     $comment = new AreaCommentModel();
     $form = $app['form.factory']->create(new NewCommentForm(), $comment);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $area = $this->parameters['area'];
             if ($request->request->get("area")) {
                 foreach ($this->parameters['parentAreas'] as $parentArea) {
                     if ($parentArea->getId() == $request->request->get("area")) {
                         $area = $parentArea;
                     }
                 }
             }
             $repo = new AreaCommentRepository();
             $repo->create($comment, $area, $app['currentUser']);
             $userWatchesAreaRepo = new UserWatchesAreaRepository();
             $userWatchesAreaRepo->startUserWatchingAreaIfNotWatchedBefore($app['currentUser'], $area);
             return $app->redirect("/area/" . $area->getSlugforURL() . '/comment');
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('site/area/newComment.html.twig', $this->parameters);
 }
コード例 #2
0
 function stopWatchingFromEmail($slug, $userid, $code, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Area does not exist.");
     }
     $userRepo = new UserAccountRepository();
     $user = $userRepo->loadByID($userid);
     if (!$user) {
         $app['monolog']->addError("Failed stop watching area from email - no user ");
         die("NO");
         // TODO
     }
     $userWatchesAreaStopRepo = new UserWatchesAreaStopRepository();
     $userWatchesAreaStop = $userWatchesAreaStopRepo->loadByUserAccountIDAndAreaIDAndAccessKey($user->getId(), $this->parameters['area']->getId(), $code);
     if (!$userWatchesAreaStop) {
         $app['monolog']->addError("Failed stop watching area from email - user " . $user->getId() . " - code wrong");
         die("NO");
         // TODO
     }
     $userWatchesAreaRepo = new UserWatchesAreaRepository();
     $userWatchesArea = $userWatchesAreaRepo->loadByUserAndArea($user, $this->parameters['area']);
     if (!$userWatchesArea || !$userWatchesArea->getIsWatching()) {
         $app['monolog']->addError("Failed stop watching area from email - user " . $user->getId() . " - not watching");
         die("You don't watch this area");
         // TODO
     }
     if ($request->request->get('action') == 'unwatch' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         $userWatchesAreaRepo->stopUserWatchingArea($user, $this->parameters['area']);
         // redirect here because if we didn't the twig global and $app vars would be wrong (the old state)
         // this is an easy way to get round that.
         $app['flashmessages']->addMessage("You have stopped watching this area.");
         return $app->redirect('/area/' . $this->parameters['area']->getSlugForURL());
     }
     $this->parameters['user'] = $user;
     return $app['twig']->render('site/area/stopWatchingFromEmail.html.twig', $this->parameters);
 }
コード例 #3
0
 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());
 }
 public function markNotificationSent(\DateTime $checkTime)
 {
     $userWatchesAreaRepository = new UserWatchesAreaRepository();
     $userWatchesArea = $userWatchesAreaRepository->loadByUserAndArea($this->userAccount, $this->area);
     $userWatchesAreaRepository->markNotifyEmailSent($userWatchesArea, $checkTime);
 }