/** * {@inheritdoc} */ public function hydrate($qb, array $options = []) { $locale = $options['locale_code']; $scope = $options['scope_code']; $config = $options['attributes_configuration']; $groupId = $options['current_group_id']; $associationTypeId = $options['association_type_id']; $currentProduct = $options['current_product']; $query = $qb->hydrate(false)->getQuery(); $results = $query->execute(); $attributes = []; foreach ($config as $attributeConf) { $attributes[$attributeConf['id']] = $attributeConf; } $rows = []; $fieldsTransformer = new FieldsTransformer(); $valuesTransformer = new ValuesTransformer(); $familyTransformer = new FamilyTransformer(); $complTransformer = new CompletenessTransformer(); $groupsTransformer = new GroupsTransformer(); $assocTransformer = new AssociationTransformer(); foreach ($results as $result) { $result = $fieldsTransformer->transform($result, $locale); $result = $valuesTransformer->transform($result, $attributes, $locale, $scope); $result = $familyTransformer->transform($result, $locale); $result = $complTransformer->transform($result, $locale, $scope); $result = $groupsTransformer->transform($result, $locale, $groupId); $result = $assocTransformer->transform($result, $associationTypeId, $currentProduct); $rows[] = new ResultRecord($result); } return $rows; }
/** * {@inheritdoc} */ public function hydrate($queryBuilder, array $options = []) { $locale = $options['locale_code']; $scope = $options['scope_code']; $config = $options['attributes_configuration']; $groupId = $options['current_group_id']; $associationTypeId = (int) $options['association_type_id']; $currentProduct = $options['current_product']; $query = $queryBuilder->hydrate(false)->getQuery(); $queryDefinition = $query->getQuery(); $hasCurrentProduct = null !== $currentProduct; $sortedByIsAssociated = isset($queryDefinition['sort']['normalizedData.is_associated']); $hasResults = 0 !== $queryDefinition['limit']; if ($hasCurrentProduct && $sortedByIsAssociated && $hasResults) { $associatedIds = $this->getAssociatedProductIds($currentProduct, $associationTypeId); $limit = $queryDefinition['limit']; $skip = $queryDefinition['skip']; $rawQuery = $queryDefinition['query']; if (-1 === (int) $queryDefinition['sort']['normalizedData.is_associated']) { $results = $this->getProductsSortedByIsAssociatedDesc($queryBuilder, $associatedIds, $rawQuery, $limit, $skip, count($associatedIds)); } else { $results = $this->getProductsSortedByIsAssociatedAsc($queryBuilder, $associatedIds, $rawQuery, $limit, $skip, $this->countProducts($queryBuilder, $associatedIds, $rawQuery)); } } else { $results = $query->execute(); } $attributes = []; foreach ($config as $attributeConf) { $attributes[$attributeConf['id']] = $attributeConf; } $rows = []; $fieldsTransformer = new FieldsTransformer(); $valuesTransformer = new ValuesTransformer(); $familyTransformer = new FamilyTransformer(); $complTransformer = new CompletenessTransformer(); $groupsTransformer = new GroupsTransformer(); $assocTransformer = new AssociationTransformer(); foreach ($results as $result) { $result = $fieldsTransformer->transform($result, $locale); $result = $valuesTransformer->transform($result, $attributes, $locale, $scope); $result = $familyTransformer->transform($result, $locale); $result = $complTransformer->transform($result, $locale, $scope); $result = $groupsTransformer->transform($result, $locale, $groupId); $result = $assocTransformer->transform($result, $associationTypeId, $currentProduct); $result['is_checked'] = $result['is_associated']; $rows[] = new ResultRecord($result); } return $rows; }
/** * {@inheritdoc} */ public function hydrate($queryBuilder, array $options = []) { $locale = $options['locale_code']; $scope = $options['scope_code']; $config = $options['attributes_configuration']; $groupId = $options['current_group_id']; $associationTypeId = $options['association_type_id']; $currentProduct = $options['current_product']; $query = $queryBuilder->hydrate(false)->getQuery(); $queryDefinition = $query->getQuery(); $hasCurrentProduct = null !== $currentProduct; $sortedByIsAssociated = isset($queryDefinition['sort']['normalizedData.is_associated']); $hasResults = 0 !== $queryDefinition['limit']; if ($hasCurrentProduct && $sortedByIsAssociated && $hasResults) { $documentManager = $query->getDocumentManager(); $productFields = $documentManager->getClassMetadata($this->productClass)->getFieldNames(); $pipeline = $this->pipelineFromQuery($currentProduct, $queryDefinition, $productFields, $associationTypeId); $collection = $documentManager->getDocumentCollection($this->productClass); $results = $collection->aggregate($pipeline)->toArray(); } else { $results = $query->execute(); } $attributes = []; foreach ($config as $attributeConf) { $attributes[$attributeConf['id']] = $attributeConf; } $rows = []; $fieldsTransformer = new FieldsTransformer(); $valuesTransformer = new ValuesTransformer(); $familyTransformer = new FamilyTransformer(); $complTransformer = new CompletenessTransformer(); $groupsTransformer = new GroupsTransformer(); foreach ($results as $result) { $result = $fieldsTransformer->transform($result, $locale); $result = $valuesTransformer->transform($result, $attributes, $locale, $scope); $result = $familyTransformer->transform($result, $locale); $result = $complTransformer->transform($result, $locale, $scope); $result = $groupsTransformer->transform($result, $locale, $groupId); $result['is_checked'] = $result['is_associated']; $rows[] = new ResultRecord($result); } return $rows; }