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();
     }
     $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;
 }
示例#4
0
 public function postFormatRecords(array &$records = NULL)
 {
     parent::postFormatRecords($records);
     if (isset($records)) {
         $propertyNames = $this->propertyNames;
         if (!isset($propertyNames)) {
             foreach ($this->assembledColumnNames as $propertyName => $index) {
                 $propertyNames[$index] = $propertyName;
             }
         }
         array_unshift($records, $propertyNames);
     }
 }