public function isUnique($property, $value, $id = null)
{
$qb = $this->getEntityManager()->createQueryBuilder()->select('COUNT(u.id)')->from('Newscoop\\Entity\\User', 'u')->where("LOWER(u.{$property}) = LOWER(?0)");
$params = array($value);
if ($id !== null) {
$qb->andWhere('u.id <> ?1');
$params[] = $id;
}
$qb->setParameters($params);
return !$qb->getQuery()->getSingleScalarResult();
}