Skip to content

Commit

Permalink
Fix code checker issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAlexH committed Nov 13, 2024
1 parent 009125f commit 5c23329
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 117 deletions.
1 change: 0 additions & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,5 @@ function xmldb_choicegroup_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2024092600, 'choicegroup');
}


return true;
}
2 changes: 1 addition & 1 deletion lang/en/choicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
$string['completiondetail:submit'] = 'Choose a group';
$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['defaultsettings'] = 'Default settings';
$string['del'] = "Remove";
$string['del_group'] = "Remove Group";
$string['del_groups'] = "Remove Groups";
Expand Down
152 changes: 111 additions & 41 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\notification;

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

require_once($CFG->dirroot . '/course/moodleform_mod.php');

/**
* Activity instance editing form.
*/
class mod_choicegroup_mod_form extends moodleform_mod {
class mod_choicegroup_mod_form extends moodleform_mod
{

/**
* Define form elements
Expand All @@ -39,7 +42,8 @@ class mod_choicegroup_mod_form extends moodleform_mod {
* @throws coding_exception
* @throws dml_exception
*/
public function definition() {
public function definition()
{
global $CFG, $choicegroupshowresults, $choicegrouppublish, $choicegroupdisplay, $DB, $COURSE, $PAGE;

$mform =& $this->_form;
Expand Down Expand Up @@ -81,7 +85,7 @@ public function definition() {
$a->linkgroups = $CFG->wwwroot . '/group/index.php?id=' . $COURSE->id;
$a->linkcourse = $CFG->wwwroot . '//course/view.php?id=' . $COURSE->id;
$message = get_string('pleasesetonegroupor', 'choicegroup', $a);
\core\notification::add($message, \core\notification::WARNING);
notification::add($message, notification::WARNING);
}

$dbgroupings = $DB->get_records('groupings', ['courseid' => $COURSE->id]);
Expand All @@ -107,7 +111,11 @@ public function definition() {
// -------------------------.
$mform->addElement('header', 'miscellaneoussettingshdr', get_string('miscellaneoussettings', 'form'));
$mform->setExpanded('miscellaneoussettingshdr');
$mform->addElement('checkbox', 'multipleenrollmentspossible', get_string('multipleenrollmentspossible', 'choicegroup'));
$mform->addElement(
'checkbox',
'multipleenrollmentspossible',
get_string('multipleenrollmentspossible', 'choicegroup')
);

$mform->addElement('text', 'maxenrollments', get_string('maxenrollments', 'choicegroup'), ['size' => '6']);
$mform->addHelpButton('maxenrollments', 'maxenrollments', 'choicegroup');
Expand All @@ -119,8 +127,13 @@ public function definition() {
$mform->addElement('select', 'showresults', get_string("publish", "choicegroup"), $choicegroupshowresults);
$mform->setDefault('showresults', CHOICEGROUP_SHOWRESULTS_DEFAULT);

$mform->addElement('select', 'publish', get_string("privacy", "choicegroup"), $choicegrouppublish,
CHOICEGROUP_PUBLISH_DEFAULT);
$mform->addElement(
'select',
'publish',
get_string("privacy", "choicegroup"),
$choicegrouppublish,
CHOICEGROUP_PUBLISH_DEFAULT
);
$mform->setDefault('publish', CHOICEGROUP_PUBLISH_DEFAULT);
$mform->disabledIf('publish', 'showresults', 'eq', 0);

Expand Down Expand Up @@ -150,7 +163,9 @@ public function definition() {
// -------------------------.

$mform->addElement('header', 'groups', get_string('groupsheader', 'choicegroup'));
$mform->addElement('html', '<fieldset class="clearfix">
$mform->addElement(
'html',
'<fieldset class="clearfix">
<div class="fcontainer clearfix">
<label for="fitem_id_option_0" class="fitemtitle">'
. get_string('choicegroupoptions_description', 'choicegroup') . '</label>
Expand All @@ -163,7 +178,8 @@ public function definition() {
<th class="col-lg-6">' . get_string('selected_groups', 'choicegroup') . '</th>
</tr>
<tr class="row">
<td style="vertical-align: top" class="col-5">');
<td style="vertical-align: top" class="col-5">'
);
$mform->addHelpButton('groups', 'choicegroupoptions', 'choicegroup');

$mform->addElement('html', '<select class="col-12" id="availablegroups" name="availableGroups" multiple size=10>');
Expand All @@ -172,37 +188,57 @@ public function definition() {
if (isset($grouping->linkedGroupsIDs) && count($grouping->linkedGroupsIDs) > 1) {
// Grouping has more than 2 items, thus we should display it (otherwise it would be clearer to display only that
// single group alone).
$mform->addElement('html', '<option value="' . $groupingid .
'" style="font-weight: bold" class="grouping">' . get_string('char_bullet_expanded', 'choicegroup') .
$grouping->name . '</option>');
$mform->addElement(
'html',
'<option value="' . $groupingid .
'" style="font-weight: bold" class="grouping">' . get_string(
'char_bullet_expanded',
'choicegroup'
) .
$grouping->name . '</option>'
);
foreach ($grouping->linkedGroupsIDs as $linkedgroupid) {
if (isset($groups[$linkedgroupid])) {
$mform->addElement('html', '<option value="' . $linkedgroupid .
'" class="group nested">&nbsp;&nbsp;&nbsp;&nbsp;' . $groups[$linkedgroupid]->name . '</option>');
$mform->addElement(
'html',
'<option value="' . $linkedgroupid .
'" class="group nested">&nbsp;&nbsp;&nbsp;&nbsp;' . $groups[$linkedgroupid]->name . '</option>'
);
$groups[$linkedgroupid]->mentioned = true;
}
}
}
}
foreach ($groups as $group) {
if ($group->mentioned === false) {
$mform->addElement('html', '<option title="' . $group->name . '" value="' . $group->id .
'" class="group toplevel">' . format_string($group->name) . '</option>');
$mform->addElement(
'html',
'<option title="' . $group->name . '" value="' . $group->id .
'" class="group toplevel">' . format_string($group->name) . '</option>'
);
}
}
$mform->addElement('html', '</select><br><button name="expandButton" type="button" disabled id="expandButton" ' .
$mform->addElement(
'html',
'</select><br><button name="expandButton" type="button" disabled id="expandButton" ' .
'class="btn btn-secondary">' . get_string('expand_all_groupings', 'choicegroup') .
'</button><button name="collapseButton" type="button" disabled id="collapseButton" class="btn btn-secondary">' .
get_string('collapse_all_groupings', 'choicegroup') .
'</button><br>' . get_string('double_click_grouping_legend', 'choicegroup') . '<br>' .
get_string('double_click_group_legend', 'choicegroup'));
get_string('double_click_group_legend', 'choicegroup')
);

$mform->addElement('html', '
$mform->addElement(
'html',
'
</td><td class="col-2"><button id="addGroupButton" name="add" type="button" disabled class="btn btn-secondary">' .
get_string('add', 'choicegroup') .
'</button><div><button name="remove" type="button" disabled id="removeGroupButton" class="btn btn-secondary">' .
get_string('del', 'choicegroup') . '</button></div></td>');
$mform->addElement('html', '<td style="vertical-align: top" class="col-5">
get_string('del', 'choicegroup') . '</button></div></td>'
);
$mform->addElement(
'html',
'<td style="vertical-align: top" class="col-5">
<select class="col-12" id="id_selectedGroups" name="selectedGroups" multiple size=10></select>
<div id="fitem_id_limit_0" class="fitem fitem_ftext" style="display:none">
<div>
Expand All @@ -212,20 +248,26 @@ public function definition() {
<input class="mod-choicegroup-limit-input" type="text" value="0" id="ui_limit_input" disabled="disabled">
</div>
</div>
</td>');
</td>'
);

$mform->addElement('html', '</tr></table>
$mform->addElement(
'html',
'</tr></table>
</div>
</div>
</div>
</div>
</fieldset>');
</fieldset>'
);

$mform->setExpanded('groups');

foreach ($groups as $group) {
$mform->addElement('hidden', 'group_' . $group->id . '_limit', '', ['id' => 'group_' . $group->id . '_limit',
'class' => 'limit_input_node', ]);
$mform->addElement('hidden', 'group_' . $group->id . '_limit', '', [
'id' => 'group_' . $group->id . '_limit',
'class' => 'limit_input_node',
]);
$mform->setType('group_' . $group->id . '_limit', PARAM_RAW);
}

Expand All @@ -237,19 +279,32 @@ public function definition() {
$serializedselectedgroupsvalue .= ';' . $groupid;
$mform->setDefault('group_' . $groupid . '_limit', $cg->maxanswers[$optionid]);
}

}

$mform->addElement('hidden', 'serializedselectedgroups', $serializedselectedgroupsvalue,
['id' => 'serializedselectedgroups']);
$mform->addElement(
'hidden',
'serializedselectedgroups',
$serializedselectedgroupsvalue,
['id' => 'serializedselectedgroups']
);
$mform->setType('serializedselectedgroups', PARAM_RAW);

switch (get_config('choicegroup', 'sortgroupsby')) {
case CHOICEGROUP_SORTGROUPS_CREATEDATE:
$systemdefault = [CHOICEGROUP_SORTGROUPS_SYSTEMDEFAULT => get_string('systemdefault_date', 'choicegroup')];
$systemdefault = [
CHOICEGROUP_SORTGROUPS_SYSTEMDEFAULT => get_string(
'systemdefault_date',
'choicegroup'
)
];
break;
case CHOICEGROUP_SORTGROUPS_NAME:
$systemdefault = [CHOICEGROUP_SORTGROUPS_SYSTEMDEFAULT => get_string('systemdefault_name', 'choicegroup')];
$systemdefault = [
CHOICEGROUP_SORTGROUPS_SYSTEMDEFAULT => get_string(
'systemdefault_name',
'choicegroup'
)
];
break;
}

Expand All @@ -260,10 +315,15 @@ public function definition() {
// Default Group Description Display
$descriptionoptions = [
CHOICEGROUP_GROUPDESCRIPTIONSTATE_VISIBLE => get_string('showdescription', 'choicegroup'),
CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN => get_string('hidedescription', 'choicegroup')
CHOICEGROUP_GROUPDESCRIPTIONSTATE_HIDDEN => get_string('hidedescription', 'choicegroup'),
];
$groupdescriptionstate = get_config('choicegroup', 'defaultgroupdescriptionstate');
$mform->addElement('select', 'defaultgroupdescriptionstate', get_string('defaultgroupdescriptionstate', 'choicegroup'), $descriptionoptions);
$mform->addElement(
'select',
'defaultgroupdescriptionstate',
get_string('defaultgroupdescriptionstate', 'choicegroup'),
$descriptionoptions
);
$mform->setDefault('defaultgroupdescriptionstate', $groupdescriptionstate);
// -------------------------
// Go on the with the remainder of the form
Expand Down Expand Up @@ -291,7 +351,8 @@ public function definition() {
* @param array $defaultvalues
* @return void
*/
public function data_preprocessing(&$defaultvalues) {
public function data_preprocessing(&$defaultvalues)
{
global $PAGE;

if ($PAGE->pagetype != 'course-defaultcompletion') {
Expand All @@ -303,7 +364,6 @@ public function data_preprocessing(&$defaultvalues) {
} else {
$defaultvalues['timerestrict'] = 1;
}

}

/**
Expand All @@ -312,11 +372,16 @@ public function data_preprocessing(&$defaultvalues) {
* @return void
* @throws coding_exception
*/
public function js_call() {
public function js_call()
{
global $PAGE;
$params = [$this->_form->getAttribute('id')];
$PAGE->requires->yui_module('moodle-mod_choicegroup-form', 'Y.Moodle.mod_choicegroup.form.init', $params);
foreach (array_keys(get_string_manager()->load_component_strings('choicegroup', current_language())) as $string) {
foreach (
array_keys(
get_string_manager()->load_component_strings('choicegroup', current_language())
) as $string
) {
$PAGE->requires->string_for_js($string, 'choicegroup');
}
}
Expand All @@ -330,7 +395,8 @@ public function js_call() {
* @param stdClass $data the form data to be modified.
* @return void
*/
public function data_postprocessing($data): void {
public function data_postprocessing($data): void
{
parent::data_postprocessing($data);
// Set up completion section even if checkbox is not ticked.
if (!empty($data->completionunlocked)) {
Expand All @@ -348,7 +414,8 @@ public function data_postprocessing($data): void {
* @return array
* @throws coding_exception
*/
public function validation($data, $files) {
public function validation($data, $files)
{
$errors = parent::validation($data, $files);

$groupids = explode(';', $data['serializedselectedgroups']);
Expand All @@ -370,7 +437,8 @@ public function validation($data, $files) {
*
* @return false|object
*/
public function get_data() {
public function get_data()
{
$data = parent::get_data();
if (!$data) {
return false;
Expand All @@ -388,7 +456,8 @@ public function get_data() {
* @return string[]
* @throws coding_exception
*/
public function add_completion_rules() {
public function add_completion_rules()
{
global $CFG;

$mform =& $this->_form;
Expand All @@ -410,7 +479,8 @@ public function add_completion_rules() {
* @param array $data Input data (not yet validated)
* @return bool
*/
public function completion_rule_enabled($data) {
public function completion_rule_enabled($data)
{
return !empty($data['completionsubmit']);
}

Expand Down
Loading

0 comments on commit 5c23329

Please sign in to comment.