Esempio n. 1
0
 /**
  * Execute queries for expansion.
  * 
  * @param array(mixed)/mixed $result Resource(s) whose navigation properties needs to be expanded.
  *
  *
  * @return void
  */
 private function _executeExpansion($result)
 {
     $expandedProjectionNodes = $this->_getExpandedProjectionNodes();
     foreach ($expandedProjectionNodes as $expandedProjectionNode) {
         $isCollection = $expandedProjectionNode->getResourceProperty()->getKind() == ResourcePropertyKind::RESOURCESET_REFERENCE;
         $expandedPropertyName = $expandedProjectionNode->getResourceProperty()->getName();
         if (is_array($result)) {
             foreach ($result as $entry) {
                 // Check for null entry
                 if ($isCollection) {
                     $currentResourceSet = $this->_getCurrentResourceSetWrapper()->getResourceSet();
                     $resourceSetOfProjectedProperty = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
                     $projectedProperty1 = $expandedProjectionNode->getResourceProperty();
                     $result1 = $this->providers->getRelatedResourceSet(QueryType::ENTITIES(), $currentResourceSet, $entry, $resourceSetOfProjectedProperty, $projectedProperty1, null, null, null, null)->results;
                     if (!empty($result1)) {
                         $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
                         if (!is_null($internalOrderByInfo)) {
                             $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
                             usort($result1, $orderByFunction);
                             unset($internalOrderByInfo);
                             $takeCount = $expandedProjectionNode->getTakeCount();
                             if (!is_null($takeCount)) {
                                 $result1 = array_slice($result1, 0, $takeCount);
                             }
                         }
                         $entry->{$expandedPropertyName} = $result1;
                         $projectedProperty = $expandedProjectionNode->getResourceProperty();
                         $needPop = $this->_pushSegmentForNavigationProperty($projectedProperty);
                         $this->_executeExpansion($result1);
                         $this->_popSegment($needPop);
                     } else {
                         $entry->{$expandedPropertyName} = array();
                     }
                 } else {
                     $currentResourceSet1 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
                     $resourceSetOfProjectedProperty1 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
                     $projectedProperty2 = $expandedProjectionNode->getResourceProperty();
                     $result1 = $this->providers->getRelatedResourceReference($currentResourceSet1, $entry, $resourceSetOfProjectedProperty1, $projectedProperty2);
                     $entry->{$expandedPropertyName} = $result1;
                     if (!is_null($result1)) {
                         $projectedProperty3 = $expandedProjectionNode->getResourceProperty();
                         $needPop = $this->_pushSegmentForNavigationProperty($projectedProperty3);
                         $this->_executeExpansion($result1);
                         $this->_popSegment($needPop);
                     }
                 }
             }
         } else {
             if ($isCollection) {
                 $currentResourceSet2 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
                 $resourceSetOfProjectedProperty2 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
                 $projectedProperty4 = $expandedProjectionNode->getResourceProperty();
                 $result1 = $this->providers->getRelatedResourceSet(QueryType::ENTITIES(), $currentResourceSet2, $result, $resourceSetOfProjectedProperty2, $projectedProperty4, null, null, null, null)->results;
                 if (!empty($result1)) {
                     $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
                     if (!is_null($internalOrderByInfo)) {
                         $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
                         usort($result1, $orderByFunction);
                         unset($internalOrderByInfo);
                         $takeCount = $expandedProjectionNode->getTakeCount();
                         if (!is_null($takeCount)) {
                             $result1 = array_slice($result1, 0, $takeCount);
                         }
                     }
                     $result->{$expandedPropertyName} = $result1;
                     $projectedProperty7 = $expandedProjectionNode->getResourceProperty();
                     $needPop = $this->_pushSegmentForNavigationProperty($projectedProperty7);
                     $this->_executeExpansion($result1);
                     $this->_popSegment($needPop);
                 } else {
                     $result->{$expandedPropertyName} = array();
                 }
             } else {
                 $currentResourceSet3 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
                 $resourceSetOfProjectedProperty3 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
                 $projectedProperty5 = $expandedProjectionNode->getResourceProperty();
                 $result1 = $this->providers->getRelatedResourceReference($currentResourceSet3, $result, $resourceSetOfProjectedProperty3, $projectedProperty5);
                 $result->{$expandedPropertyName} = $result1;
                 if (!is_null($result1)) {
                     $projectedProperty6 = $expandedProjectionNode->getResourceProperty();
                     $needPop = $this->_pushSegmentForNavigationProperty($projectedProperty6);
                     $this->_executeExpansion($result1);
                     $this->_popSegment($needPop);
                 }
             }
         }
     }
 }