/** * * @param type $class * @return string */ public function getMostVisitedEntities(\Twig_Environment $twig, $entity_name) { $class = $this->params[$entity_name]['class']; $globalVisits = $this->gvm->findByClass($class, array('number_visits' => 'DESC'), 5, 0); if (0 >= count($globalVisits)) { return ''; } $entities = $this->gvm->findEntitiesByGlobalVisitsAndClass($globalVisits, $class); return $twig->render($this->params[$entity_name]['view'], array('entities' => null === $entities ? array() : $entities)); }
/** * * @param type $uri * @param type $entity * @return VisitedPage */ public function createVisitedPage($uri, $entity = null) { if (false === $this->trackAdmins && true === $this->authChecker->isGranted('ROLE_ADMIN')) { return; } $visited_page = new VisitedPage(); $event = new VisitedPageEvent($visited_page); $this->dispatcher->dispatch(MetricsEvents::PRE_SAVE_VISITED, $event); $visited_page->setUri($uri); $this->em->persist($visited_page); $globalVisits = $this->gvm->findOneGlobalVisitByUri($uri); if (null === $globalVisits) { $globalVisits = $this->gvm->createGlobalVisit($uri, $entity); } else { $globalVisits = $this->gvm->updateGlobalVisit($uri); } $this->em->flush(); return $visited_page; }