public function formatRecord(array &$records = NULL, $record) { $result = parent::formatRecord($records, $record); if ($result) { $this->errorUnsupportedChainOfResultFormatters(); } $recordKey = NULL; foreach ($this->keyColumnNames as $columnName) { $recordKey[] = isset($record[$columnName]) ? $record[$columnName] : NULL; } $key = ArrayHelper::prepareCompositeKey($recordKey); if (isset($records[$key])) { if ($this->isColumnValueUnique) { throw new IllegalArgumentException(t('Found several records for the key: @key', array('@key' => ArrayHelper::printArray($recordKey, ', ', TRUE, TRUE)))); } $records[$key][] = $record; } else { if ($this->isColumnValueUnique) { $records[$key] = $record; } else { $records[$key][] = $record; } } return TRUE; }
public function formatRecord(array &$records = NULL, $record) { $result = parent::formatRecord($records, $record); if ($result) { $this->errorUnsupportedChainOfResultFormatters(); } $formattedRecord = NULL; if (isset($this->propertyNames)) { // using predefined column name foreach ($this->propertyNames as $index => $propertyName) { $formattedRecord[$index] = isset($record[$propertyName]) ? $record[$propertyName] : NULL; } } else { // checking if we need to add additional columns foreach ($record as $propertyName => $propertyValue) { if (!isset($this->assembledColumnNames[$propertyName])) { $index = count($this->assembledColumnNames); // registering new column $this->assembledColumnNames[$propertyName] = $index; // adding NULL values for the column for previous records if (isset($records)) { foreach ($records as &$record) { $record[$index] = NULL; } } } } foreach ($this->assembledColumnNames as $propertyName => $index) { $formattedRecord[$index] = isset($record[$propertyName]) ? $record[$propertyName] : NULL; } } $records[] = $formattedRecord; return TRUE; }
public function formatRecord(array &$records = NULL, $record) { $result = parent::formatRecord($records, $record); if ($result) { $this->errorUnsupportedChainOfResultFormatters(); } $columnValue = NULL; if (isset($this->propertyName)) { $columnValue = isset($record[$this->propertyName]) ? $record[$this->propertyName] : NULL; } else { $count = count($record); switch ($count) { case 0: // it is the same as NULL break; case 1: $columnValue = reset($record); break; default: throw new IllegalArgumentException(t('Only one property is supported by this result formatter')); } } if (isset($columnValue)) { $records[] = $columnValue; } return TRUE; }
public function formatRecord(array &$records = NULL, $record) { $result = parent::formatRecord($records, $record); if ($result) { $this->errorUnsupportedChainOfResultFormatters(); } if (isset($records)) { // trying to find a record which could be reused foreach ($records as &$existingRecord) { $isRecordMatched = TRUE; foreach ($this->adjustedGroupByPropertyNames as $groupByPropertyName) { if (isset($existingRecord[$groupByPropertyName])) { if (isset($record[$groupByPropertyName])) { if ($existingRecord[$groupByPropertyName] !== $record[$groupByPropertyName]) { $isRecordMatched = FALSE; } } else { $isRecordMatched = FALSE; } } elseif (isset($record[$groupByPropertyName])) { $isRecordMatched = FALSE; } if (!$isRecordMatched) { break; } } if ($isRecordMatched) { $this->formatSubjectProperties($existingRecord, $record); return TRUE; } } unset($existingRecord); } // preparing new record $newRecord = NULL; foreach ($record as $name => $value) { if ($name === $this->adjustedEnumerationPropertyName) { continue; } if (isset($this->adjustedSubjectPropertyNames)) { if (array_search($name, $this->adjustedSubjectPropertyNames) !== FALSE) { continue; } } elseif (array_search($name, $this->adjustedGroupByPropertyNames) === FALSE) { continue; } // We still add some columns which are not really useful. // Example: // * data is prepared by cube. Returned properties: 'agency', 'agency.name', ... // * 'agency.name' is subject property // * new record will contain 'agency' property. There is no good generic logic to eliminate such property $newRecord[$name] = $value; } $this->formatSubjectProperties($newRecord, $record); $records[] = $newRecord; return TRUE; }