Skip to content

Commit 22e9b97

Browse files
toanlamttai.letan
andauthored
Questionnaire: metadata like open/close times and dates (#378)
Co-authored-by: tai.letan <tlt84@open.ac.uk>
1 parent 4d81469 commit 22e9b97

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

lang/en/questionnaire.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
$string['answers'] = 'Answers';
5151
$string['answerquestions'] = 'Answer the questions...';
5252
$string['attempted'] = 'This questionnaire has been submitted.';
53+
$string['attemptsallowed'] = 'Attempts allowed: {$a}';
5354
$string['attemptstillinprogress'] = 'In progress. Saved on:';
5455
$string['autonumbering'] = 'Auto numbering';
5556
$string['autonumbering_help'] = 'Automatic numbering of questions and pages. You might want to disable automatic numbering
@@ -68,6 +69,7 @@
6869
$string['boxesnbmin'] = 'a minimum of {$a} box(es).';
6970
$string['boxesnbreq'] = 'For this question you must tick ';
7071
$string['by'] = ' by ';
72+
$string['daily'] = '1 per day';
7173
$string['missingname'] = 'Question {$a} cannot be used in this feedback section because it does not have a name.';
7274
$string['missingrequired'] = 'Question {$a} cannot be used in this feedback section because it is not required.';
7375
$string['missingnameandrequired'] = 'Question {$a} cannot be used in this feedback section because it does not have a name and it is not required.';
@@ -89,8 +91,9 @@
8991
$string['checknotstarted'] = 'Select not started';
9092
$string['checkstarted'] = 'Select started';
9193
$string['clicktoswitch'] = '(click to switch)';
94+
$string['closesat'] = 'Closes at {$a}';
9295
$string['closebeforeopen'] = 'You have specified a close date before the open date.';
93-
$string['closed'] = 'The questionnaire was closed on {$a}. Thanks.';
96+
$string['closed'] = 'Closed on {$a}.';
9497
$string['closedate'] = 'Allow responses until';
9598
$string['closeson'] = 'Questionnaire closes on {$a}';
9699
$string['completionsubmit'] = 'Student must submit this questionnaire to complete it';
@@ -317,6 +320,7 @@
317320
$string['modulename_help'] = 'The questionnaire module allows you to construct surveys using a variety of question types, for the purpose of gathering data from users.';
318321
$string['modulename_link'] = 'mod/questionnaire/view';
319322
$string['modulenameplural'] = 'Questionnaires';
323+
$string['monthly'] = '1 per month';
320324
$string['movedisabled'] = 'This item cannot be moved';
321325
$string['myresponses'] = 'All your responses';
322326
$string['myresponsetitle'] = 'Your {$a} response(s)';
@@ -356,7 +360,7 @@
356360
$string['notificationsimple'] = 'Notification only';
357361
$string['notifications_help'] = 'Notify roles with the "mod/questionnaire:submissionnotification" capability when a submission is made.';
358362
$string['notifications_link'] = 'mod/questionnaire/mod#Submission_Notifications';
359-
$string['notopen'] = 'This questionnaire will not open until {$a}.';
363+
$string['notopen'] = 'This questionnaire will not be available until {$a}.';
360364
$string['notrequired'] = 'Response is not required';
361365
$string['notset'] = 'not set';
362366
$string['not_started'] = 'not started';
@@ -371,7 +375,9 @@
371375
$string['numberscaleitems_help'] = 'Nb of scale items is the *number of items* to be used in your rate scale. You would normally use a value of 3 to 5. Default value: **5**.';
372376
$string['numeric'] = 'Numeric';
373377
$string['numeric_help'] = 'Use this question type if you expect the response to be a correctly formatted number.';
378+
$string['openedat'] = 'Opened at {$a}';
374379
$string['of'] = 'of';
380+
$string['once'] = '1';
375381
$string['openafterclose'] = 'You have specified an open date after the close date';
376382
$string['opendate'] = 'Allow responses from';
377383
$string['option'] = 'option {$a}';
@@ -658,6 +664,7 @@
658664
$string['undefinedquestiontype'] = 'Undefined question type!';
659665
$string['unknown'] = 'Unknown';
660666
$string['unknownaction'] = 'Unknown questionnaire action specified...';
667+
$string['unlimited'] = 'Unlimited';
661668
$string['url'] = 'Confirmation URL';
662669
$string['url_help'] = 'The URL to which a user is redirected after completing this questionnaire.';
663670
$string['useprivate'] = 'Copy existing';
@@ -678,6 +685,7 @@
678685
$string['viewresponses'] = 'All responses ({$a})';
679686
$string['viewyourresponses'] = 'View your response(s)';
680687
$string['warning'] = 'Warning, error encountered.';
688+
$string['weekly'] = '1 per week';
681689
$string['where'] = 'where ';
682690
$string['wronganswers'] = 'There is something wrong with your answers (see below)';
683691
$string['wrongdateformat'] = 'The date entered: <strong>{$a}</strong> does not correspond to the format shown in the example.';

questionnaire.class.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,4 +4189,62 @@ public static function get_user_identity_fields($context, $userid) {
41894189
$row = $DB->get_record_sql($sql, array_merge($params, [$userid]));
41904190
return $row;
41914191
}
4192+
4193+
/**
4194+
* Output the questionnair information.
4195+
*
4196+
* @param array $messages any access messages that should be described.
4197+
*/
4198+
public function view_information() {
4199+
$messages = [];
4200+
4201+
if (isset($this->qtype)) {
4202+
switch ($this->qtype) {
4203+
case QUESTIONNAIREUNLIMITED:
4204+
$typestring = get_string('unlimited', 'questionnaire');
4205+
break;
4206+
case QUESTIONNAIREONCE:
4207+
$typestring = get_string('once', 'questionnaire');
4208+
break;
4209+
case QUESTIONNAIREDAILY:
4210+
$typestring = get_string('daily', 'questionnaire');
4211+
break;
4212+
case QUESTIONNAIREWEEKLY:
4213+
$typestring = get_string('weekly', 'questionnaire');
4214+
break;
4215+
case QUESTIONNAIREMONTHLY:
4216+
$typestring = get_string('monthly', 'questionnaire');
4217+
break;
4218+
default:
4219+
$typestring = '';
4220+
break;
4221+
}
4222+
array_push($messages, get_string('attemptsallowed', 'questionnaire', $typestring));
4223+
}
4224+
4225+
if ($this->is_open() && !$this->is_closed()) {
4226+
if ($this->opendate > 0) {
4227+
array_push($messages, get_string('openedat', 'questionnaire', userdate($this->opendate)));
4228+
}
4229+
if ($this->closedate > 0) {
4230+
array_push($messages, get_string('closesat', 'questionnaire', userdate($this->closedate)));
4231+
}
4232+
}
4233+
4234+
return $messages;
4235+
}
4236+
4237+
/**
4238+
* Print each message in an array, surrounded by &lt;p>, &lt;/p> tags.
4239+
*
4240+
* @param array $messages the array of message strings.
4241+
* @return string HTML to output.
4242+
*/
4243+
public function access_messages($messages) {
4244+
$output = '';
4245+
foreach ($messages as $message) {
4246+
$output .= html_writer::tag('p', $message) . "\n";
4247+
}
4248+
return $output;
4249+
}
41924250
}

templates/viewpage.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"intro": "HTML of the intro text.",
4141
"message": "HTML of the message text.",
4242
"complete": "HTML of the completion notice and link.",
43+
"info": "HTML of the info text.",
4344
"guestuser": "HTML of guest user content.",
4445
"yourresponse": "HTML for your responses link.",
4546
"allresponses": "HTML for all responses link."
@@ -55,4 +56,5 @@
5556
{{#yourresponse}}<div class="yourresponse">{{{yourresponse}}}</div>{{/yourresponse}}
5657
{{#allresponses}}<div class="allresponses">{{{allresponses}}}</div>{{/allresponses}}
5758
</div>
59+
{{#info}}<div class="info">{{{info}}}</div>{{/info}}
5860
</div>

view.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
get_string('addquestions', 'questionnaire') . '</a>');
103103
}
104104

105+
// Time zone message (if required).
106+
if (!$message && $questionnaire->is_open() && !$questionnaire->is_closed()) {
107+
$info = $questionnaire->view_information();
108+
$questionnaire->page->add_to_page('info', $questionnaire->access_messages($info));
109+
}
110+
105111
if (isguestuser()) {
106112
$guestno = html_writer::tag('p', get_string('noteligible', 'questionnaire'));
107113
$liketologin = html_writer::tag('p', get_string('liketologin'));

0 commit comments

Comments
 (0)