@@ -29,6 +29,12 @@ class rate extends question {
29
29
/** @var array $nameddegrees */
30
30
public $ nameddegrees = [];
31
31
32
+ /** @var int Row start position of the rate table. */
33
+ public const ROW_START = 2 ;
34
+
35
+ /** @var int Column start position of the rate table. */
36
+ public const COL_START = 2 ;
37
+
32
38
/**
33
39
* The class constructor
34
40
* @param int $id
@@ -319,22 +325,24 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
319
325
$ notcomplete = true ;
320
326
}
321
327
322
- $ row = 0 ;
328
+ $ rowstart = self :: ROW_START ;
323
329
$ choicetags ->qelements ['rows ' ] = [];
324
330
foreach ($ this ->choices as $ cid => $ choice ) {
325
331
$ cols = [];
326
332
if (isset ($ choice ->content )) {
327
- $ row ++;
328
333
$ str = 'q ' ."{$ this ->id }_ $ cid " ;
329
334
$ content = $ choice ->content ;
335
+ $ rendercontent = format_text ($ choice ->content , FORMAT_PLAIN );
330
336
if ($ this ->osgood_rate_scale ()) {
331
337
list ($ content , $ contentright ) = array_merge (preg_split ('/[|]/ ' , $ content ), array (' ' ));
332
338
}
333
339
$ cols [] = ['colstyle ' => 'text-align: ' .$ textalign .'; ' ,
334
340
'coltext ' => format_text ($ content , FORMAT_HTML , ['noclean ' => true ]).' ' ];
335
341
336
342
$ bg = 'c0 raterow ' ;
343
+ $ hasnotansweredchoice = false ;
337
344
if (($ nbchoices > 1 ) && !$ this ->no_duplicate_choices () && !$ blankquestionnaire ) {
345
+ $ hasnotansweredchoice = true ;
338
346
$ checked = ' checked="checked" ' ;
339
347
$ completeclass = 'notanswered ' ;
340
348
$ title = '' ;
@@ -351,12 +359,15 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
351
359
if (!empty ($ order )) {
352
360
$ colinput ['onclick ' ] = $ order ;
353
361
}
362
+ $ colinput ['label ' ] = $ this ->set_label ($ rowstart , $ rendercontent , self ::COL_START ,
363
+ get_string ('unanswered ' , 'questionnaire ' ));
354
364
$ cols [] = ['colstyle ' => 'width:1%; ' , 'colclass ' => $ completeclass , 'coltitle ' => $ title ,
355
365
'colinput ' => $ colinput ];
356
366
}
357
367
if ($ nameddegrees > 0 ) {
358
368
reset ($ this ->nameddegrees );
359
369
}
370
+ $ colstart = $ hasnotansweredchoice ? self ::COL_START + 1 : self ::COL_START ;
360
371
for ($ j = 1 ; $ j <= $ this ->length + $ this ->has_na_column (); $ j ++) {
361
372
if (!isset ($ collabel [$ j ])) {
362
373
// If not using this value, continue.
@@ -389,18 +400,20 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
389
400
if (!empty ($ order )) {
390
401
$ col ['colinput ' ]['onclick ' ] = $ order ;
391
402
}
392
- $ col ['colinput ' ]['label ' ] = ' Choice ' . $ collabel [ $ j ]. ' for row ' . format_text ( $ content , FORMAT_PLAIN );
403
+ $ col ['colinput ' ]['label ' ] = $ this -> set_label ( $ rowstart , $ rendercontent , $ colstart , $ collabel [ $ j ] );
393
404
if ($ bg == 'c0 raterow ' ) {
394
405
$ bg = 'c1 raterow ' ;
395
406
} else {
396
407
$ bg = 'c0 raterow ' ;
397
408
}
409
+ $ colstart ++;
398
410
$ cols [] = $ col ;
399
411
}
400
412
if ($ this ->osgood_rate_scale ()) {
401
413
$ cols [] = ['coltext ' => ' ' .format_text ($ contentright , FORMAT_HTML , ['noclean ' => true ])];
402
414
}
403
415
$ choicetags ->qelements ['rows ' ][] = ['cols ' => $ cols ];
416
+ $ rowstart ++;
404
417
}
405
418
}
406
419
@@ -1089,4 +1102,23 @@ public static function move_all_nameddegree_choices(int $surveyid = null) {
1089
1102
}
1090
1103
$ ratequests ->close ();
1091
1104
}
1105
+
1106
+ /**
1107
+ * Set label for per column inside rate table.
1108
+ *
1109
+ * @param int $rowposition
1110
+ * @param string $choicetitle
1111
+ * @param int $colposition
1112
+ * @param string $choiceanswer
1113
+ * @return string
1114
+ */
1115
+ private function set_label (int $ rowposition , string $ choicetitle , int $ colposition , string $ choiceanswer ): string {
1116
+ $ a = (object ) [
1117
+ 'rowposition ' => $ rowposition ,
1118
+ 'choicetitle ' => $ choicetitle ,
1119
+ 'colposition ' => $ colposition ,
1120
+ 'choiceanswer ' => $ choiceanswer ,
1121
+ ];
1122
+ return get_string ('accessibility:rate:choice ' , 'questionnaire ' , $ a );
1123
+ }
1092
1124
}
0 commit comments