Skip to content

Commit

Permalink
2028 working with lat/lon.
Browse files Browse the repository at this point in the history
  • Loading branch information
rowasc committed Sep 11, 2017
1 parent 933e06f commit 302e0f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions application/classes/Ushahidi/Formatter/Post/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function generateCSVRecords($records)
if ($record['post_date'] instanceof \DateTimeInterface) {
$record['post_date'] = $record['post_date']->format("Y-m-d H:i:s");
}

$values = [];
foreach ($heading as $key => $value) {
$setValue = '';
Expand All @@ -69,12 +70,19 @@ protected function generateCSVRecords($records)
$setValue = $record[$headingKey];
} else if (isset($record['values'][$headingKey])) {
if (count($keySet) > 1){
/**
* we work with multiple posts which means our actual count($record[$key])
* value might not exist in all of the posts we are posting in the CSV
*/
$setValue = isset($record['values'][$headingKey][$keySet[1]])? ($record['values'][$headingKey][$keySet[1]]): '';
}else{
if($keySet[1] === 'lat' || $keySet[1] === 'lon'){
/*
* Lat/Lon are never multivalue fields so we can get the first index only
*/
$setValue = isset($record['values'][$headingKey][0][$keySet[1]])? ($record['values'][$headingKey][0][$keySet[1]]): '';
} else {
/**
* we work with multiple posts which means our actual count($record[$key])
* value might not exist in all of the posts we are posting in the CSV
*/
$setValue = isset($record['values'][$headingKey][0][$keySet[1]])? ($record['values'][$headingKey][$keySet[1]]): '';
}
} else{
$setValue = $record['values'][$headingKey];
}
} else {
Expand Down Expand Up @@ -151,14 +159,17 @@ private function sortGroupedFieldsByPriority($groupedFields){
* Finally, we can flatten the array, and set the fields (key->labels) with the user-selected order.
*/
foreach ($attributeKeys as $attributeKey => $attribute){
if (is_array($attribute) && isset($attribute['count'])){
if (is_array($attribute) && isset($attribute['count']) && $attribute['type'] !== 'point'){
/**
* If the attribute has a count key, it means we want to show that as key.index in the header.
* This is to make sure we don't miss values in multi-value fields
*/
for ($i = 0 ; $i<$attribute['count']; $i++){
$attributeKeysWithStageFlat[$attributeKey.'.'.$i] = $attribute['label'].'.'.$i;
}
} else if ($attribute['type'] === 'point'){
$attributeKeysWithStageFlat[$attributeKey.'.lat'] = $attribute['label'].'.lat';
$attributeKeysWithStageFlat[$attributeKey.'.lon'] = $attribute['label'].'.lon';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/classes/Ushahidi/Repository/Post/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function retrieveColumnNameData($data) {
/**
* @DEVNOTE form_stage_id can be NULL. Why is that? solve that scenario and get back here.
*/
$attributes[$key] = ['label' => $attribute->label, 'priority'=> $attribute->priority, 'stage' => $attribute->form_stage_id];
$attributes[$key] = ['label' => $attribute->label, 'priority'=> $attribute->priority, 'stage' => $attribute->form_stage_id, 'type'=> $attribute->type];
/**
* @DEVNOTE what happens when we export tags ? check/debug that scenario a bit more
*/
Expand Down

0 comments on commit 302e0f6

Please sign in to comment.