From dc20f06511331896c5efcbd4883273eed4408c08 Mon Sep 17 00:00:00 2001 From: toanlam Date: Mon, 13 Dec 2021 17:02:17 +0700 Subject: [PATCH] Questionnaire: metadata like open/close times and dates --- lang/en/questionnaire.php | 12 ++++++-- questionnaire.class.php | 58 +++++++++++++++++++++++++++++++++++++ templates/viewpage.mustache | 2 ++ view.php | 6 ++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/lang/en/questionnaire.php b/lang/en/questionnaire.php index e4e86c17..4a4b6c57 100644 --- a/lang/en/questionnaire.php +++ b/lang/en/questionnaire.php @@ -48,6 +48,7 @@ $string['answers'] = 'Answers'; $string['answerquestions'] = 'Answer the questions...'; $string['attempted'] = 'This questionnaire has been submitted.'; +$string['attemptsallowed'] = 'Attempts allowed: {$a}'; $string['attemptstillinprogress'] = 'In progress. Saved on:'; $string['autonumbering'] = 'Auto numbering'; $string['autonumbering_help'] = 'Automatic numbering of questions and pages. You might want to disable automatic numbering @@ -66,6 +67,7 @@ $string['boxesnbmin'] = 'a minimum of {$a} box(es).'; $string['boxesnbreq'] = 'For this question you must tick '; $string['by'] = ' by '; +$string['daily'] = '1 per day'; $string['missingname'] = 'Question {$a} cannot be used in this feedback section because it does not have a name.'; $string['missingrequired'] = 'Question {$a} cannot be used in this feedback section because it is not required.'; $string['missingnameandrequired'] = 'Question {$a} cannot be used in this feedback section because it does not have a name and it is not required.'; @@ -87,8 +89,9 @@ $string['checknotstarted'] = 'Select not started'; $string['checkstarted'] = 'Select started'; $string['clicktoswitch'] = '(click to switch)'; +$string['closesat'] = 'Closes at {$a}'; $string['closebeforeopen'] = 'You have specified a close date before the open date.'; -$string['closed'] = 'The questionnaire was closed on {$a}. Thanks.'; +$string['closed'] = 'Closed on {$a}.'; $string['closedate'] = 'Allow responses until'; $string['closeson'] = 'Questionnaire closes on {$a}'; $string['completionsubmit'] = 'Student must submit this questionnaire to complete it'; @@ -301,6 +304,7 @@ $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.'; $string['modulename_link'] = 'mod/questionnaire/view'; $string['modulenameplural'] = 'Questionnaires'; +$string['monthly'] = '1 per month'; $string['movedisabled'] = 'This item cannot be moved'; $string['myresponses'] = 'All your responses'; $string['myresponsetitle'] = 'Your {$a} response(s)'; @@ -336,7 +340,7 @@ $string['notificationsimple'] = 'Notification only'; $string['notifications_help'] = 'Notify roles with the "mod/questionnaire:submissionnotification" capability when a submission is made.'; $string['notifications_link'] = 'mod/questionnaire/mod#Submission_Notifications'; -$string['notopen'] = 'This questionnaire will not open until {$a}.'; +$string['notopen'] = 'This questionnaire will not be available until {$a}.'; $string['notrequired'] = 'Response is not required'; $string['notset'] = 'not set'; $string['not_started'] = 'not started'; @@ -351,7 +355,9 @@ $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**.'; $string['numeric'] = 'Numeric'; $string['numeric_help'] = 'Use this question type if you expect the response to be a correctly formatted number.'; +$string['openedat'] = 'Opened at {$a}'; $string['of'] = 'of'; +$string['once'] = '1'; $string['openafterclose'] = 'You have specified an open date after the close date'; $string['opendate'] = 'Allow responses from'; $string['option'] = 'option {$a}'; @@ -624,6 +630,7 @@ $string['undefinedquestiontype'] = 'Undefined question type!'; $string['unknown'] = 'Unknown'; $string['unknownaction'] = 'Unknown questionnaire action specified...'; +$string['unlimited'] = 'Unlimited'; $string['url'] = 'Confirmation URL'; $string['url_help'] = 'The URL to which a user is redirected after completing this questionnaire.'; $string['useprivate'] = 'Copy existing'; @@ -644,6 +651,7 @@ $string['viewresponses'] = 'All responses ({$a})'; $string['viewyourresponses'] = 'Your responses- view {$a}'; $string['warning'] = 'Warning, error encountered.'; +$string['weekly'] = '1 per week'; $string['wronganswers'] = 'There is something wrong with your answers (see below)'; $string['wrongdateformat'] = 'The date entered: {$a} does not correspond to the format shown in the example.'; $string['wrongdaterange'] = 'ERROR! The year must be set in the 1902 to 2037 range.'; diff --git a/questionnaire.class.php b/questionnaire.class.php index 90e67c49..74fdd5e5 100644 --- a/questionnaire.class.php +++ b/questionnaire.class.php @@ -3903,4 +3903,62 @@ public function get_all_file_areas() { return $areas; } + + /** + * Output the questionnair information + * + * @param array $messages any access messages that should be described. + */ + public function view_information() { + $messages = []; + + if (isset($this->qtype)) { + switch ($this->qtype) { + case QUESTIONNAIREUNLIMITED: + $typestring = get_string('unlimited', 'questionnaire'); + break; + case QUESTIONNAIREONCE: + $typestring = get_string('once', 'questionnaire'); + break; + case QUESTIONNAIREDAILY: + $typestring = get_string('daily', 'questionnaire'); + break; + case QUESTIONNAIREWEEKLY: + $typestring = get_string('weekly', 'questionnaire'); + break; + case QUESTIONNAIREMONTHLY: + $typestring = get_string('monthly', 'questionnaire'); + break; + default: + $typestring = ''; + break; + } + array_push($messages, get_string('attemptsallowed', 'questionnaire', $typestring)); + } + + if ($this->is_open() && !$this->is_closed()) { + if ($this->opendate > 0) { + array_push($messages, get_string('openedat', 'questionnaire', userdate($this->opendate))); + } + if ($this->closedate > 0) { + array_push($messages, get_string('closesat', 'questionnaire', userdate($this->closedate))); + } + } + + return $messages; + } + + /** + * Print each message in an array, surrounded by <p>, </p> tags. + * + * @param array $messages the array of message strings. + * @return string HTML to output. + */ + public function access_messages($messages) { + $output = ''; + foreach ($messages as $message) { + $output .= html_writer::tag('p', $message) . "\n"; + } + return $output; + } } diff --git a/templates/viewpage.mustache b/templates/viewpage.mustache index 0cbede3c..b84b21c8 100644 --- a/templates/viewpage.mustache +++ b/templates/viewpage.mustache @@ -40,6 +40,7 @@ "intro": "HTML of the intro text.", "message": "HTML of the message text.", "complete": "HTML of the completion notice and link.", + "info": "HTML of the info text.", "guestuser": "HTML of guest user content.", "yourresponse": "HTML for your responses link.", "allresponses": "HTML for all responses link." @@ -50,6 +51,7 @@ {{#intro}}
{{{intro}}}
{{/intro}} {{#message}}
{{{message}}}
{{/message}} {{#complete}}
{{{complete}}}
{{/complete}} + {{#info}}
{{{info}}}
{{/info}} {{#guestuser}}
{{{guestuser}}}
{{/guestuser}} {{#yourresponse}}
{{{yourresponse}}}
{{/yourresponse}} {{#allresponses}}
{{{allresponses}}}
{{/allresponses}} diff --git a/view.php b/view.php index 20781b0f..629ad2e3 100644 --- a/view.php +++ b/view.php @@ -98,6 +98,12 @@ get_string('addquestions', 'questionnaire') . ''); } +// Time zone message (if required). +if (!$message && $questionnaire->is_open() && !$questionnaire->is_closed()) { + $info = $questionnaire->view_information(); + $questionnaire->page->add_to_page('info', $questionnaire->access_messages($info)); +} + if (isguestuser()) { $guestno = html_writer::tag('p', get_string('noteligible', 'questionnaire')); $liketologin = html_writer::tag('p', get_string('liketologin'));