MDL-49220 mod_choice: Add option to allow students to preview choices
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<FIELD NAME="limitanswers" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="showpreview" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
|
||||
<FIELD NAME="completionsubmit" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, then the activity will be automatically marked as 'complete' once the user submits their choice."/>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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'));
|
||||
|
||||
|
||||
+17
-12
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
|
||||
+7
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user