diff --git a/mod/choice/db/install.xml b/mod/choice/db/install.xml
index 424d58e6757..8291b8e483a 100644
--- a/mod/choice/db/install.xml
+++ b/mod/choice/db/install.xml
@@ -21,6 +21,7 @@
+
diff --git a/mod/choice/db/upgrade.php b/mod/choice/db/upgrade.php
index 1a74ff41039..d745ff3414a 100644
--- a/mod/choice/db/upgrade.php
+++ b/mod/choice/db/upgrade.php
@@ -65,6 +65,21 @@ function xmldb_choice_upgrade($oldversion) {
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
+ if ($oldversion < 2014111001) {
+
+ // Define field showpreview to be added to choice.
+ $table = new xmldb_table('choice');
+ $field = new xmldb_field('showpreview', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timeclose');
+
+ // Conditionally launch add field showpreview.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Choice savepoint reached.
+ upgrade_mod_savepoint(true, 2014111001, 'choice');
+ }
+
return true;
}
diff --git a/mod/choice/lang/en/choice.php b/mod/choice/lang/en/choice.php
index e241893933e..c9245c9526e 100644
--- a/mod/choice/lang/en/choice.php
+++ b/mod/choice/lang/en/choice.php
@@ -90,6 +90,7 @@ $string['options'] = 'Options';
$string['page-mod-choice-x'] = 'Any choice module page';
$string['pluginadministration'] = 'Choice administration';
$string['pluginname'] = 'Choice';
+$string['previewonly'] = 'This is just a preview of the available options for this activity. You will not be able to submit your choice until {$a}.';
$string['privacy'] = 'Privacy of results';
$string['publish'] = 'Publish results';
$string['publishafteranswer'] = 'Show results to students after they answer';
@@ -105,6 +106,8 @@ $string['responsesresultgraphheader'] = 'Graph display';
$string['responsesto'] = 'Responses to {$a}';
$string['results'] = 'Results';
$string['savemychoice'] = 'Save my choice';
+$string['showpreview'] = 'Show preview';
+$string['showpreview_help'] = 'Allow students to preview the available options before the choice is opened for submission.';
$string['showunanswered'] = 'Show column for unanswered';
$string['spaceleft'] = 'space available';
$string['spacesleft'] = 'spaces available';
diff --git a/mod/choice/lib.php b/mod/choice/lib.php
index a2d3a35b243..280c4322bf7 100644
--- a/mod/choice/lib.php
+++ b/mod/choice/lib.php
@@ -232,6 +232,10 @@ function choice_prepare_options($choice, $user, $coursemodule, $allresponses) {
$cdisplay['allowupdate'] = true;
}
+ if ($choice->showpreview && $choice->timeopen > time()) {
+ $cdisplay['previewonly'] = true;
+ }
+
return $cdisplay;
}
diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php
index 480daa59114..9b9e4955435 100644
--- a/mod/choice/mod_form.php
+++ b/mod/choice/mod_form.php
@@ -79,6 +79,10 @@ class mod_choice_mod_form extends moodleform_mod {
$mform->addElement('date_time_selector', 'timeclose', get_string("choiceclose", "choice"));
$mform->disabledIf('timeclose', 'timerestrict');
+ $mform->addElement('advcheckbox', 'showpreview', get_string('showpreview', 'choice'));
+ $mform->addHelpButton('showpreview', 'showpreview', 'choice');
+ $mform->disabledIf('showpreview', 'timerestrict');
+
//-------------------------------------------------------------------------------
$mform->addElement('header', 'resultshdr', get_string('results', 'choice'));
diff --git a/mod/choice/renderer.php b/mod/choice/renderer.php
index 5e2c3cd312a..c46b87c3de2 100644
--- a/mod/choice/renderer.php
+++ b/mod/choice/renderer.php
@@ -41,6 +41,7 @@ class mod_choice_renderer extends plugin_renderer_base {
}
$target = new moodle_url('/mod/choice/view.php');
$attributes = array('method'=>'POST', 'action'=>$target, 'class'=> $layoutclass);
+ $disabled = empty($options['previewonly']) ? array() : array('disabled' => 'disabled');
$html = html_writer::start_tag('form', $attributes);
$html .= html_writer::start_tag('ul', array('class'=>'choices' ));
@@ -65,7 +66,7 @@ class mod_choice_renderer extends plugin_renderer_base {
$availableoption--;
}
- $html .= html_writer::empty_tag('input', (array)$option->attributes);
+ $html .= html_writer::empty_tag('input', (array)$option->attributes + $disabled);
$html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->id));
$html .= html_writer::end_tag('li');
}
@@ -75,19 +76,23 @@ class mod_choice_renderer extends plugin_renderer_base {
$html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
$html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid));
- if (!empty($options['hascapability']) && ($options['hascapability'])) {
- if ($availableoption < 1) {
- $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
- } else {
- $html .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('savemychoice','choice'), 'class'=>'button'));
- }
+ if (empty($options['previewonly'])) {
+ if (!empty($options['hascapability']) && ($options['hascapability'])) {
+ if ($availableoption < 1) {
+ $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
+ } else {
+ $html .= html_writer::empty_tag('input',
+ array('type' => 'submit', 'value' => get_string('savemychoice', 'choice'), 'class' => 'button'));
+ }
- if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
- $url = new moodle_url('view.php', array('id'=>$coursemoduleid, 'action'=>'delchoice', 'sesskey'=>sesskey()));
- $html .= html_writer::link($url, get_string('removemychoice','choice'));
+ if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
+ $url = new moodle_url('view.php',
+ array('id' => $coursemoduleid, 'action' => 'delchoice', 'sesskey' => sesskey()));
+ $html .= html_writer::link($url, get_string('removemychoice', 'choice'));
+ }
+ } else {
+ $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
}
- } else {
- $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
}
$html .= html_writer::end_tag('ul');
diff --git a/mod/choice/version.php b/mod/choice/version.php
index 180cf9cf539..0de84a5ea35 100644
--- a/mod/choice/version.php
+++ b/mod/choice/version.php
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2014111000; // The current module version (Date: YYYYMMDDXX)
+$plugin->version = 2014111001; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014110400; // Requires this Moodle version
$plugin->component = 'mod_choice'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
diff --git a/mod/choice/view.php b/mod/choice/view.php
index 176872d8cad..00a4e3c8f3f 100644
--- a/mod/choice/view.php
+++ b/mod/choice/view.php
@@ -128,9 +128,13 @@ if (isloggedin() && (!empty($current)) &&
$choiceopen = true;
if ($choice->timeclose !=0) {
if ($choice->timeopen > $timenow ) {
- echo $OUTPUT->box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "generalbox notopenyet");
- echo $OUTPUT->footer();
- exit;
+ if ($choice->showpreview) {
+ echo $OUTPUT->box(get_string('previewonly', 'choice', userdate($choice->timeopen)), 'generalbox alert');
+ } else {
+ echo $OUTPUT->box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "generalbox notopenyet");
+ echo $OUTPUT->footer();
+ exit;
+ }
} else if ($timenow > $choice->timeclose) {
echo $OUTPUT->box(get_string("expired", "choice", userdate($choice->timeclose)), "generalbox expired");
$choiceopen = false;