/** * @param int $dataColumnIndex Index of the data column whose container to construct * @return iDataContainer * @throws NotImplementedException for aggregation types not yet implemented */ public function constructDataContainer($dataColumnIndex) { $data =& $this->pivotDescription->getDataTable(); $column = $data->getColumnDescription($dataColumnIndex); $dataFieldId = $column->getId(); $aggregationType = $this->pivotDescription->getAggregationType($dataFieldId); $aggregationTypeCode = $aggregationType ? $aggregationType->getCode() : null; switch ($aggregationTypeCode) { case AggregationType::AVG: return new AverageDataContainer(); case AggregationType::MIN: return new MinDataContainer(); case AggregationType::MAX: return new MaxDataContainer(); case AggregationType::COUNT: return new CountDataContainer(); case AggregationType::SUM: default: // e.g. null (no specified aggregation type) return new SumDataContainer(); } }
public function testAddDataFieldWithAggregationType() { $type = AggregationType::MAX; $pivot = new PivotDescription($this->dataTable); $pivot->addDataField('expense', $type); $expected = array('expense'); $actual = $pivot->getDataFields(); $this->assertEquals($expected, $actual); $expected = $type; $actual = $pivot->getAggregationType('expense'); $this->assertNotNull($actual); $this->assertEquals($expected, $actual->getCode()); }