File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
app/Models/Foundation/Main/ExtraQuestions Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,28 @@ public function setValue($value): void
108
108
throw new ValidationException ("Question is not set. " );
109
109
}
110
110
111
+ if ($ this ->question ->isMandatory () && empty ($ value )){
112
+ throw new ValidationException
113
+ (
114
+ sprintf
115
+ (
116
+ "Question %s is mandatory. " ,
117
+ $ this ->question ->getId ()
118
+ )
119
+ );
120
+ }
121
+
122
+ if (!$ this ->question ->isValidValue ($ value )){
123
+ throw new ValidationException
124
+ (
125
+ sprintf
126
+ (
127
+ "Invalid value (%s) for question %s " ,
128
+ json_encode ($ value ),
129
+ $ this ->question ->getId ()
130
+ )
131
+ );
132
+ }
111
133
$ res = $ value ;
112
134
if (is_array ($ res ))
113
135
{
Original file line number Diff line number Diff line change @@ -262,6 +262,21 @@ private function getValueMaxOrder():int{
262
262
public function allowsValues ():bool {
263
263
return in_array ($ this ->type , ExtraQuestionTypeConstants::AllowedMultiValueQuestionType);
264
264
}
265
+
266
+ public function isValidValue ($ value ):bool {
267
+ if (empty ($ value ) && !$ this ->mandatory ) return true ;
268
+ if ($ this ->allowsValues ()) {
269
+ if (!is_array ($ value ))
270
+ $ value = explode (self ::QuestionChoicesCharSeparator, $ value );
271
+ foreach ($ value as $ v ) {
272
+ if (!$ this ->getValueById (intval ($ v )))
273
+ return false ;
274
+ }
275
+ }
276
+ if ($ this ->type === ExtraQuestionTypeConstants::RadioButtonQuestionType)
277
+ return empty ($ value ) || $ value === 'true ' ;
278
+ return true ;
279
+ }
265
280
/**
266
281
* @param ExtraQuestionTypeValue $value
267
282
* @throws ValidationException
You can’t perform that action at this time.
0 commit comments