/** * Add click * * @param \Main\SiteBundle\Entity\Click $click * @return Link */ public function addClick(\Main\SiteBundle\Entity\Click $click) { $this->click[] = $click; $click->setLink($this); return $this; }
public function shortenerAction($short) { $repository = $this->getDoctrine()->getManager()->getRepository('MainSiteBundle:Link'); $lien = $repository->findOneBy(array('lien_small' => $short)); if (is_object($lien)) { if ($lien->getActivate()) { $countryUser = file_get_contents("http://api.hostip.info/country.php?ip=" . $_SERVER['REMOTE_ADDR']); $referrerUrl = parse_url($this->get('request')->headers->get('referer'), PHP_URL_HOST); if ($referrerUrl == NULL) { $referrerUrl = "Direct"; } if ($countryUser == "XX") { $countryUser = "******"; } $click = new Click(); $click->setLink($lien)->setCountry($countryUser)->setReferrer($referrerUrl); $this->getDoctrine()->getEntityManager()->persist($click); $this->getDoctrine()->getEntityManager()->flush(); return $this->redirect($lien->getLienReel()); } else { return $this->render('MainSiteBundle:Default:falselink.html.twig'); } } else { return $this->render('MainSiteBundle:Default:nolink.html.twig'); } }