From a7c3cf669aac6e937acf1d8772531b9a651dbe84 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 11 Sep 2019 09:31:36 +0100
Subject: [PATCH] FEAT #11270 TIME 0:20 customFields default_values + order by
 label

---
 .../controllers/CustomFieldController.php            | 12 +++++++-----
 src/app/customField/models/CustomFieldModel.php      |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/app/customField/controllers/CustomFieldController.php b/src/app/customField/controllers/CustomFieldController.php
index 508cf32ed27..46c5f380fdd 100644
--- a/src/app/customField/controllers/CustomFieldController.php
+++ b/src/app/customField/controllers/CustomFieldController.php
@@ -63,9 +63,10 @@ class CustomFieldController
         }
 
         $id = CustomFieldModel::create([
-            'label'     => $body['label'],
-            'type'      => $body['type'],
-            'values'    => empty($body['values']) ? null : json_encode($body['values'])
+            'label'         => $body['label'],
+            'type'          => $body['type'],
+            'values'        => empty($body['values']) ? null : json_encode($body['values']),
+            'default_value' => $body['default_value']
         ]);
 
         return $response->withStatus(204)->withJson(['customFieldId' => $id]);
@@ -97,8 +98,9 @@ class CustomFieldController
 
         CustomFieldModel::update([
             'set'   => [
-                'label'     => $body['label'],
-                'values'    => empty($body['values']) ? null : json_encode($body['values'])
+                'label'         => $body['label'],
+                'values'        => empty($body['values']) ? null : json_encode($body['values']),
+                'default_value' => $body['default_value']
             ],
             'where' => ['id = ?'],
             'data'  => [$args['id']]
diff --git a/src/app/customField/models/CustomFieldModel.php b/src/app/customField/models/CustomFieldModel.php
index 81d7e6d8b4c..236c723d7cd 100644
--- a/src/app/customField/models/CustomFieldModel.php
+++ b/src/app/customField/models/CustomFieldModel.php
@@ -29,7 +29,7 @@ class CustomFieldModel
             'table'     => ['custom_fields'],
             'where'     => empty($args['where']) ? [] : $args['where'],
             'data'      => empty($args['data']) ? [] : $args['data'],
-            'order_by'  => empty($args['orderBy']) ? [] : $args['orderBy'],
+            'order_by'  => empty($args['orderBy']) ? ['label'] : $args['orderBy'],
             'limit'     => empty($args['limit']) ? 0 : $args['limit']
         ]);
 
-- 
GitLab