/** * @param StaticSegment $staticSegment * * {@inheritdoc} */ protected function createSubordinateIterator($staticSegment) { $this->assertRequiredDependencies(); if (!$staticSegment->getExtendedMergeVars()) { return new \EmptyIterator(); } $qb = $this->getIteratorQueryBuilder($staticSegment); $marketingList = $staticSegment->getMarketingList(); $memberIdentifier = MarketingListQueryBuilderAdapter::MEMBER_ALIAS . '.id'; $fieldExpr = $this->fieldHelper->getFieldExpr($marketingList->getEntity(), $qb, $this->doctrineHelper->getSingleEntityIdentifierFieldName($marketingList->getEntity())); $qb->addSelect($fieldExpr . ' AS entity_id'); $qb->addSelect($memberIdentifier . ' AS member_id'); $qb->andWhere($qb->expr()->andX($qb->expr()->isNotNull($memberIdentifier))); $bufferedIterator = new BufferedQueryResultIterator($qb); $bufferedIterator->setHydrationMode(AbstractQuery::HYDRATE_ARRAY)->setReverse(true); $uniqueMembers =& $this->uniqueMembers; return new \CallbackFilterIterator($bufferedIterator, function (&$current) use($staticSegment, &$uniqueMembers) { if (is_array($current)) { if (!empty($current['member_id']) && in_array($current['member_id'], $uniqueMembers, true)) { return false; } $current['subscribersList_id'] = $staticSegment->getSubscribersList()->getId(); $current['static_segment_id'] = $staticSegment->getId(); $uniqueMembers[] = $current['member_id']; unset($current['id']); } return true; }); }
/** * {@inheritdoc} */ protected function createSubordinateIterator($staticSegment) { $vars = $this->provider->provideExtendedMergeVars($staticSegment->getMarketingList()); $varNames = array_map(function ($each) { return $each['name']; }, $vars); $qb = $this->doctrineHelper->getEntityManager($this->extendedMergeVarClassName)->getRepository($this->extendedMergeVarClassName)->createQueryBuilder('extendedMergeVar'); $qb->select(['extendedMergeVar.id', $staticSegment->getId() . ' static_segment_id', 'extendedMergeVar.name', $qb->expr()->literal(ExtendedMergeVar::STATE_REMOVE) . ' state']); $qb->where($qb->expr()->andX($qb->expr()->eq('extendedMergeVar.staticSegment', ':staticSegment'), $qb->expr()->notIn('extendedMergeVar.name', ':vars'), $qb->expr()->neq('extendedMergeVar.state', ':state')))->setParameter('staticSegment', $staticSegment)->setParameter('vars', $varNames)->setParameter('state', ExtendedMergeVar::STATE_DROPPED); $bufferedIterator = new BufferedQueryResultIterator($qb); $bufferedIterator->setHydrationMode(AbstractQuery::HYDRATE_ARRAY)->setReverse(true); return $bufferedIterator; }
/** * @param StaticSegment $staticSegment * * {@inheritdoc} */ protected function createSubordinateIterator($staticSegment) { $qb = $this->getIteratorQueryBuilder($staticSegment); $qb->andWhere($qb->expr()->isNull(MarketingListQueryBuilderAdapter::MEMBER_ALIAS . '.id')); $bufferedIterator = new BufferedQueryResultIterator($qb); $bufferedIterator->setHydrationMode(AbstractQuery::HYDRATE_ARRAY)->setReverse(true); $bufferedIterator->setBufferSize(self::BUFFER_SIZE); return new \CallbackFilterIterator($bufferedIterator, function (&$current) use($staticSegment) { if (is_array($current)) { $current['subscribersList_id'] = $staticSegment->getSubscribersList()->getId(); $current['entityClass'] = $staticSegment->getMarketingList()->getEntity(); } return true; }); }
public function testIteratorWithArrayHydrationMode() { $records = [['a_0' => '1'], ['a_0' => '2'], ['a_0' => '3']]; $actualSqls = []; $statementCounter = 0; $statements = [$this->createFetchStatementMock([['sclr_0' => count($records)]]), $this->createFetchStatementMock([$records[0], $records[1], $records[2]])]; $this->getDriverConnectionMock($this->em)->expects($this->any())->method('query')->will($this->returnCallback(function ($sql) use(&$statements, &$statementCounter, &$actualSqls) { $actualSqls[$statementCounter] = $sql; $statement = $statements[$statementCounter]; $statementCounter++; return $statement; })); $source = $this->em->createQueryBuilder()->select('o')->from('Stub:Entity', 'o'); $iterator = new BufferedQueryResultIterator($source); $iterator->setHydrationMode(Query::HYDRATE_ARRAY); $this->assertEquals(count($records), $iterator->count()); $count = 0; foreach ($iterator as $record) { $this->assertEquals($records[$count]['a_0'], $record['a']); $count++; } $this->assertEquals(count($records), $count); $this->assertEquals('SELECT count(e0_.a) AS sclr_0 FROM Entity e0_', $actualSqls[0]); $this->assertEquals('SELECT e0_.a AS a_0, e0_.b AS b_1 FROM Entity e0_ LIMIT ' . BufferedQueryResultIterator::DEFAULT_BUFFER_SIZE . ' OFFSET 0', $actualSqls[1]); }