Skip to content

Instantly share code, notes, and snippets.

@pedrorvidal
Created September 22, 2015 17:57
Show Gist options
  • Select an option

  • Save pedrorvidal/7d1a8b4710684266f7a0 to your computer and use it in GitHub Desktop.

Select an option

Save pedrorvidal/7d1a8b4710684266f7a0 to your computer and use it in GitHub Desktop.
Get background funcionando
/**
*
* @return \Entity\BackgroundHome
*/
public function getBackgroundHome()
{
$hash = $this->getParam()->get('hash');
$backgroundId = $this->getParam()->getInt('id');
$isBackgroundPreview = ($this->getParam()->get('preview') == 'background');
if ($isBackgroundPreview) {
if ($this->verifyHash($hash)) {
$this->getTpl()->addGlobal('pre_visualizacao_bg', true);
return $this->getEm()
->getRepository('Entity\BackgroundHome')
->find($backgroundId);
} else {
throw new \Exception\NotFoundException;
}
}
return $this->getEm()
->getRepository('Entity\BackgroundHome')
->getBackgroundHomeFunc(1);
}
/**
*
* @return object
*/
public function getBackgroundHomeFunc()
{
return $this->getEntityManager()
->createQueryBuilder()
->select('b')
->from('Entity\BackgroundHome', 'b')
->andWhere('b.publicado = 1')
->andWhere('b.dataInicial < CURRENT_DATE()')
->andWhere('b.dataFinal > CURRENT_DATE() OR b.dataFinal IS NULL')
->getQuery()
->setMaxResults(1)->getOneOrNullResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment