From d6d2e8546fcbbe14e78558ed58cb9c59367ab9a5 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Wed, 10 Jun 2020 15:17:34 +0200
Subject: [PATCH] FEAT #11720 TIME 0:30 contact export change route + fix
 boolean values + fix custom array

---
 rest/index.php                                               | 2 +-
 src/app/contact/controllers/ContactController.php            | 5 ++++-
 .../contact/list/export/contact-export.component.ts          | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/rest/index.php b/rest/index.php
index dd266712c36..1766b097b24 100755
--- a/rest/index.php
+++ b/rest/index.php
@@ -131,6 +131,7 @@ $app->put('/configurations/{service}', \Configuration\controllers\ConfigurationC
 $app->get('/contacts', \Contact\controllers\ContactController::class . ':get');
 $app->post('/contacts', \Contact\controllers\ContactController::class . ':create');
 $app->get('/contacts/{id}', \Contact\controllers\ContactController::class . ':getById');
+$app->put('/contacts/export', \Contact\controllers\ContactController::class . ':exportContacts');
 $app->put('/contacts/{id}', \Contact\controllers\ContactController::class . ':update');
 $app->delete('/contacts/{id}', \Contact\controllers\ContactController::class . ':delete');
 $app->put('/contacts/{id}/activation', \Contact\controllers\ContactController::class . ':updateActivation');
@@ -138,7 +139,6 @@ $app->get('/formattedContacts/{id}/types/{type}', \Contact\controllers\ContactCo
 $app->get('/ban/availableDepartments', \Contact\controllers\ContactController::class . ':getAvailableDepartments');
 $app->get('/duplicatedContacts', \Contact\controllers\ContactController::class . ':getDuplicatedContacts');
 $app->put('/contacts/{id}/merge', \Contact\controllers\ContactController::class . ':mergeContacts');
-$app->post('/contacts/export', \Contact\controllers\ContactController::class . ':exportContacts');
 
 //ContactsCustomFields
 $app->get('/contactsCustomFields', \Contact\controllers\ContactCustomFieldController::class . ':get');
diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php
index da0d909dbd2..c16f6af15eb 100755
--- a/src/app/contact/controllers/ContactController.php
+++ b/src/app/contact/controllers/ContactController.php
@@ -1174,12 +1174,15 @@ class ContactController
 
         foreach ($contacts as $contact) {
             foreach ($contact as $field => $value) {
-                if (strpos($field, 'contactCustomField_') !== false) {
+                if (strpos($field, 'contact_custom_field_') !== false) {
                     $decoded = json_decode($value, true);
                     if (is_array($decoded)) {
                         $contact[$field] = implode("\n", $decoded);
                     }
                 }
+                if (Validator::boolType()->validate($value)) {
+                    $contact[$field] = $value ? 'TRUE' : 'FALSE';
+                }
             }
             if (!empty($contact['creator_label'])) {
                 $contact['creator_label'] = UserModel::getLabelledUserById(['id' => $contact['creator_label']]);
diff --git a/src/frontend/app/administration/contact/list/export/contact-export.component.ts b/src/frontend/app/administration/contact/list/export/contact-export.component.ts
index b977ec8dfb5..2ee3db11d3f 100644
--- a/src/frontend/app/administration/contact/list/export/contact-export.component.ts
+++ b/src/frontend/app/administration/contact/list/export/contact-export.component.ts
@@ -138,7 +138,7 @@ export class ContactExportComponent implements OnInit {
     exportData() {
         this.localStorage.save(`exportContactFields_${this.headerService.user.id}`, JSON.stringify(this.exportModel));
         this.loadingExport = true;
-        this.http.post('../rest/contacts/export', this.exportModel, { responseType: 'blob' }).pipe(
+        this.http.put('../rest/contacts/export', this.exportModel, { responseType: 'blob' }).pipe(
             tap((data: any) => {
                 if (data.type !== 'text/html') {
                     const downloadLink = document.createElement('a');
-- 
GitLab