/** * Get a count of unique hits for the current tracking ID * * @param Page|Redirect $page * @param string $trackingId * * @return int * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getHitCountForTrackingId($page, $trackingId) { $q = $this->createQueryBuilder('h')->select('count(h.id) as num'); if ($page instanceof Page) { $q->where('IDENTITY(h.page) = ' . $page->getId()); } elseif ($page instanceof Redirect) { $q->where('IDENTITY(h.redirect) = ' . $page->getId()); } $q->andWhere('h.trackingId = :id')->setParameter('id', $trackingId); $count = $q->getQuery()->getSingleResult(); return (int) $count['num']; }
/** * Determine if the page hit is a unique * * @param Page|Redirect $page * @param string $trackingId * * @return bool */ public function isUniquePageHit($page, $trackingId) { $q = $this->getEntityManager()->getConnection()->createQueryBuilder(); $q2 = $this->getEntityManager()->getConnection()->createQueryBuilder(); $q2->select('null')->from(MAUTIC_TABLE_PREFIX . 'page_hits', 'h'); $expr = $q2->expr()->andX($q2->expr()->eq('h.tracking_id', ':id')); if ($page instanceof Page) { $expr->add($q2->expr()->eq('h.page_id', $page->getId())); } elseif ($page instanceof Redirect) { $expr->add($q2->expr()->eq('h.redirect_id', $page->getId())); } $q2->where($expr); $q->select('u.is_unique')->from(sprintf('(SELECT (NOT EXISTS (%s)) is_unique)', $q2->getSQL()), 'u')->setParameter('id', $trackingId); return (bool) $q->execute()->fetchColumn(); }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }