Skip to content

Commit

Permalink
MDL-49220 mod_choice: Add option to allow students to preview choices
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjbutler committed Feb 20, 2015
1 parent 95751e8 commit c30dbd6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions mod/choice/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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."/>
Expand Down
15 changes: 15 additions & 0 deletions mod/choice/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions mod/choice/lang/en/choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
$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';
Expand All @@ -105,6 +106,8 @@
$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';
Expand Down
4 changes: 4 additions & 0 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions mod/choice/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ function definition() {
$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'));

Expand Down
29 changes: 17 additions & 12 deletions mod/choice/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function display_options($options, $coursemoduleid, $vertical = false, $m
}
$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' ));
Expand All @@ -65,7 +66,7 @@ public function display_options($options, $coursemoduleid, $vertical = false, $m
$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');
}
Expand All @@ -75,19 +76,23 @@ public function display_options($options, $coursemoduleid, $vertical = false, $m
$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');
Expand Down
2 changes: 1 addition & 1 deletion mod/choice/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 7 additions & 3 deletions mod/choice/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@
$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;
Expand Down

0 comments on commit c30dbd6

Please sign in to comment.