简体   繁体   中英

How do I separate the results

I have the following query on Doctrine QueryBuilder:

$qb = $this->createQueryBuilder('e')
            ->select('e.id, e.name, e.body, e.teaser, e.slug, e.dateBegin, e.dateEnd, e.dateTbd, v.name AS v_name')
            ->innerJoin('e.venue', 'v')
            ->where('v.name LIKE :TBD')
            ->orWhere('v.name LIKE :TBA')
            ->orWhere('e.name LIKE :TBD')
            ->orWhere('e.name LIKE :TBA')
            ->orWhere('e.name LIKE \'none\'')
            ->orWhere('e.name LIKE \'n/a\'')
            ->orWhere('e.teaser LIKE :TBD')
            ->orWhere('e.body LIKE :TBD')
            ->orWhere('e.dateTbd=true')
            ->orWhere('TIME(e.dateBegin) < :earlyMorning AND TIME(e.dateBegin) > :lateNight')
            ->setParameter('TBA', '%TBA%')
            ->setParameter('TBD', '%TBD%')
            ->setParameter('earlyMorning', '06:00:00')
            ->setParameter('lateNight', '23:00:00');

How I can separate the results by 'where' clause in this query. I need to display every event with criteria which listed in where clause.

I can't see a way of achieving this easily, especially if we are to assume you're using this to retrieve a standard doctrine entity collection, since additional grouping / properties wouldn't really be something you could pass into these.

If you need to group these simply to display them slightly differently as they're output, say, in your markup, I'd consider adding additional methods into your entity's class to allow you detect which 'type' they are based on similar criteria defined in your query, eg using standard string matching functions.

Otherwise your options are going to be filtering the collection (ArrayCollections carry a method for doing that easily) or separating it out into multiple queries, which given your approach, I assume you are trying to avoid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM