Skip to content

Commit

Permalink
merge master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAlexH committed Nov 13, 2024
2 parents 7fad595 + 2f5569e commit 009125f
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 37 deletions.
57 changes: 29 additions & 28 deletions db/install.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/choicegroup/db" VERSION="20120425" COMMENT="XMLDB file for Moodle mod/choicegroup"
<XMLDB PATH="mod/choicegroup/db" VERSION="20240926" COMMENT="XMLDB file for Moodle mod/choicegroup"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="choicegroup" COMMENT="Available choicegroups are stored here" NEXT="choicegroup_options">
<TABLE NAME="choicegroup" COMMENT="Available choicegroups are stored here">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="course" NEXT="intro"/>
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="intro" NEXT="publish"/>
<FIELD NAME="publish" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="introformat" NEXT="multipleenrollmentspossible"/>
<FIELD NAME="multipleenrollmentspossible" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="publish" NEXT="showresults"/>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<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="multipleenrollmentspossible" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maxenrollments" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="showresults" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="multipleenrollmentspossible" NEXT="display"/>
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="showresults" NEXT="allowupdate"/>
<FIELD NAME="allowupdate" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="display" NEXT="showunanswered"/>
<FIELD NAME="showunanswered" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="allowupdate" NEXT="limitanswers"/>
<FIELD NAME="limitanswers" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="showunanswered" NEXT="timeopen"/>
<FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="limitanswers" NEXT="timeclose"/>
<FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeopen" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeclose" NEXT="completionsubmit"/>
<FIELD NAME="completionsubmit" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" 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 choicegroup." PREVIOUS="timemodified" NEXT="sortgroupsby"/>
<FIELD NAME="sortgroupsby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Column used to sort groups." PREVIOUS="completionsubmit" NEXT="onlyactive"/>
<FIELD NAME="onlyactive" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, users with expired or suspended enrolments will be filtered out of response data." PREVIOUS="sortgroupsby"/>
<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"/>
<FIELD NAME="allowupdate" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="showunanswered" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<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="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 choicegroup."/>
<FIELD NAME="sortgroupsby" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Column used to sort groups."/>
<FIELD NAME="onlyactive" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, users with expired or suspended enrolments will be filtered out of response data."/>
<FIELD NAME="defaultgroupdescriptionstate" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Default group descriptions state"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand All @@ -33,17 +34,17 @@
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>
<TABLE NAME="choicegroup_options" COMMENT="available options to choicegroup" PREVIOUS="choicegroup">
<TABLE NAME="choicegroup_options" COMMENT="available options to choicegroup">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="choicegroupid"/>
<FIELD NAME="choicegroupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="groupid"/>
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="choicegroupid" NEXT="maxanswers"/>
<FIELD NAME="maxanswers" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="groupid" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="maxanswers"/>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="choicegroupid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maxanswers" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="choicegroupid"/>
<KEY NAME="choicegroupid" TYPE="foreign" FIELDS="choicegroupid" REFTABLE="choicegroup" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="choicegroupid" TYPE="foreign" FIELDS="choicegroupid" REFTABLE="choicegroup" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ function xmldb_choicegroup_upgrade($oldversion) {
// Group choice savepoint reached.
upgrade_mod_savepoint(true, 2021080500, 'choicegroup');
}
if ($oldversion < 2024092600) {

// Define field defaultgroupdescriptionstate to be added to choicegroup.
$table = new xmldb_table('choicegroup');
$field = new xmldb_field('defaultgroupdescriptionstate', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'onlyactive');

// Conditionally launch add field defaultgroupdescriptionstate.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Choicegroup savepoint reached.
upgrade_mod_savepoint(true, 2024092600, 'choicegroup');
}


return true;
}
2 changes: 2 additions & 0 deletions lang/en/choicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
$string['completionsubmit'] = 'Show as complete when user makes a choice';
$string['createdate'] = 'Group creation date';
$string['defaultsettings'] = 'Default settings';
$string['defaultgroupdescriptionstate'] = 'Default group description display';
$string['defaultgroupdescriptionstate_desc'] = 'Should the group description be displayed by default or not.';
$string['del'] = "Remove";
$string['del_group'] = "Remove Group";
$string['del_groups'] = "Remove Groups";
Expand Down
3 changes: 3 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
define('CHOICEGROUP_SORTGROUPS_CREATEDATE', '1');
define('CHOICEGROUP_SORTGROUPS_NAME', '2');

define('CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN', 0);
define('CHOICEGROUP_GROUPDESCRIPTIONSTATE_VISIBLE', 1);

// Ugly hack to make 3.11 and 4.0 work seamlessly.
if (!defined('FEATURE_MOD_PURPOSE')) {
define('FEATURE_MOD_PURPOSE', 'mod_purpose');
Expand Down
8 changes: 8 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ public function definition() {
$mform->addElement('select', 'sortgroupsby', get_string('sortgroupsby', 'choicegroup'), $options);
$mform->setDefault('sortgroupsby', CHOICEGROUP_SORTGROUPS_SYSTEMDEFAULT);

// Default Group Description Display
$descriptionoptions = [
CHOICEGROUP_GROUPDESCRIPTIONSTATE_VISIBLE => get_string('showdescription', 'choicegroup'),
CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN => get_string('hidedescription', 'choicegroup')
];
$groupdescriptionstate = get_config('choicegroup', 'defaultgroupdescriptionstate');
$mform->addElement('select', 'defaultgroupdescriptionstate', get_string('defaultgroupdescriptionstate', 'choicegroup'), $descriptionoptions);
$mform->setDefault('defaultgroupdescriptionstate', $groupdescriptionstate);
// -------------------------
// Go on the with the remainder of the form
// -------------------------.
Expand Down
20 changes: 15 additions & 5 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ class mod_choicegroup_renderer extends plugin_renderer_base {
*/
public function display_options($options, $coursemoduleid, $vertical = true, $publish = false, $limitanswers = false,
$showresults = false, $current = false, $choicegroupopen = false, $disabled = false,
$multipleenrollmentspossible = false, $onlyactive = false) {
$multipleenrollmentspossible = false, $onlyactive = false, $groupdescriptionstate = false) {
global $choicegroupgroups;

if ($groupdescriptionstate === false) {
$groupdescriptionstate = get_config('choicegroup', 'defaultgroupdescriptionstate');
}
$target = new moodle_url('/mod/choicegroup/view.php');
$attributes = ['method' => 'POST', 'action' => $target, 'class' => 'tableform'];

Expand All @@ -66,9 +69,15 @@ public function display_options($options, $coursemoduleid, $vertical = true, $pu
$html .= html_writer::tag('th', get_string('choice', 'choicegroup'), ['class' => 'width10']);

$group = get_string('group').' ';
$group .= html_writer::tag('a', get_string('showdescription', 'choicegroup'),
['role' => 'button', 'class' => 'choicegroup-descriptiondisplay choicegroup-descriptionshow btn btn-secondary ml-1',
'href' => '#', ]);
if ($groupdescriptionstate == CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN) {
$group .= html_writer::tag('a', get_string('showdescription', 'choicegroup'),
['role' => 'button', 'class' => 'choicegroup-descriptiondisplay choicegroup-descriptionshow btn btn-secondary ml-1',
'href' => '#',]);
} else {
$group .= html_writer::tag('a', get_string('hidedescription', 'choicegroup'),
['role' => 'button', 'class' => 'choicegroup-descriptiondisplay choicegroup-descriptionshow btn btn-secondary ml-1',
'href' => '#',]);
}
$html .= html_writer::tag('th', $group, ['class' => 'width40']);

if ( $showresults == CHOICEGROUP_SHOWRESULTS_ALWAYS ||
Expand Down Expand Up @@ -142,13 +151,14 @@ public function display_options($options, $coursemoduleid, $vertical = true, $pu
$option->attributes->disabled = true;
$availableoption--;
}
$hidden = ($groupdescriptionstate == CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN) ? "hidden" : "";
$labeltext .= html_writer::tag('div', format_text(file_rewrite_pluginfile_urls($group->description,
'pluginfile.php',
$context->id,
'group',
'description',
$group->id)),
['class' => 'choicegroups-descriptions hidden']);
['class' => "choicegroups-descriptions {$hidden}"]);
if ($disabled) {
$option->attributes->disabled = true;
}
Expand Down
11 changes: 11 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@
$options = choicegroup_get_sort_options();
$settings->add(new admin_setting_configselect('choicegroup/sortgroupsby', get_string('sortgroupsby', 'choicegroup'), '',
CHOICEGROUP_SORTGROUPS_CREATEDATE, $options));

$settings->add(new admin_setting_configselect(
'choicegroup/defaultgroupdescriptionstate',
get_string('defaultgroupdescriptionstate', 'choicegroup'),
get_string('defaultgroupdescriptionstate_desc', 'choicegroup'),
CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN,
[
CHOICEGROUP_GROUPDESCRIPTIONSTATE_VISIBLE => get_string('showdescription', 'choicegroup'),
CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN => get_string('hidedescription', 'choicegroup')
]
));
}
3 changes: 1 addition & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@

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

$plugin->version = 2024080801;
$plugin->version = 2024092600;
$plugin->requires = 2023100900; // Moodle 4.3.
$plugin->supported = [403, 405];
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.47 for Moodle 4.3-4.5 (Build: 2024080801)';
$plugin->component = 'mod_choicegroup';

5 changes: 3 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,18 @@

$options = choicegroup_prepare_options($choicegroup, $USER, $cm, $allresponses);
$renderer = $PAGE->get_renderer('mod_choicegroup');

if ((!$current || $choicegroup->allowupdate) && $choicegroupopen && is_enrolled($context, null, 'mod/choicegroup:choose')) {
// They haven't made their choicegroup yet or updates allowed and choicegroup is open.

echo $renderer->display_options($options, $cm->id, $choicegroup->display, $choicegroup->publish, $choicegroup->limitanswers,
$choicegroup->showresults, $current, $choicegroupopen, false, $choicegroup->multipleenrollmentspossible,
$choicegroup->onlyactive);
$choicegroup->onlyactive, $choicegroup->defaultgroupdescriptionstate);
} else {
// Form can not be updated.
echo $renderer->display_options($options, $cm->id, $choicegroup->display, $choicegroup->publish, $choicegroup->limitanswers,
$choicegroup->showresults, $current, $choicegroupopen, true, $choicegroup->multipleenrollmentspossible,
$choicegroup->onlyactive);
$choicegroup->onlyactive, $choicegroup->defaultgroupdescriptionstate);
}
$choicegroupformshown = true;

Expand Down

0 comments on commit 009125f

Please sign in to comment.