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); }
public function markNotificationSent(\DateTime $checkTime) { $userWatchesAreaRepository = new UserWatchesAreaRepository(); $userWatchesArea = $userWatchesAreaRepository->loadByUserAndArea($this->userAccount, $this->area); $userWatchesAreaRepository->markNotifyEmailSent($userWatchesArea, $checkTime); }