Skip to content
Snippets Groups Projects
Verified Commit 80d57d86 authored by Damien's avatar Damien
Browse files

FEAT #12636 TIME 2:00 Update custom values

parent b9eabcd9
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ class ContactCustomFieldController ...@@ -98,7 +98,7 @@ class ContactCustomFieldController
return $response->withStatus(400)->withJson(['errors' => 'Some values have the same name']); return $response->withStatus(400)->withJson(['errors' => 'Some values have the same name']);
} }
$field = ContactCustomFieldListModel::getById(['select' => [1], 'id' => $args['id']]); $field = ContactCustomFieldListModel::getById(['select' => ['type', 'values'], 'id' => $args['id']]);
if (empty($field)) { if (empty($field)) {
return $response->withStatus(400)->withJson(['errors' => 'Custom field not found']); return $response->withStatus(400)->withJson(['errors' => 'Custom field not found']);
} }
...@@ -108,6 +108,24 @@ class ContactCustomFieldController ...@@ -108,6 +108,24 @@ class ContactCustomFieldController
return $response->withStatus(400)->withJson(['errors' => 'Custom field with this label already exists']); return $response->withStatus(400)->withJson(['errors' => 'Custom field with this label already exists']);
} }
if (in_array($field['type'], ['select', 'checkbox', 'radio'])) {
$values = json_decode($field['values'], true);
foreach ($values as $key => $value) {
if (!empty($body['values'][$key]) && $body['values'][$key] != $value) {
ContactModel::update([
'postSet' => ['custom_fields' => "jsonb_insert(custom_fields, '{{$args['id']}, 0}', '\"{$body['values'][$key]}\"')"],
'where' => ["custom_fields->'{$args['id']}' @> ?"],
'data' => ["\"{$value}\""]
]);
ContactModel::update([
'postSet' => ['custom_fields' => "jsonb_set(custom_fields, '{{$args['id']}}', (custom_fields->'{$args['id']}') - '{$value}')"],
'where' => ['1 = ?'],
'data' => [1]
]);
}
}
}
ContactCustomFieldListModel::update([ ContactCustomFieldListModel::update([
'set' => [ 'set' => [
'label' => $body['label'], 'label' => $body['label'],
......
...@@ -100,7 +100,7 @@ class CustomFieldController ...@@ -100,7 +100,7 @@ class CustomFieldController
return $response->withStatus(400)->withJson(['errors' => 'Some values have the same name']); return $response->withStatus(400)->withJson(['errors' => 'Some values have the same name']);
} }
$field = CustomFieldModel::getById(['select' => [1], 'id' => $args['id']]); $field = CustomFieldModel::getById(['select' => ['type', 'values'], 'id' => $args['id']]);
if (empty($field)) { if (empty($field)) {
return $response->withStatus(400)->withJson(['errors' => 'Custom field not found']); return $response->withStatus(400)->withJson(['errors' => 'Custom field not found']);
} }
...@@ -110,6 +110,24 @@ class CustomFieldController ...@@ -110,6 +110,24 @@ class CustomFieldController
return $response->withStatus(400)->withJson(['errors' => 'Custom field with this label already exists']); return $response->withStatus(400)->withJson(['errors' => 'Custom field with this label already exists']);
} }
if (in_array($field['type'], ['select', 'checkbox', 'radio'])) {
$values = json_decode($field['values'], true);
foreach ($values as $key => $value) {
if (!empty($body['values'][$key]) && $body['values'][$key] != $value) {
ResModel::update([
'postSet' => ['custom_fields' => "jsonb_insert(custom_fields, '{{$args['id']}, 0}', '\"{$body['values'][$key]}\"')"],
'where' => ["custom_fields->'{$args['id']}' @> ?"],
'data' => ["\"{$value}\""]
]);
ResModel::update([
'postSet' => ['custom_fields' => "jsonb_set(custom_fields, '{{$args['id']}}', (custom_fields->'{$args['id']}') - '{$value}')"],
'where' => ['1 = ?'],
'data' => [1]
]);
}
}
}
CustomFieldModel::update([ CustomFieldModel::update([
'set' => [ 'set' => [
'label' => $body['label'], 'label' => $body['label'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment