public function testColumnDescriptionCustomProperties() { $cd = new ColumnDescription('first', ValueType::STRING); $cd->setCustomProperty('a', 'foo'); $properties = $cd->getCustomProperties(); $this->assertTrue(is_array($properties), "properties must be an array"); $this->assertArrayHasKey('a', $properties, "properties[a] must exist"); $this->assertSame('foo', $cd->getCustomProperty('a'), "getCustomProperty must return expected value"); }
public function &initPivotTable() { $dataOut = new DataTable(); $dataIn =& $this->pivotDescription->getDataTable(); // First add all the row fields. // Just copy these as-is from the input DataTable $rowFieldIndexes = $this->getRowFieldIndexes(); foreach ($rowFieldIndexes as $columnIndex) { $columnDescription = $dataIn->getColumnDescription($columnIndex); $columnDescription->setCustomProperty('rowFieldIndex', $columnIndex); $dataOut->addColumn($columnDescription); } // Next add a column for each unique column in // the column key index $columnDescriptions = array(); $columnFieldIndexes = $this->getColumnFieldIndexes(); $numColumnFields = count($columnFieldIndexes); foreach ($columnFieldIndexes as $columnIndex) { $columnDescription = $dataIn->getColumnDescription($columnIndex); $columnDescriptions[] = $columnDescription; } $dataColumnDescriptions = array(); $dataFieldIndexes = $this->getDataFieldIndexes(); $numDataFields = count($dataFieldIndexes); foreach ($dataFieldIndexes as $columnIndex) { $columnDescription = $dataIn->getColumnDescription($columnIndex); $dataColumnDescriptions[] = $columnDescription; } $uniqueColumnKeys = $this->columnKeyIndex->getKeys(); foreach ($uniqueColumnKeys as $hash => $key) { $idParts = array(); $labelParts = array(); $columnValues = $key->getColumnValues(); for ($i = 0; $i < $numColumnFields; $i++) { $columnDescription = $columnDescriptions[$i]; $columnValue = $columnValues[$i]; $idParts[] = $columnDescription->getId() . '=' . $columnValue; $labelParts[] = $columnValue; } for ($di = 0; $di < $numDataFields; $di++) { $dataFieldIndex = $dataFieldIndexes[$di]; $dataColumnDescription = $dataColumnDescriptions[$di]; $fieldId = $dataColumnDescription->getId(); $fieldLabel = $dataColumnDescription->getLabel(); $aggregationType = $this->pivotDescription->getAggregationType($fieldId); $id = implode("__", $idParts) . "__" . $fieldId; $label = ($aggregationType ? $aggregationType->getCode() . ' ' : '') . implode(" ", $labelParts) . " " . $fieldLabel; // For now copy the same type as the input column. // In the future we may need to set this explicitly based on the calculation. $type = $dataColumnDescription->getType(); $columnDescription = new ColumnDescription($id, $type, $label); $columnDescription->setCustomProperty('columnKeyId', $key->__toString()); $columnDescription->setCustomProperty('dataFieldIndex', $dataFieldIndex); $dataOut->addColumn($columnDescription); } } return $dataOut; }