Newscoop\Entity\Repository\UserRepository::isUnique PHP Метод

isUnique() публичный Метод

Test if property value is unique
public isUnique ( string $property, string $value, integer $id = null ) : boolean
$property string
$value string
$id integer
Результат boolean
    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();
    }