public function findOneElement($class, UserInterface $user = null) {
        $em = $this->getDoctrine()->getManager();
        $alias = "o";
        $qb = $em->createQueryBuilder()
                ->select($alias)
                ->from($class, $alias);
        if ($user !== null) {
            $qb
                    ->andWhere("o.user = :user")
                    ->setParameter("user", $user)
            ;
        }
        $qb->orderBy("o.createdAt", "DESC");
        $entity = $qb->setMaxResults(1)->getQuery()->getOneOrNullResult();
        return $entity;
    }
public function findOneElement($class, UserInterface $user = null) {
        $em = $this->getDoctrine()->getManager();
        $alias = "o";
        $qb = $em->createQueryBuilder()
                ->select($alias)
                ->from($class, $alias);
        if ($user !== null) {
            $qb
                    ->andWhere("o.user = :user")
                    ->setParameter("user", $user)
            ;
        }
        $qb->orderBy("o.createdAt", "DESC");
        $entity = $qb->setMaxResults(1)->getQuery()->getOneOrNullResult();
        return $entity;
    }
public function findOneElement ( $ class , UserInterface $ user = null ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ alias = "o" ; $ qb = $ em -> createQueryBuilder ( ) -> select ( $ alias ) -> from ( $ class , $ alias ) ; if ( $ user !== null ) { $ qb -> andWhere ( "o.user = :user" ) -> setParameter ( "user" , $ user ) ; } $ qb -> orderBy ( "o.createdAt" , "DESC" ) ; $ entity = $ qb -> setMaxResults ( 1 ) -> getQuery ( ) -> getOneOrNullResult ( ) ; return $ entity ; }
Devuelve el primer elemento que encuentr de la base de datos
@param type $class
@return type
Devuelve el primer elemento que encuentr de la base de datos