コード例 #1
0
 public function fetchRelatedObjectRefsOfEntity(MySQLi $mySQLi, ObjectEntity $otherEntity, QueryContext $queryContext, Scope $scope, array &$fetchedObjectRefs)
 {
     // Find the corresponding relationship, ignoring link-relationships.
     $hasTerminatedObjects = FALSE;
     foreach ($this->objectEntity->getRelationships() as $relationship) {
         if ($relationship->getOppositeEntity($this->objectEntity) != $otherEntity) {
             continue;
         }
         // Select the id of the related object.
         $objectIdColumnName = $otherEntity->getObjectIdColumnName();
         $query = new QueryRelatedEntity($this->objectEntity, $this->id, $relationship, $queryContext, $scope);
         $query->setPropertyNames(array($objectIdColumnName));
         $queryString = $query->getQueryString();
         $queryResult = $mySQLi->query($queryString);
         if (!$queryResult) {
             throw new Exception("Error fetching ObjectRefs of entity '" . $otherEntity->getName() . "', associated to '" . $this->objectEntity->getName() . "[{$this->id}]' - " . $mySQLi->error . "\n<!--\n{$queryString}\n-->");
         }
         while ($dbObject = $queryResult->fetch_assoc()) {
             $objectRef = new ObjectRef($otherEntity, $dbObject[$objectIdColumnName]);
             if (!$queryContext->getParameterPublished() and isset($dbObject[QueryEntity::ID_TERMINATED])) {
                 $hasTerminatedObjects = TRUE;
             } else {
                 // Always use the objectRef if we're fetching published data or if it's not terminated.
                 $fetchedObjectRefs[] = $objectRef;
             }
         }
         $queryResult->close();
     }
     return $hasTerminatedObjects;
 }