Repository/EventRepository.php
public function searchEventsByUser(
        UserInterface $user,
        \DateTime $from,
        \DateTime $to,
        bool $active = true
    ) {
        $qb = $this->createQueryBuilder('e');

        return $qb
            ->join('e.invitations', 'i')

            // Add conditions.
            ->andWhere($qb->expr()->between('e.start', ':from', ':to'))
            ->andWhere($qb->expr()->eq('i.invitee', ':invitee'))
            ->andWhere($qb->expr()->eq('e.active', ':active'))
            ->andWhere($qb->expr()->orX(
                $qb->expr()->isNull('i.response'),
                $qb->expr()->neq('i.response', ':decline')
            ))

            // Add parameters.
            ->setParameter('from', $from)
            ->setParameter('to', $to)
            ->setParameter('invitee', $user->getUsername())
            ->setParameter('decline', Invitation::RESPONSE_DECLINE)
            ->setParameter('active', $active)

            // Get results.
            ->getQuery()
            ->getResult();
    }
public function searchEventsByUser(
        UserInterface $user,
        \DateTime $from,
        \DateTime $to,
        bool $active = true
    ) {
        $qb = $this->createQueryBuilder('e');

        return $qb
            ->join('e.invitations', 'i')

            // Add conditions.
            ->andWhere($qb->expr()->between('e.start', ':from', ':to'))
            ->andWhere($qb->expr()->eq('i.invitee', ':invitee'))
            ->andWhere($qb->expr()->eq('e.active', ':active'))
            ->andWhere($qb->expr()->orX(
                $qb->expr()->isNull('i.response'),
                $qb->expr()->neq('i.response', ':decline')
            ))

            // Add parameters.
            ->setParameter('from', $from)
            ->setParameter('to', $to)
            ->setParameter('invitee', $user->getUsername())
            ->setParameter('decline', Invitation::RESPONSE_DECLINE)
            ->setParameter('active', $active)

            // Get results.
            ->getQuery()
            ->getResult();
    }
public function searchEventsByUser ( UserInterface $ user , \ DateTime $ from , \ DateTime $ to , bool $ active = true ) { $ qb = $ this -> createQueryBuilder ( 'e' ) ; return $ qb -> join ( 'e.invitations' , 'i' ) // Add conditions. -> andWhere ( $ qb -> expr ( ) -> between ( 'e.start' , ':from' , ':to' ) ) -> andWhere ( $ qb -> expr ( ) -> eq ( 'i.invitee' , ':invitee' ) ) -> andWhere ( $ qb -> expr ( ) -> eq ( 'e.active' , ':active' ) ) -> andWhere ( $ qb -> expr ( ) -> orX ( $ qb -> expr ( ) -> isNull ( 'i.response' ) , $ qb -> expr ( ) -> neq ( 'i.response' , ':decline' ) ) ) // Add parameters. -> setParameter ( 'from' , $ from ) -> setParameter ( 'to' , $ to ) -> setParameter ( 'invitee' , $ user -> getUsername ( ) ) -> setParameter ( 'decline' , Invitation :: RESPONSE_DECLINE ) -> setParameter ( 'active' , $ active ) // Get results. -> getQuery ( ) -> getResult ( ) ; }
Search for events for a user.

@param UserInterface $user   The production to search in.
@param \DateTime     $from   The time to start searching from.
@param \DateTime     $to     The time to end searching from.
@param bool          $active The active state of the events.

@return Event[]
Search for events for a user .