/** * @param Article $article */ public function processArticle(Article $article) { $session = $this->request->getSession(); $viewedArticles = $session->get('viewedArticles', []); $articleId = $article->getId(); if (!isset($viewedArticles[$articleId])) { $viewedArticles[$articleId] = true; $article->increaseViewsCount(); $session->set('viewedArticles', $viewedArticles); $this->em->flush($article); } }
/** * @param Response $response * @param Article $article * @param string $type */ private function addToRated(Response $response, Article $article, $type) { $articleId = $article->getId(); $key = "harentius_blog_articles_{$type}"; $rated = json_decode($this->getRequest()->cookies->get($key, '[]')); if (!in_array($articleId, $rated)) { $rated[] = $articleId; $response->headers->setCookie(new Cookie($key, json_encode($rated))); $this->cache->save($ip = $this->getRequest()->getClientIp(), true, self::TIME_TO_REMEMBER_IP); } }