Skip to content

Commit

Permalink
MDL-37745 mod_choice: Show taken and limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Jul 25, 2020
1 parent 94fdac9 commit 8419764
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mod/choice/backup/moodle2/backup_choice_stepslib.php
Expand Up @@ -41,7 +41,7 @@ protected function define_structure() {
'name', 'intro', 'introformat', 'publish',
'showresults', 'display', 'allowupdate', 'allowmultiple', 'showunanswered',
'limitanswers', 'timeopen', 'timeclose', 'timemodified',
'completionsubmit', 'showpreview', 'includeinactive'));
'completionsubmit', 'showpreview', 'includeinactive', 'showavailable'));

$options = new backup_nested_element('options');

Expand Down
2 changes: 2 additions & 0 deletions mod/choice/classes/external.php
Expand Up @@ -519,6 +519,7 @@ public static function get_choices_by_courses($courseids = array()) {
$choicedetails['limitanswers'] = $choice->limitanswers;
$choicedetails['showunanswered'] = $choice->showunanswered;
$choicedetails['includeinactive'] = $choice->includeinactive;
$choicedetails['showavailable'] = $choice->showavailable;
}

if (has_capability('moodle/course:manageactivities', $context)) {
Expand Down Expand Up @@ -571,6 +572,7 @@ public static function get_choices_by_courses_returns() {
'showpreview' => new external_value(PARAM_BOOL, 'Show preview before timeopen', VALUE_OPTIONAL),
'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL),
'completionsubmit' => new external_value(PARAM_BOOL, 'Completion on user submission', VALUE_OPTIONAL),
'showavailable' => new external_value(PARAM_BOOL, 'Show available spaces', VALUE_OPTIONAL),
'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL),
'visible' => new external_value(PARAM_BOOL, 'Visible', VALUE_OPTIONAL),
'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL),
Expand Down
9 changes: 2 additions & 7 deletions mod/choice/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/choice/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/choice"
<XMLDB PATH="mod/choice/db" VERSION="20200616" COMMENT="XMLDB file for Moodle mod/choice"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -11,7 +11,6 @@
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

<FIELD NAME="publish" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="showresults" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand All @@ -24,8 +23,8 @@
<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."/>
<FIELD NAME="showavailable" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, then the the number of available space on choice options will be shown, given limitanswers is set to 1."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand All @@ -34,7 +33,6 @@
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>

<TABLE NAME="choice_options" COMMENT="available options to choice">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
Expand All @@ -44,7 +42,6 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>

<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="choiceid" TYPE="foreign" FIELDS="choiceid" REFTABLE="choice" REFFIELDS="id"/>
</KEYS>
Expand All @@ -54,7 +51,6 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="choiceid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

<FIELD NAME="optionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
Expand All @@ -64,7 +60,6 @@
<KEY NAME="optionid" TYPE="foreign" FIELDS="optionid" REFTABLE="choice_options" REFFIELDS="id"/>
</KEYS>
<INDEXES>

<INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
</INDEXES>
</TABLE>
Expand Down
16 changes: 15 additions & 1 deletion mod/choice/db/upgrade.php
Expand Up @@ -22,7 +22,9 @@
defined('MOODLE_INTERNAL') || die();

function xmldb_choice_upgrade($oldversion) {
global $CFG;
global $CFG, $DB;

$dbman = $DB->get_manager();

// Automatically generated Moodle v3.5.0 release upgrade line.
// Put any upgrade step following this.
Expand All @@ -39,5 +41,17 @@ function xmldb_choice_upgrade($oldversion) {
// Automatically generated Moodle v3.9.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2020061600) {
// Define field showavailable to be added to choice.
$table = new xmldb_table('choice');
$field = new xmldb_field('showavailable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completionsubmit');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Choice savepoint reached.
upgrade_mod_savepoint(true, 2020061600, 'choice');
}
return true;
}
4 changes: 4 additions & 0 deletions mod/choice/lang/en/choice.php
Expand Up @@ -83,6 +83,7 @@
$string['indicator:socialbreadthdef_help'] = 'The participant has reached this percentage of the social engagement offered by the Choice activities during this analysis interval (Levels = No participation, Participant alone, Participant with others)';
$string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth';
$string['limit'] = 'Limit';
$string['limita'] = 'Limit: {$a}';
$string['limitno'] = 'Limit {no}';
$string['limitanswers'] = 'Limit the number of responses allowed';
$string['modulename'] = 'Choice';
Expand Down Expand Up @@ -137,11 +138,14 @@
$string['removeresponses'] = 'Remove all responses';
$string['responses'] = 'Responses';
$string['responsesresultgraphheader'] = 'Graph display';
$string['responsesa'] = 'Responses: {$a}';
$string['responsesto'] = 'Responses to {$a}';
$string['results'] = 'Results';
$string['savemychoice'] = 'Save my choice';
$string['search:activity'] = 'Choice - activity information';
$string['selectalloption'] = 'Select all "{$a}"';
$string['showavailable'] = 'Show available spaces';
$string['showavailable_help'] = 'Allow students to see how many available spaces there are per option.';
$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';
Expand Down
4 changes: 3 additions & 1 deletion mod/choice/lib.php
Expand Up @@ -213,7 +213,9 @@ function choice_prepare_options($choice, $user, $coursemodule, $allresponses) {

$cdisplay = array('options'=>array());

$cdisplay['limitanswers'] = true;
$cdisplay['limitanswers'] = $choice->limitanswers;
$cdisplay['showavailable'] = $choice->showavailable;

$context = context_module::instance($coursemodule->id);

foreach ($choice->option as $optionid => $text) {
Expand Down
4 changes: 4 additions & 0 deletions mod/choice/mod_form.php
Expand Up @@ -44,6 +44,10 @@ function definition() {
$mform->addElement('selectyesno', 'limitanswers', get_string('limitanswers', 'choice'));
$mform->addHelpButton('limitanswers', 'limitanswers', 'choice');

$mform->addElement('selectyesno', 'showavailable', get_string('showavailable', 'choice'));
$mform->addHelpButton('showavailable', 'showavailable', 'choice');
$mform->hideIf('showavailable', 'limitanswers', 'eq', 0);

$repeatarray = array();
$repeatarray[] = $mform->createElement('text', 'option', get_string('optionno', 'choice'));
$repeatarray[] = $mform->createElement('text', 'limit', get_string('limitno', 'choice'));
Expand Down
19 changes: 17 additions & 2 deletions mod/choice/renderer.php
Expand Up @@ -50,7 +50,7 @@ public function display_options($options, $coursemoduleid, $vertical = false, $m
$choicecount = 0;
foreach ($options['options'] as $option) {
$choicecount++;
$html .= html_writer::start_tag('li', array('class'=>'option'));
$html .= html_writer::start_tag('li', array('class' => 'option mr-3'));
if ($multiple) {
$option->attributes->name = 'answer[]';
$option->attributes->type = 'checkbox';
Expand All @@ -67,6 +67,13 @@ public function display_options($options, $coursemoduleid, $vertical = false, $m
$availableoption--;
}

if (!empty($options['limitanswers']) && !empty($options['showavailable'])) {
$labeltext .= html_writer::empty_tag('br');
$labeltext .= get_string("responsesa", "choice", $option->countanswers);
$labeltext .= html_writer::empty_tag('br');
$labeltext .= get_string("limita", "choice", $option->maxanswers);
}

$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 Down Expand Up @@ -182,6 +189,11 @@ public function display_publish_name_vertical($choices) {
$headertitle = get_string('notanswered', 'choice');
} else if ($optionid > 0) {
$headertitle = format_string($choices->options[$optionid]->text);
if (!empty($choices->options[$optionid]->user) && count($choices->options[$optionid]->user) > 0) {
if ((count($choices->options[$optionid]->user)) == ($choices->options[$optionid]->maxanswer)) {
$headertitle .= ' ' . get_string('full', 'choice');
}
}
}
$celltext = $headertitle;

Expand Down Expand Up @@ -209,7 +221,10 @@ public function display_publish_name_vertical($choices) {
if (!empty($options->user) && count($options->user) > 0) {
$numberofuser = count($options->user);
}

if (($choices->limitanswers) && ($choices->showavailable)) {
$numberofuser .= html_writer::empty_tag('br');
$numberofuser .= get_string("limita", "choice", $options->maxanswer);
}
$celloption->text = html_writer::div($celltext, 'text-center');
$optionsnames[$optionid] = $celltext;
$cellusernumber->text = html_writer::div($numberofuser, 'text-center');
Expand Down
19 changes: 19 additions & 0 deletions mod/choice/tests/behat/limit_responses.feature
Expand Up @@ -10,6 +10,7 @@ Feature: Limit choice responses
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
Expand All @@ -18,12 +19,14 @@ Feature: Limit choice responses
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "Choice" to section "1" and I fill the form with:
| Choice name | Choice name |
| Description | Choice Description |
| Limit the number of responses allowed | 1 |
| Show available spaces | 1 |
| option[0] | Option 1 |
| limit[0] | 1 |
| option[1] | Option 2 |
Expand All @@ -38,4 +41,20 @@ Feature: Limit choice responses
And I am on "Course 1" course homepage
And I follow "Choice name"
And I should see "Option 1 (Full)"
And I should see "Responses: 1"
And I should see "Limit: 1"
And the "choice_1" "radio" should be disabled
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Choice name"
And I navigate to "Edit settings" in current page administration
And I set the following fields to these values:
| Limit the number of responses allowed | No |
And I press "Save and return to course"
And I log out
And I log in as "student3"
And I am on "Course 1" course homepage
And I follow "Choice name"
Then I should not see "Limit: 1"
And the "choice_1" "radio" should be enabled
19 changes: 19 additions & 0 deletions mod/choice/tests/behat/multiple_options.feature
Expand Up @@ -52,6 +52,7 @@ Feature: Multiple option choice response
| Description | Choice Description |
| Allow more than one choice to be selected | Yes |
| Limit the number of responses allowed | 1 |
| Show available spaces | 1 |
| option[0] | Option 1 |
| limit[0] | 1 |
| option[1] | Option 2 |
Expand All @@ -74,3 +75,21 @@ Feature: Multiple option choice response
And the "#choice_1" "css_element" should be disabled
And the "#choice_2" "css_element" should be disabled
And the "#choice_3" "css_element" should be enabled
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Choice name"
And I follow "View 1 responses"
Then I should see "Option 1 (Full)"
And I should see "Limit: 1"
And I am on "Course 1" course homepage with editing mode on
And I follow "Choice name"
And I navigate to "Edit settings" in current page administration
And I set the following fields to these values:
| Limit the number of responses allowed | No |
And I press "Save and return to course"
And I am on "Course 1" course homepage
And I follow "Choice name"
And I follow "View 1 responses"
Then I should not see "Limit: 1"
And I log out
2 changes: 1 addition & 1 deletion mod/choice/version.php
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2020061500; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2020061600; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2020060900; // Requires this Moodle version
$plugin->component = 'mod_choice'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
6 changes: 6 additions & 0 deletions theme/boost/scss/moodle/modules.scss
Expand Up @@ -17,6 +17,12 @@ select {
}
}

.path-mod-choice {
.choices .option label {
vertical-align: top;
}
}

.path-mod-feedback .feedback_form .col-form-label {
display: block !important; /* stylelint-disable-line declaration-no-important */
}
Expand Down
3 changes: 3 additions & 0 deletions theme/boost/style/moodle.css
Expand Up @@ -16591,6 +16591,9 @@ select {
.path-mod-choice .horizontal .choices .option {
display: inline-block; }

.path-mod-choice .choices .option label {
vertical-align: top; }

.path-mod-feedback .feedback_form .col-form-label {
display: block !important;
/* stylelint-disable-line declaration-no-important */ }
Expand Down
3 changes: 3 additions & 0 deletions theme/classic/style/moodle.css
Expand Up @@ -16820,6 +16820,9 @@ select {
.path-mod-choice .horizontal .choices .option {
display: inline-block; }

.path-mod-choice .choices .option label {
vertical-align: top; }

.path-mod-feedback .feedback_form .col-form-label {
display: block !important;
/* stylelint-disable-line declaration-no-important */ }
Expand Down

0 comments on commit 8419764

Please sign in to comment.