Skip to content

Commit

Permalink
Updating csv to show tag name, set name, form name, completed stage name
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed Aug 15, 2017
1 parent 3551b76 commit f7e985a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
64 changes: 61 additions & 3 deletions application/classes/Ushahidi/Repository/Post/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,71 @@

class Ushahidi_Repository_Post_Export extends Ushahidi_Repository_Post
{
public function getFormAttributes($values) {

public function transformData($data) {

// Set attribute keys
$attributes = [];
foreach ($values as $key => $val)
foreach ($data['values'] as $key => $val)
{
$attribute = $this->form_attribute_repo->getByKey($key);
$attributes[$key] = $attribute->label;

// Set attribute names
if ($attribute->type === 'tags') {
$data['values'][$key] = $this->retrieveTagNames($val);
}
}

$data += ['attributes' => $attributes];

// Set Set names
if (!empty($data['sets'])) {
$data['sets'] = $this->retrieveSetNames($data['sets']);
}

// Set Completed Stage names
if(!empty($data['completed_stages'])) {
$data['completed_stages'] = $this->retrieveCompletedStageNames($data['completed_stages']);
}

// Set Form name
if (!empty($data['form_id'])) {
$form = $this->form_repo->get($data['form_id']);
$data['form_name'] = $form->name;
}


return $data;

}

public function retrieveTagNames($tag_ids) {
$tag_repo = service('repository.tag');
$names = [];
foreach($tag_ids as $tag_id) {
$tag = $tag_repo->get($tag_id);
array_push($names, $tag->tag);
}
return $names;
}

public function retrieveSetNames($set_ids) {
$set_repo = service('repository.set');
$names = [];
foreach($set_ids as $set_id) {
$set = $set_repo->get($set_id);
array_push($names, $set->name);
}
return $names;
}

public function retrieveCompletedStageNames($stage_ids) {
$names = [];
foreach($stage_ids as $stage_id) {
$stage = $this->form_stage_repo->get($stage_id);
array_push($names, $stage->label);
}
return $attributes;
return $names;
}
}
1 change: 0 additions & 1 deletion application/classes/Ushahidi/Repository/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function update(Entity $entity)
return $count;
}


// UpdatePostTagRepository
public function getByTag($tag)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Usecase/Post/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function interact()

// Retrieved Attribute Labels for Entity's values
$data = $entity->asArray();
$data += ['attributes' => $this->repo->getFormAttributes($data['values'])];
$data = $this->repo->transformData($data);

$results[$idx] = $data;
}
Expand Down

0 comments on commit f7e985a

Please sign in to comment.