public function countUnread(User $user)
    {
        return $this->createQueryBuilder('m')
            ->select('count(m)')
            ->join('m.userMessages', 'um')
            ->where('m.user != :sender')
            ->orWhere('m.user IS NULL')
            ->andWhere('um.user = :user')
            ->andWhere('um.isRead = 0')
            ->andWhere('um.isRemoved = 0')
            ->setParameter(':user', $user)
            ->setParameter(':sender', $user)
            ->getQuery()
            ->getSingleScalarResult();
    }
public function countUnread(User $user)
    {
        return $this->createQueryBuilder('m')
            ->select('count(m)')
            ->join('m.userMessages', 'um')
            ->where('m.user != :sender')
            ->orWhere('m.user IS NULL')
            ->andWhere('um.user = :user')
            ->andWhere('um.isRead = 0')
            ->andWhere('um.isRemoved = 0')
            ->setParameter(':user', $user)
            ->setParameter(':sender', $user)
            ->getQuery()
            ->getSingleScalarResult();
    }
public function countUnread ( User $ user ) { return $ this -> createQueryBuilder ( 'm' ) -> select ( 'count(m)' ) -> join ( 'm.userMessages' , 'um' ) -> where ( 'm.user != :sender' ) -> orWhere ( 'm.user IS NULL' ) -> andWhere ( 'um.user = :user' ) -> andWhere ( 'um.isRead = 0' ) -> andWhere ( 'um.isRemoved = 0' ) -> setParameter ( ':user' , $ user ) -> setParameter ( ':sender' , $ user ) -> getQuery ( ) -> getSingleScalarResult ( ) ; }
Counts the number of unread messages of a user.

@param User $user

@return integer
Counts the number of unread messages of a user .