/** * Populate a property that is supposed to contain an entity or collection * of entities if it is not already populated * * @param mixed $property */ protected function _populateRelatedObject($property, $params = array()) { // Don't populate the related object if it already is if (is_array($this->{$property}) || is_object($this->{$property})) { return; } $mappings = $this->_gamineservice->getMappedProperty($this->entity_key, $property); $primary_key = $this->_gamineservice->getPrimaryKeyProperty($this->entity_key); $final_resource_location = ''; if ($mappings['relates']['relative']) { $final_resource_location .= $this->_getResourceLocation() . '/'; } else { $fkey = $mappings['relates']['related_by']; $params[$fkey] = $this->getDataArrayIdentifierValue(); } if ($mappings['relates']['collection']) { $final_resource_location .= $this->_gamineservice->getCollectionResource($mappings['relates']['entity']); } else { $entity_path = $this->_gamineservice->getEntityResource($mappings['relates']['entity']); if (strpos($entity_path, '{:id}')) { $final_resource_location .= str_ireplace('{:id}', $this->getDataArrayIdentifierValue(), $entity_path); } elseif ($mappings['relates']['related_by']) { $final_resource_location .= $entity_path . '/' . $params[$fkey]; } else { $final_resource_location .= $entity_path; } } $data = $this->_gamineservice->getManager($mappings['relates']['entity'])->getAccessService()->call($final_resource_location, 'GET', $params, false); $this->_mapRelationData($property, $data, $mappings['relates']); }