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);
        }
    }
function get_node_field_boolean_value($node, $fieldName, $index = 0, $storageSuffixName = 'value', $default = FALSE) {
    $value = get_node_field_int_value($node, $fieldName, $index, $storageSuffixName);

    $result = $default;
    if (is_array($value)) {
        $vs = array();
        foreach ($value as $i => $v) {
            $vs[$i] = $v == 1;
        }
        $result = $vs;
    }
    elseif (isset($value)) {
        $result = $value == 1;
    }

    return $result;
}
Beispiel #3
0
function get_node_field_boolean_value($node, $propertyName, $index = 0, $storageSuffixName = 'value', $default = FALSE)
{
    $value = get_node_field_int_value($node, $propertyName, $index, $storageSuffixName);
    return isset($value) ? $value == 1 : $default;
}