public function registerSimpleReferencePoint($referenceName, $datasetName, $columnName) { $reference = $this->findReference($referenceName); if (isset($reference)) { $this->unregisterReference($referenceName); } else { $reference = new DatasetReference(); $reference->name = $referenceName; } $referencePoint = $reference->initiatePoint(); $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $datasetName; $referencePointColumn->columnName = $columnName; $referencePoint->registerColumnInstance($referencePointColumn); $reference->registerPointInstance($referencePoint); $this->registerReference($reference); }
protected function mergeWithReference(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceReferenceName, $sourceReference) { $referenceName = NameSpaceHelper::resolveNameSpace($namespace, $sourceReferenceName); $reference = $metamodel->findReference($referenceName); if (isset($reference)) { $metamodel->unregisterReference($referenceName); } else { $reference = new DatasetReference(); $reference->name = $referenceName; } // reference[]/dataset/name foreach ($sourceReference as $pointIndex => $sourcePoint) { if (!isset($sourcePoint->datasetName)) { throw new IllegalStateException(t( '%referenceName reference point definition (index: %pointIndex) does not contain a reference to dataset', array('%referenceName' => $referenceName, '%pointIndex' => $pointIndex))); } $datasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourcePoint->datasetName); // TODO eliminate the following check because we should allow reference definition in separate file which is processed before corresponding datasets are processed // at the same time we do not want to have references which point to 'missing' datasets // we can eliminate such references during final meta model validation if ($metamodel->findDataset($datasetName) == NULL) { continue; } $referencePoint = $reference->initiatePoint(); if (isset($sourcePoint->columnNames)) { foreach ($sourcePoint->columnNames as $columnName) { $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $datasetName; $referencePointColumn->columnName = $columnName; $referencePoint->registerColumnInstance($referencePointColumn); } } else { $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $datasetName; $referencePoint->registerColumnInstance($referencePointColumn); } $reference->registerPointInstance($referencePoint); } $metamodel->registerReference($reference); return $reference; }
protected function mergeWithReference(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceReferenceName, $sourceReference) { $referenceName = NameSpaceHelper::resolveNameSpace($namespace, $sourceReferenceName); $reference = $metamodel->findReference($referenceName); if (isset($reference)) { $metamodel->unregisterReference($referenceName); } else { $reference = new DatasetReference(); $reference->name = $referenceName; } // reference[]/dataset/name foreach ($sourceReference as $pointIndex => $sourcePoint) { if (!isset($sourcePoint->datasetName)) { throw new IllegalStateException(t("'@referenceName' reference point definition (index: @pointIndex) does not contain a reference to dataset", array('@referenceName' => $referenceName, '@pointIndex' => $pointIndex))); } $datasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourcePoint->datasetName); $referencePoint = $reference->initiatePoint(); if (isset($sourcePoint->columnNames)) { foreach ($sourcePoint->columnNames as $columnName) { $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $datasetName; $referencePointColumn->columnName = $columnName; $referencePoint->registerColumnInstance($referencePointColumn); } } else { $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $datasetName; $referencePoint->registerColumnInstance($referencePointColumn); } $reference->registerPointInstance($referencePoint); } $metamodel->registerReference($reference); return $reference; }
public static function prepareReference(MetaModel $metamodel, $referenceNode, array $referencePointNodes = NULL) { $referencePoints = $lookupReferencePoints = $interlookupReferences = NULL; // loading reference points $referencePointIndex = 0; while (TRUE) { $point_nid = get_node_field_int_value($referenceNode, 'field_reference_point', $referencePointIndex, 'nid'); if (!isset($point_nid)) { break; } $referencePointNode = $referencePointNodes[$point_nid]; $datasetName = get_node_field_value($referencePointNode, 'field_ref_point_dataset_sysname', 0, 'value', TRUE); $dataset = $metamodel->findDataset($datasetName); if (isset($dataset)) { $referencePoint = new DatasetReferencePoint(); $lookupReferencePoint = new DatasetReferencePoint(); $loader = MetaModelFactory::getInstance()->getLoader($dataset->loaderName); $cube = $metamodel->getCube($dataset->name); $referenceDatasetName = $cube->factsDatasetName; // preparing list of columns $referencePointColumnIndex = 0; while (TRUE) { $columnName = get_node_field_value($referencePointNode, 'field_ref_point_column_sysname', $referencePointColumnIndex); if (isset($columnName) || ($referencePointColumnIndex === 0)) { $referencePointColumn = $referencePoint->initiateColumn(); $referencePointColumn->datasetName = $referenceDatasetName; $referencePoint->registerColumnInstance($referencePointColumn); if (isset($columnName)) { $referencePointColumn->columnName = $columnName; } $interlookupLookupReferencePointColumn = $lookupReferencePoint->initiateColumn(); $interlookupLookupReferencePointColumn->datasetName = $referenceDatasetName; $interlookupLookupReferencePointColumn->columnName = $referencePointColumn->columnName; ReferenceMetaModelLoaderHelper::adjustReferencePointColumn($loader, $metamodel, $interlookupLookupReferencePointColumn); if (!$interlookupLookupReferencePointColumn->isShared()) { $interlookupReferences[$referencePointColumnIndex][$referencePointIndex] = $interlookupLookupReferencePointColumn; } $lookupReferencePointColumn = clone $interlookupLookupReferencePointColumn; $lookupReferencePointColumn->columnName = NULL; $lookupReferencePoint->registerColumnInstance($lookupReferencePointColumn); } if (!isset($columnName)) { break; } $referencePointColumnIndex++; } $referencePoints[$referencePointIndex] = $referencePoint; $lookupReferencePoints[$referencePointIndex] = $lookupReferencePoint; } $referencePointIndex++; } $referencePointCount = count($referencePoints); if ($referencePointCount == 0) { return; } // checking if we need to add references between lookup reference point columns (second reference point in each reference) if (isset($interlookupReferences)) { // creating separate references for each reference point foreach ($referencePoints as $referencePointIndex => $referencePoint) { $lookupReferencePoint = $lookupReferencePoints[$referencePointIndex]; $reference = new DatasetReference(); $reference->name = get_node_field_value($referenceNode, 'field_reference_sysname', 0, 'value', TRUE) . '_rp' . $referencePointIndex; $reference->registerPointInstance($referencePoint); $reference->registerPointInstance($lookupReferencePoint); $metamodel->registerReference($reference); } // linking lookup reference point columns foreach ($interlookupReferences as $columnIndex => $interlookupReferencePointColumns) { if (count($interlookupReferencePointColumns) < $referencePointCount) { throw new UnsupportedOperationException(t('All reference point columns with the same reference point column index have to be non-shared')); } $interLookupReferenceName = get_node_field_value($referenceNode, 'field_reference_sysname', 0, 'value', TRUE) . '_rpci' . $columnIndex; foreach ($interlookupReferencePointColumns as $interlookupReferencePointColumn) { $metamodel->registerSimpleReferencePoint( $interLookupReferenceName, $interlookupReferencePointColumn->datasetName, $interlookupReferencePointColumn->columnName); } } } else { // checking that all lookup reference points are the same $masterLookupReferencePoint = NULL; foreach ($lookupReferencePoints as $lookupReferencePoint) { if (isset($masterLookupReferencePoint)) { if (!$masterLookupReferencePoint->equals($lookupReferencePoint)) { throw new UnsupportedOperationException(t('Unlinkable lookup reference points are not the same')); } } else { $masterLookupReferencePoint = $lookupReferencePoint; } } // combining all reference points into one reference $reference = new DatasetReference(); $reference->name = get_node_field_value($referenceNode, 'field_reference_sysname', 0, 'value', TRUE); foreach ($referencePoints as $referencePointIndex => $referencePoint) { $lookupReferencePoint = $lookupReferencePoints[$referencePointIndex]; $reference->registerPointInstance($referencePoint); $reference->registerPointInstance($lookupReferencePoint); } $metamodel->registerReference($reference); } }