<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Query\Expr;

/**
 * TravelProgramRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class TravelProgramRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * @return TravelProgram[]
     */
    public function getProgramsToExport()
    {
        return $this->createQueryBuilder('tp')
            ->innerJoin('tp.page', 'page')
            ->addSelect('page')
            ->leftJoin('tp.countries', 'country')
            ->addSelect('country')
            ->leftJoin('country.destinations', 'destination')
            ->addSelect('destination')
            ->leftJoin('tp.options', 'option')
            ->addSelect('option')
            ->leftJoin('tp.images', 'image', Expr\Join::WITH, 'image.type = 1')
            ->addSelect('image')
            ->where('tp.status = 1')
            ->andWhere('tp.programType = '. TravelProgram::ORGANIZED_PROGRAM_TYPE)
            ->getQuery()
            ->execute()
            ;
    }
}
