File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
app/Models/Foundation/Main/ExtraQuestions Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,17 @@ public function setValue($value): void
108108 throw new ValidationException ("Question is not set. " );
109109 }
110110
111+ if (!$ this ->question ->isValidValue ($ value )){
112+ throw new ValidationException
113+ (
114+ sprintf
115+ (
116+ "Invalid value (%s) for question %s " ,
117+ json_encode ($ value ),
118+ $ this ->question ->getId ()
119+ )
120+ );
121+ }
111122 $ res = $ value ;
112123 if (is_array ($ res ))
113124 {
Original file line number Diff line number Diff line change @@ -262,6 +262,20 @@ private function getValueMaxOrder():int{
262262 public function allowsValues ():bool {
263263 return in_array ($ this ->type , ExtraQuestionTypeConstants::AllowedMultiValueQuestionType);
264264 }
265+
266+ public function isValidValue ($ value ):bool {
267+ if (is_array ($ value )) {
268+ if (!$ this ->allowsValues ())
269+ return false ;
270+ foreach ($ value as $ v ) {
271+ if (!$ this ->getValueById (intval ($ v )))
272+ return false ;
273+ }
274+ }
275+ if ($ this ->type === ExtraQuestionTypeConstants::RadioButtonQuestionType)
276+ return empty ($ value ) || $ value === 'true ' ;
277+ return true ;
278+ }
265279 /**
266280 * @param ExtraQuestionTypeValue $value
267281 * @throws ValidationException
You can’t perform that action at this time.
0 commit comments