From 68803d4a9b32b64f4f7c2287a5096e55bbffe5fa Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Wed, 15 Jul 2020 22:20:00 +0200 Subject: [PATCH] FIX #13195 TIME 0:15 search with sql custom fields --- .../indexing_searching/search_adv.php | 11 +++++++++-- .../controllers/CustomFieldController.php | 6 +++++- src/app/resource/controllers/StoreController.php | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/maarch_entreprise/indexing_searching/search_adv.php b/apps/maarch_entreprise/indexing_searching/search_adv.php index df05534df13..4e4a21d6261 100755 --- a/apps/maarch_entreprise/indexing_searching/search_adv.php +++ b/apps/maarch_entreprise/indexing_searching/search_adv.php @@ -137,8 +137,15 @@ foreach ($customFields as $customField) { $arr_tmp = array(); array_push($arr_tmp, array('VALUE' => '', 'LABEL' => _CHOOSE.'...')); $customValues = json_decode($customField['values'], true); - foreach ($customValues as $customValue) { - array_push($arr_tmp, array('VALUE' => $customValue, 'LABEL' => $customValue)); + if (!empty($customValues['table'])) { + $customValues = \CustomField\models\CustomFieldModel::getValuesSQL($customValues); + foreach ($customValues as $customInfo) { + array_push($arr_tmp, array('VALUE' => $customInfo['key'], 'LABEL' => $customInfo['label'])); + } + } else { + foreach ($customValues as $customValue) { + array_push($arr_tmp, array('VALUE' => $customValue, 'LABEL' => $customValue)); + } } $arr_tmp2 = array('label' => $customField['label'], 'type' => 'select_simple', 'param' => array('field_label' => $customField['label'], 'default_label' => '', 'options' => $arr_tmp)); } elseif ($customField['type'] == 'date') { diff --git a/src/app/customField/controllers/CustomFieldController.php b/src/app/customField/controllers/CustomFieldController.php index d514e70d3cf..20e2b95038e 100644 --- a/src/app/customField/controllers/CustomFieldController.php +++ b/src/app/customField/controllers/CustomFieldController.php @@ -44,7 +44,11 @@ class CustomFieldController if (empty($queryParams['admin']) || !PrivilegeController::hasPrivilege(['privilegeId' => 'admin_custom_fields', 'userId' => $GLOBALS['id']])) { if (!empty($customFields[$key]['values']['table'])) { $customFields[$key]['values'] = CustomFieldModel::getValuesSQL($customFields[$key]['values']); - if ($customField['type'] == 'string') { + if (in_array($customField['type'], ['select', 'radio', 'checkbox'])) { + foreach ($customFields[$key]['values'] as $iKey => $sValue) { + $customFields[$key]['values'][$iKey]['key'] = (string)$sValue['key']; + } + } elseif ($customField['type'] == 'string') { $customFields[$key]['values'][0]['key'] = (string)$customFields[$key]['values'][0]['key']; } elseif ($customField['type'] == 'integer') { $customFields[$key]['values'][0]['key'] = (int)$customFields[$key]['values'][0]['key']; diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php index a2fb30ed081..38b2aca41c1 100755 --- a/src/app/resource/controllers/StoreController.php +++ b/src/app/resource/controllers/StoreController.php @@ -185,6 +185,13 @@ class StoreController $date = new \DateTime($value); $value = $date->format('Y-m-d'); $args['customFields'][$key] = $value; + } elseif ($customField['type'] != 'integer' && !is_array($value)) { + $args['customFields'][$key] = (string)$value; + } elseif ($customField['type'] != 'integer' && is_array($value)) { + foreach ($value as $iKey => $sValue) { + $value[$iKey] = (string)$sValue; + } + $args['customFields'][$key] = $value; } } } @@ -298,6 +305,13 @@ class StoreController $date = new \DateTime($value); $value = $date->format('Y-m-d'); $args['customFields'][$key] = $value; + } elseif ($customField['type'] != 'integer' && !is_array($value)) { + $args['customFields'][$key] = (string)$value; + } elseif ($customField['type'] != 'integer' && is_array($value)) { + foreach ($value as $iKey => $sValue) { + $value[$iKey] = (string)$sValue; + } + $args['customFields'][$key] = $value; } } $preparedData['custom_fields'] = json_encode($args['customFields']); -- GitLab