Skip to content

Commit ca3ddee

Browse files
committed
feat: add linear scale answer type and associated settings
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent aea0490 commit ca3ddee

8 files changed

Lines changed: 439 additions & 7 deletions

File tree

lib/Constants.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Constants {
7575
public const ANSWER_TYPE_DATETIME = 'datetime';
7676
public const ANSWER_TYPE_TIME = 'time';
7777
public const ANSWER_TYPE_FILE = 'file';
78+
public const ANSWER_TYPE_LINEARSCALE = 'linearscale';
7879

7980
// All AnswerTypes
8081
public const ANSWER_TYPES = [
@@ -87,13 +88,15 @@ class Constants {
8788
self::ANSWER_TYPE_DATETIME,
8889
self::ANSWER_TYPE_TIME,
8990
self::ANSWER_TYPE_FILE,
91+
self::ANSWER_TYPE_LINEARSCALE,
9092
];
9193

9294
// AnswerTypes, that need/have predefined Options
9395
public const ANSWER_TYPES_PREDEFINED = [
9496
self::ANSWER_TYPE_MULTIPLE,
9597
self::ANSWER_TYPE_MULTIPLEUNIQUE,
96-
self::ANSWER_TYPE_DROPDOWN
98+
self::ANSWER_TYPE_DROPDOWN,
99+
self::ANSWER_TYPE_LINEARSCALE
97100
];
98101

99102
// AnswerTypes for date/time questions
@@ -155,6 +158,13 @@ class Constants {
155158
'x-office/spreadsheet',
156159
];
157160

161+
public const EXTRA_SETTINGS_LINEARSCALE = [
162+
'optionsLowest' => ['integer'],
163+
'optionsHighest' => ['integer'],
164+
'optionsLabelLowest' => ['string'],
165+
'optionsLabelHighest' => ['string'],
166+
];
167+
158168
public const FILENAME_INVALID_CHARS = [
159169
"\n",
160170
'/',

lib/ResponseDefinitions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
* allowedFileTypes?: list<string>,
2626
* maxAllowedFilesCount?: int,
2727
* maxFileSize?: int,
28+
* optionsHighest?: 2|3|4|5|6|7|8|9|10,
29+
* optionsLabelHighest?: string,
30+
* optionsLabelLowest?: string,
2831
* optionsLimitMax?: int,
2932
* optionsLimitMin?: int,
33+
* optionsLowest?: 0|1,
3034
* shuffleOptions?: bool,
3135
* validationRegex?: string,
3236
* validationType?: string

lib/Service/FormsService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType
629629
case Constants::ANSWER_TYPE_FILE:
630630
$allowed = Constants::EXTRA_SETTINGS_FILE;
631631
break;
632+
case Constants::ANSWER_TYPE_LINEARSCALE:
633+
$allowed = Constants::EXTRA_SETTINGS_LINEARSCALE;
634+
break;
632635
default:
633636
$allowed = [];
634637
}
@@ -698,6 +701,14 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType
698701
return false;
699702
}
700703
}
704+
705+
// Special handling of linear scale validation
706+
} elseif ($questionType === Constants::ANSWER_TYPE_LINEARSCALE) {
707+
// Ensure limits are sane
708+
if (isset($extraSettings['optionsLowest']) && ($extraSettings['optionsLowest'] < 0 || $extraSettings['optionsLowest'] > 1) ||
709+
isset($extraSettings['optionsHighest']) && ($extraSettings['optionsHighest'] < 2 || $extraSettings['optionsHighest'] > 10)) {
710+
return false;
711+
}
701712
}
702713
return true;
703714
}

openapi.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,27 @@
426426
"type": "integer",
427427
"format": "int64"
428428
},
429+
"optionsHighest": {
430+
"type": "integer",
431+
"format": "int64",
432+
"enum": [
433+
2,
434+
3,
435+
4,
436+
5,
437+
6,
438+
7,
439+
8,
440+
9,
441+
10
442+
]
443+
},
444+
"optionsLabelHighest": {
445+
"type": "string"
446+
},
447+
"optionsLabelLowest": {
448+
"type": "string"
449+
},
429450
"optionsLimitMax": {
430451
"type": "integer",
431452
"format": "int64"
@@ -434,6 +455,14 @@
434455
"type": "integer",
435456
"format": "int64"
436457
},
458+
"optionsLowest": {
459+
"type": "integer",
460+
"format": "int64",
461+
"enum": [
462+
0,
463+
1
464+
]
465+
},
437466
"shuffleOptions": {
438467
"type": "boolean"
439468
},
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2025 Christian Hartmann <chris-hartmann@gmx.de>
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<template>
7+
<span
8+
:aria-hidden="!title"
9+
:aria-label="title"
10+
class="material-design-icon drag-indicator-icon"
11+
role="img"
12+
v-bind="$attrs"
13+
@click="$emit('click', $event)">
14+
<svg
15+
:fill="fillColor"
16+
class="material-design-icon__svg"
17+
:height="size"
18+
:width="size"
19+
viewBox="0 -960 960 960">
20+
<path
21+
d="M672-288q-71 0-123.38-44.36Q496.24-376.73 482.9-444H281q-11 26-35 43t-54 17q-40.32 0-68.16-27.77Q96-439.55 96-479.77 96-520 123.84-548q27.84-28 68.16-28 30 0 54 17t35.46 43H484q13.21-67.28 65.1-111.64Q601-672 672-672q79.68 0 135.84 56.23 56.16 56.22 56.16 136Q864-400 807.84-344 751.68-288 672-288Zm0-72q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35Z" />
22+
<title v-if="title">{{ title }}</title>
23+
</svg>
24+
</span>
25+
</template>
26+
27+
<script>
28+
export default {
29+
name: 'IconLinearScale',
30+
props: {
31+
title: {
32+
type: String,
33+
default: '',
34+
},
35+
fillColor: {
36+
type: String,
37+
default: 'currentColor',
38+
},
39+
size: {
40+
type: Number,
41+
default: 20,
42+
},
43+
},
44+
}
45+
</script>

0 commit comments

Comments
 (0)