Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions packages/core/classes/setting/Setting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ public static function getColumns() {
'boolean',
'integer',
'float',
'string'
'string',
'many2one'
],
'description' => 'The format of data stored by the param.',
'default' => 'string',
'visible' => ['is_sequence', '=', false]
],

'object_class' => [
'type' => 'string',
'description' => "Full name of the entity the Setting refers to.",
'visible' => ['type', '=', 'many2one']
],

'is_multilang' => [
'type' => 'boolean',
'description' => "Marks the setting as translatable.",
Expand Down Expand Up @@ -230,7 +237,7 @@ public static function get_value(string $package, string $section, string $code,
}

$setting_values = $om->read(SettingValue::getType(), $setting['setting_values_ids'], ['user_id', 'value'], $values_lang);
if($setting_values > 0) {
if($setting_values > 0 && count($setting_values)) {
$value = null;
// #memo - by default settings values are sorted on user_id (which can be null), so first value is the default one
foreach($setting_values as $setting_value) {
Expand All @@ -241,7 +248,17 @@ public static function get_value(string $package, string $section, string $code,
}
if(!is_null($value)) {
$result = $value;
settype($result, $setting['type']);

$map_extra_types = [
'many2one' => 'integer'
];

$type = $map_extra_types[$setting['type']] ?? $setting['type'];

settype($result, $type);
}
elseif($setting['type'] == 'many2one') {
$result = null;
}
}
}
Expand Down Expand Up @@ -324,7 +341,7 @@ public static function fetch_and_add(string $package, string $section, string $c
$result = null;

$providers = \eQual::inject(['orm']);
/** @var \equal\orm\ObjectManager */
/** @var \equal\orm\ObjectManager $orm */
$orm = $providers['orm'];

$settings_ids = $orm->search(self::getType(), [
Expand Down
3 changes: 2 additions & 1 deletion packages/core/i18n/en/setting/Setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"boolean": "booléen",
"integer": "entier",
"float": "nombre flottant",
"string": "chaîne de caractères"
"string": "chaîne de caractères",
"many2one": "many2one relationship"
},
"description": "Setting type.",
"help": ""
Expand Down
3 changes: 2 additions & 1 deletion packages/core/i18n/fr/setting/Setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"boolean": "booléen",
"integer": "entier",
"float": "nombre flottant",
"string": "chaîne de caractère"
"string": "chaîne de caractère",
"many2one": "relation many2one"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions packages/core/views/setting/Setting.form.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
"value": "form_control",
"width": "50%"
},
{
"type": "field",
"value": "object_class",
"width": "100%"
},
{
"type": "field",
"value": "is_multilang",
Expand Down