Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questionnaire: metadata like open/close times and dates #378

Open
wants to merge 1 commit into
base: MOODLE_401_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lang/en/questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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
Expand All @@ -67,6 +68,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.';
Expand All @@ -88,8 +90,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';
Expand Down Expand Up @@ -315,6 +318,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)';
Expand Down Expand Up @@ -354,7 +358,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';
Expand All @@ -369,7 +373,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}';
Expand Down Expand Up @@ -652,6 +658,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';
Expand All @@ -672,6 +679,7 @@
$string['viewresponses'] = 'All responses ({$a})';
$string['viewyourresponses'] = 'View your response(s)';
$string['warning'] = 'Warning, error encountered.';
$string['weekly'] = '1 per week';
$string['where'] = 'where ';
$string['wronganswers'] = 'There is something wrong with your answers (see below)';
$string['wrongdateformat'] = 'The date entered: <strong>{$a}</strong> does not correspond to the format shown in the example.';
Expand Down
58 changes: 58 additions & 0 deletions questionnaire.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4180,4 +4180,62 @@ public static function get_user_identity_fields($context, $userid) {
$row = $DB->get_record_sql($sql, array_merge($params, [$userid]));
return $row;
}

/**
* 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 &lt;p>, &lt;/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;
}
}
2 changes: 2 additions & 0 deletions templates/viewpage.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -55,4 +56,5 @@
{{#yourresponse}}<div class="yourresponse">{{{yourresponse}}}</div>{{/yourresponse}}
{{#allresponses}}<div class="allresponses">{{{allresponses}}}</div>{{/allresponses}}
</div>
{{#info}}<div class="info">{{{info}}}</div>{{/info}}
</div>
6 changes: 6 additions & 0 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
get_string('addquestions', 'questionnaire') . '</a>');
}

// 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'));
Expand Down
Loading