From f7e985a194ee3bf35929a22419f936c2bd5204fd Mon Sep 17 00:00:00 2001 From: will Date: Tue, 8 Aug 2017 14:49:29 -0400 Subject: [PATCH 1/4] Updating csv to show tag name, set name, form name, completed stage name --- .../Ushahidi/Repository/Post/Export.php | 64 ++++++++++++++++++- .../classes/Ushahidi/Repository/Tag.php | 1 - src/Core/Usecase/Post/Export.php | 2 +- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/application/classes/Ushahidi/Repository/Post/Export.php b/application/classes/Ushahidi/Repository/Post/Export.php index 44b57607fb..78385ce961 100644 --- a/application/classes/Ushahidi/Repository/Post/Export.php +++ b/application/classes/Ushahidi/Repository/Post/Export.php @@ -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; } } diff --git a/application/classes/Ushahidi/Repository/Tag.php b/application/classes/Ushahidi/Repository/Tag.php index 3c8a4593aa..fc32ec121c 100644 --- a/application/classes/Ushahidi/Repository/Tag.php +++ b/application/classes/Ushahidi/Repository/Tag.php @@ -123,7 +123,6 @@ public function update(Entity $entity) return $count; } - // UpdatePostTagRepository public function getByTag($tag) { diff --git a/src/Core/Usecase/Post/Export.php b/src/Core/Usecase/Post/Export.php index 629dd35111..e99ae0e0ef 100644 --- a/src/Core/Usecase/Post/Export.php +++ b/src/Core/Usecase/Post/Export.php @@ -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; } From 73dd6b089e7d49401d9d073ac55f1b7760cca77f Mon Sep 17 00:00:00 2001 From: will Date: Tue, 8 Aug 2017 14:53:16 -0400 Subject: [PATCH 2/4] Adding tag names too --- application/classes/Ushahidi/Repository/Post/Export.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/classes/Ushahidi/Repository/Post/Export.php b/application/classes/Ushahidi/Repository/Post/Export.php index 78385ce961..71bdff8b9a 100644 --- a/application/classes/Ushahidi/Repository/Post/Export.php +++ b/application/classes/Ushahidi/Repository/Post/Export.php @@ -46,8 +46,11 @@ public function transformData($data) { $form = $this->form_repo->get($data['form_id']); $data['form_name'] = $form->name; } - + if (!empty($data['tags'])) { + $data['tags'] = $this->retrieveTagNames($data['tags']); + } + return $data; } From 7187dd65c32b64264f4917f73b267bbff8cf4399 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 21 Aug 2017 17:11:27 -0400 Subject: [PATCH 3/4] Update Export.php --- application/classes/Ushahidi/Repository/Post/Export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/classes/Ushahidi/Repository/Post/Export.php b/application/classes/Ushahidi/Repository/Post/Export.php index 71bdff8b9a..5de77c8d42 100644 --- a/application/classes/Ushahidi/Repository/Post/Export.php +++ b/application/classes/Ushahidi/Repository/Post/Export.php @@ -14,7 +14,7 @@ class Ushahidi_Repository_Post_Export extends Ushahidi_Repository_Post { - public function transformData($data) { + public function retrieveColumnNameData($data) { // Set attribute keys $attributes = []; From e96ecef76c51bf476253c9e0cc501f58d6e2e4b5 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 21 Aug 2017 18:34:46 -0400 Subject: [PATCH 4/4] Change function name --- src/Core/Usecase/Post/Export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Usecase/Post/Export.php b/src/Core/Usecase/Post/Export.php index e99ae0e0ef..2632553a26 100644 --- a/src/Core/Usecase/Post/Export.php +++ b/src/Core/Usecase/Post/Export.php @@ -63,7 +63,7 @@ public function interact() // Retrieved Attribute Labels for Entity's values $data = $entity->asArray(); - $data = $this->repo->transformData($data); + $data = $this->repo->retrieveColumnNameData($data); $results[$idx] = $data; }