Skip to content

Commit dd66418

Browse files
tailetantai.letan
andauthored
Improve question print display for interactive types (#618)
Co-authored-by: tai.letan <[email protected]>
1 parent f2ffa46 commit dd66418

14 files changed

+216
-14
lines changed

classes/question/date.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
8585
$choice->value = (isset($response->answers[$this->id][0]->value) ? $response->answers[$this->id][0]->value : '');
8686
$questiontags->qelements = new \stdClass();
8787
$questiontags->qelements->choice = $choice;
88+
$questiontags->isprint = $this->get_isprint();
8889
return $questiontags;
8990
}
9091

classes/question/drop.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ protected function question_survey_display($response, $dependants, $blankquestio
117117
$chobj->class = 'select custom-select menu q'.$this->id;
118118
$chobj->options = $options;
119119
$choicetags->qelements->choice = $chobj;
120+
$choicetags->isprint = $this->get_isprint();
120121

121122
return $choicetags;
122123
}

classes/question/essay.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
8989
} else {
9090
$value = '';
9191
}
92-
if ($canusehtmleditor) {
92+
if ($canusehtmleditor && !$this->get_isprint()) {
9393
$editor = editors_get_preferred_editor();
9494
$editor->use_editor($name, questionnaire_get_editor_options($this->context));
9595
$texteditor = html_writer::tag('textarea', $value,
9696
['id' => $name, 'name' => $name, 'rows' => $rows, 'cols' => $cols, 'class' => 'form-control']);
9797
} else {
98-
$editor = FORMAT_PLAIN;
9998
$texteditor = html_writer::tag('textarea', $value,
10099
['id' => $name, 'name' => $name, 'rows' => $rows, 'cols' => $cols]);
101100
}

classes/question/question.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ abstract class question {
109109
/** @var mixed $extradata Any custom data for the question type. */
110110
public $extradata = '';
111111

112+
/** @var boolean $isprint The isprint flag. */
113+
public $isprint = false;
114+
112115
/** @var array $qtypenames List of all question names. */
113116
private static $qtypenames = [
114117
QUESYESNO => 'yesno',
@@ -467,6 +470,24 @@ public function get_notifications() {
467470
}
468471
}
469472

473+
/**
474+
* Sets the print status of the page.
475+
*
476+
* @param bool $isprint Optional. Defaults to false. If true, sets the page as a print page.
477+
*/
478+
public function set_isprint(bool $isprint = false) {
479+
$this->isprint = $isprint;
480+
}
481+
482+
/**
483+
* Retrieves the print status of the page.
484+
*
485+
* @return bool True if the page is a print page, otherwise false.
486+
*/
487+
public function get_isprint(): bool {
488+
return (bool) $this->isprint;
489+
}
490+
470491
/**
471492
* Each question type must define its response class.
472493
* @return object The response object based off of questionnaire_response_base.

classes/question/slider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ protected function question_survey_display($response, $dependants = [], $blankqu
121121
$extradata->id = self::qtypename($this->type_id) . $this->id;
122122
$questiontags->qelements = new \stdClass();
123123
$questiontags->qelements->extradata = $extradata;
124+
$questiontags->isprint = $this->get_isprint();
124125
return $questiontags;
125126
}
126127

classes/question/text.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
9393
format_string(stripslashes($response->answers[$this->id][0]->value)) : '');
9494
$choice->id = self::qtypename($this->type_id) . $this->id;
9595
$questiontags->qelements->choice = $choice;
96+
$questiontags->isprint = $this->get_isprint();
9697
return $questiontags;
9798
}
9899

lang/en/questionnaire.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@
421421
$string['print'] = 'Print this Response';
422422
$string['printblank'] = 'Print Blank';
423423
$string['printblanktooltip'] = 'Opens printer-friendly window with blank Questionnaire';
424+
$string['printstrictdateformatting'] = 'Enter the date';
424425
$string['printtooltip'] = 'Opens printer-friendly window with current Response';
425426

426427
$string['privacy:metadata:questionnaire_response'] = 'A response in progress or submitted';

questionnaire.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ public function survey_print_render($courseid, $message = '', $referer='', $rid=
16201620
} else {
16211621
$dependants = [];
16221622
}
1623+
$this->questions[$questionid]->set_isprint($referer === 'print');
16231624
$output .= $this->renderer->question_output($this->questions[$questionid], $this->responses[0] ?? [],
16241625
$i++, null, $dependants);
16251626
$this->page->add_to_page('questions', $output);

styles.css

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ td.selected {
170170
margin-top: 10px;
171171
}
172172

173+
#page-mod-questionnaire-print .printdropdown input:first-child,
174+
#page-mod-questionnaire-print .printdropdown label:first-of-type,
175+
#page-mod-questionnaire-print .printdropdown br:first-of-type {
176+
display: none;
177+
}
178+
179+
#page-mod-questionnaire-print .print-text {
180+
min-width: 100%;
181+
box-sizing: border-box;
182+
height: 30px;
183+
}
184+
173185
#page-mod-questionnaire-complete .notice .buttons div,
174186
#page-mod-questionnaire-complete .notice .buttons form {
175187
display: inline;
@@ -543,3 +555,71 @@ td.selected {
543555
height: 2px;
544556
left: 50%;
545557
}
558+
559+
/* Styles for the print blank page. */
560+
#page-mod-questionnaire-print .slider {
561+
position: relative;
562+
width: 100%;
563+
}
564+
565+
#page-mod-questionnaire-print.path-mod-questionnaire .question-slider.print-slider {
566+
margin-top: 20px;
567+
margin-bottom: 20px;
568+
}
569+
570+
#page-mod-questionnaire-print.path-mod-questionnaire .print-slider .left-side-label,
571+
#page-mod-questionnaire-print.path-mod-questionnaire .print-slider .right-side-label,
572+
#page-mod-questionnaire-print.path-mod-questionnaire .print-slider .slider {
573+
margin: 0;
574+
}
575+
576+
#page-mod-questionnaire-print input[type="range"] {
577+
appearance: none;
578+
height: 10px;
579+
border-radius: 5px;
580+
background-color: #ddd;
581+
}
582+
583+
#page-mod-questionnaire-print input[type="range"]::-webkit-slider-thumb {
584+
-webkit-appearance: none;
585+
appearance: none;
586+
width: 0;
587+
height: 0;
588+
}
589+
590+
#page-mod-questionnaire-print input[type="range"]::-moz-range-thumb {
591+
-webkit-appearance: none;
592+
appearance: none;
593+
width: 0;
594+
height: 0;
595+
}
596+
597+
#page-mod-questionnaire-print input[type="range"]::-ms-thumb {
598+
-webkit-appearance: none;
599+
appearance: none;
600+
width: 0;
601+
height: 0;
602+
}
603+
604+
#page-mod-questionnaire-print .path-mod-questionnaire .right-side-label,
605+
#page-mod-questionnaire-print .path-mod-questionnaire .left-side-label {
606+
margin: 0;
607+
}
608+
609+
#page-mod-questionnaire-print .bubble {
610+
display: none;
611+
}
612+
613+
@media print {
614+
#page-mod-questionnaire-print .slider {
615+
position: relative;
616+
width: 100%;
617+
}
618+
619+
#page-mod-questionnaire-print input[type="range"] {
620+
appearance: none;
621+
width: 100%;
622+
border: 1px solid #000000;
623+
border-radius: 5px;
624+
}
625+
}

templates/question_date.mustache

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
3030
Example context (json):
3131
{
32+
"isprint": false,
3233
"qelements": {
3334
"choice": {
3435
"type": "text",
@@ -42,11 +43,17 @@
4243
<!-- Begin HTML generated from question_date template. -->
4344
{{#qelements}}
4445
{{#choice}}
45-
<div class="qn-datemsg">{{# str }}strictdateformatting, mod_questionnaire{{/ str}}</div>
46-
<div class="qn-date">
47-
<input type="{{type}}" name="{{choice.name}}" value="{{choice.value}}" />
48-
<!-- <input {{#choice.onkeypress}}onkeypress="{{.}}"{{/choice.onkeypress}} type="text" size="12" name="{{choice.name}}" maxlength="10" value="{{choice.value}}" /> -->
49-
</div>
46+
{{#isprint}}
47+
<div class="qn-datemsg">{{# str }}printstrictdateformatting, mod_questionnaire{{/ str}}</div>
48+
<input type="text" size="{{choice.size}}" name="{{choice.name}}" />
49+
{{/isprint}}
50+
{{^isprint}}
51+
<div class="qn-datemsg">{{# str }}strictdateformatting, mod_questionnaire{{/ str}}</div>
52+
<div class="qn-date">
53+
<input type="{{type}}" name="{{choice.name}}" value="{{choice.value}}" />
54+
<!-- <input {{#choice.onkeypress}}onkeypress="{{.}}"{{/choice.onkeypress}} type="text" size="12" name="{{choice.name}}" maxlength="10" value="{{choice.value}}" /> -->
55+
</div>
56+
{{/isprint}}
5057
{{/choice}}
5158
{{/qelements}}
5259
<!-- End HTML generated from question_date template. -->

0 commit comments

Comments
 (0)