public function indexAction(Request $request) { $dateRange = new StatsDateRange(); $dateRange->setFromRequest($request); $repositoryBuilder = new VisitorSessionRepositoryBuilder(); $repositoryBuilder->setDateRange($dateRange); $doctrine = $this->getDoctrine()->getManager(); $treeRepo = $doctrine->getRepository('QuestionKeyBundle:VisitorSession'); $sessions = $treeRepo->findByBuilder($repositoryBuilder); return $this->render('QuestionKeyBundle:AdminVisitorSessionList:index.html.twig', array('dateRange' => $dateRange, 'sessions' => $sessions)); }
public function findByBuilder(VisitorSessionRepositoryBuilder $visitorSessionRepositoryBuilder) { $where = array(); $params = array(); if ($visitorSessionRepositoryBuilder->getDateRange()) { $where[] = ' vs.createdAt > :from AND vs.createdAt < :to'; $params['from'] = $visitorSessionRepositoryBuilder->getDateRange()->getFrom(); $params['to'] = $visitorSessionRepositoryBuilder->getDateRange()->getTo(); } $s = $this->getEntityManager()->createQuery(' SELECT vs FROM QuestionKeyBundle:VisitorSession vs' . ' WHERE ' . implode(" AND ", $where))->setParameters($params)->getResult(); return $s; }