class RegionRepository extends \Doctrine\ORM\EntityRepository { public function findAvailableRegions() { $qb = $this->createQueryBuilder('r'); return $qb ->join('r.houses', 'h') ->join('h.developer', 'd') # start ->innerJoin('h.apartments', 'a') // ->where('h.longitude IS NOT NULL') // ->andWhere('h.latitude IS NOT NULL') //, ->andWhere('h.description IS NOT NULL') //*... .. .. # end # start ->andWhere('d.verified') // - ... # end ->getQuery() ->getResult(); } public function findAvailableRegionsByDeveloper(DeveloperCompany $developerCompany) { $qb = $this->createQueryBuilder('r'); return $qb ->join('r.houses', 'h') ->join('h.developer', 'd') # start ->innerJoin('h.apartments', 'a') // ->where('h.longitude IS NOT NULL') // ->andWhere('h.latitude IS NOT NULL') //, ->andWhere('h.description IS NOT NULL') //*... .. .. # end ->andWhere('d.id = :developer_id') ->setParameter('developer_id', $developerCompany->getId()) ->getQuery() ->getResult(); } }
class HouseRepository extends \Doctrine\ORM\EntityRepository { public function findAvailableHouses() { $qb = $this->createQueryBuilder('h'); return $qb ->join('h.developer', 'd') ->innerJoin('h.apartments', 'a') // ->where('h.longitude IS NOT NULL') // ->andWhere('h.latitude IS NOT NULL') // ->andWhere('h.description IS NOT NULL') // #!!! ->where('d.verified') //, . ... ->getQuery() ->getResult(); } }
class DeveloperCompanyRepository extends \Doctrine\ORM\EntityRepository { public function findAvailableDevelopers() { return $this->createQueryBuilder('d') ->where('d.verified') //........ ->getQuery() ->getResult(); } }
use Happyr\DoctrineSpecification\BaseSpecification; use Happyr\DoctrineSpecification\Spec; class CorrectDeveloperSpecification extends BaseSpecification { public function getSpec() { return Spec::eq('verified', true); } }
use Happyr\DoctrineSpecification\BaseSpecification; use Happyr\DoctrineSpecification\Spec; class CorrectHouseSpecification extends BaseSpecification { public function getSpec() { Spec::andX( Spec::innerJoin('apartments', 'a'), Spec::innerJoin('developer', 'd'), Spec::isNotNull('description'), Spec::isNotNull('longitude'), Spec::isNotNull('latitude'), new CorrectDeveloperSpecification('d') ); } }
use Happyr\DoctrineSpecification\BaseSpecification; use Happyr\DoctrineSpecification\Spec; class CorrectRegionSpecification extends BaseSpecification { public function getSpec() { return Spec::andX( Spec::innerJoin('houses', 'h'), new CorrectHouseSpecification('h') ); } }
use AppBundle\Entity\DeveloperCompany; use Happyr\DoctrineSpecification\BaseSpecification; use Happyr\DoctrineSpecification\Spec; class CorrectOccupiedRegionByDeveloperSpecification extends BaseSpecification { /** @var DeveloperCompany */ private $developer; public function __construct(DeveloperCompany $developerCompany, $dqlAlias = null) { parent::__construct($dqlAlias); $this->developer = $developerCompany; } public function getSpec() { return Spec::andX( new CorrectRegionSpecification(), Spec::join('developer', 'd', 'h'), Spec::eq('d.id', $this->developer->getId()) ); } }
class RegionRepository extends EntitySpecificationRepository { public function findAvailableRegions() { return $this->match( new CorrectRegionSpecification() ); } public function findAvailableRegionsByDeveloper(DeveloperCompany $developerCompany) { return $this->match( new CorrectOccupiedRegionByDeveloperSpecification($developerCompany) ); } }
class HouseRepository extends EntitySpecificationRepository { public function findAvailableHouses() { return $this->match( new CorrectHouseSpecification() ); } }
class DeveloperCompanyRepository extends EntitySpecificationRepository { public function findAvailableDevelopers() { return $this->match( new CorrectDeveloperSpecification() ); } }
Source: https://habr.com/ru/post/334404/
All Articles