/** * @return array */ public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel) { global $CONFIG; $out = array(); $grb = new AreaRepositoryBuilder(); $grb->setSite($siteModel); $grb->setLimit(0); // all! No limit // TODO don't we still want to do this? How will user A get a notification if user B deletes area? but then so far most area deletetions are by admins. $grb->setIncludeDeleted(false); foreach ($grb->fetchAll() as $area) { $uwg = $this->loadByUserAndArea($userAccountModel, $area); if ($uwg && $uwg->getIsWatching()) { $dateSince = $uwg->getSinceDateForNotifyChecking(); $historyRepositoryBuilder = new HistoryRepositoryBuilder(); $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setArea($area); $historyRepositoryBuilder->setSince($dateSince); $historyRepositoryBuilder->setNotUser($userAccountModel); // Only admins can change tags at the moment so don't include $historyRepositoryBuilder->setIncludeTagHistory(false); $histories = $historyRepositoryBuilder->fetchAll(); if ($histories) { $content = new UserWatchesAreaNotifyContent(); $content->setHistories($histories); $userWatchesAreaStopRepository = new UserWatchesAreaStopRepository(); $userWatchesAreaStop = $userWatchesAreaStopRepository->getForUserAndArea($userAccountModel, $area); $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesAreaStop->getAccessKey()); $content->setUserAccount($userAccountModel); $content->setSite($siteModel); $content->setArea($area); $content->setWatchedThingTitle($area->getTitle()); $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/history'); $out[] = $content; } } } return $out; }
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); }