Ejemplo n.º 1
0
 /**
  * @param $root Response root element.
  *
  * @throws OLAPException
  */
 private function createMetaData(DOMElement $root)
 {
     $olapInfo = XMLAUtil::findChild($root, XMLAUtil::MDDATASET_NS, "OlapInfo");
     $cubeInfo = XMLAUtil::findChild($olapInfo, XMLAUtil::MDDATASET_NS, "CubeInfo");
     $cubeNode = XMLAUtil::findChild($cubeInfo, XMLAUtil::MDDATASET_NS, "Cube");
     $cubeNameNode = XMLAUtil::findChild($cubeNode, XMLAUtil::MDDATASET_NS, "CubeName");
     $cubeName = XMLAUtil::gatherText($cubeNameNode);
     // REVIEW: If there are multiple cubes with the same name, we should
     // qualify by catalog and schema. Currently we just take the first.
     $cube = $this->lookupCube($this->statement->getConnection()->getMetadata(), $cubeName);
     if ($cube == null) {
         throw new OLAPException("Internal error: cube '{$cubeName}' not found.");
     }
     // REVIEW: We should not modify the connection. It is not safe, because
     // connection might be shared between multiple statements with different
     // cubes. Caller should call
     //
     // connection.setCatalog(
     //   cellSet.getMetaData().getCube().getSchema().getCatalog().getName())
     //
     // before doing metadata queries.
     $this->statement->getConnection()->setCatalog($cube->getSchema()->getCatalog()->getName());
     $axesInfo = XMLAUtil::findChild($olapInfo, XMLAUtil::MDDATASET_NS, "AxesInfo");
     $axisInfos = XMLAUtil::findChildren($axesInfo, XMLAUtil::MDDATASET_NS, "AxisInfo");
     $axisMetaDataList = array();
     $filterAxisMetaData = null;
     foreach ($axisInfos as $axisInfo) {
         $axisName = $axisInfo->getAttribute('name');
         $axis = $this->lookupAxis($axisName);
         $hierarchyInfos = XMLAUtil::findChildren($axisInfo, XMLAUtil::MDDATASET_NS, 'HierarchyInfo');
         $hierarchyList = array();
         /*
                 <OlapInfo>
            <AxesInfo>
                <AxisInfo name="Axis0">
                    <HierarchyInfo name="Customers">
                        <UName name="[Customers].[MEMBER_UNIQUE_NAME]"/>
                        <Caption name="[Customers].[MEMBER_CAPTION]"/>
                        <LName name="[Customers].[LEVEL_UNIQUE_NAME]"/>
                        <LNum name="[Customers].[LEVEL_NUMBER]"/>
                        <DisplayInfo name="[Customers].[DISPLAY_INFO]"/>
                    </HierarchyInfo>
                </AxisInfo>
                ...
            </AxesInfo>
            <CellInfo>
                <Value name="VALUE"/>
                <FmtValue name="FORMATTED_VALUE"/>
                <FormatString name="FORMAT_STRING"/>
            </CellInfo>
                 </OlapInfo>
         */
         $propertyList = array();
         foreach ($hierarchyInfos as $hierarchyInfo) {
             $hierarchyName = $hierarchyInfo->getAttribute('name');
             $hierarchy = $this->lookupHierarchy($cube, $hierarchyName);
             $hierarchyList[] = $hierarchy;
             foreach (XMLAUtil::childElements($hierarchyInfo) as $childNode) {
                 $tag = $childNode->localName;
                 if (in_array($tag, self::$standardProperties)) {
                     continue;
                 }
                 $propertyUniqueName = $childNode->getAttribute('name');
                 $property = new XMLACellSetMemberProperty($propertyUniqueName, $hierarchy, $tag);
                 $propertyList[] = $property;
             }
         }
         $axisMetaData = new XMLACellSetAxisMetaData($this->statement->getConnection(), $axis, $hierarchyList, $propertyList);
         if ($axis->isFilter()) {
             $filterAxisMetaData = $axisMetaData;
         } else {
             $axisMetaDataList[] = $axisMetaData;
         }
     }
     if ($filterAxisMetaData == null) {
         $filterAxisMetaData = new XMLACellSetAxisMetaData($this->statement->getConnection(), Axis::getEnum(Axis::FILTER), array(), array());
     }
     $cellInfo = XMLAUtil::findChild($olapInfo, XMLAUtil::MDDATASET_NS, 'CellInfo');
     $cellProperties = array();
     foreach (XMLAUtil::childElements($cellInfo) as $element) {
         $cellProperties[] = new XMLACellProperty($element->localName, $element->getAttribute('name'));
     }
     return new XMLACellSetMetaData($this->statement, $cube, $filterAxisMetaData, $axisMetaDataList, $cellProperties);
 }