Skip to content

Commit 226d1e9

Browse files
committed
add grade pass functionality
This commits adds the ability to set a passing grade for a moodleoverflow that can be checked in the activity completions
1 parent b91f9a6 commit 226d1e9

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

db/install.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<FIELD NAME="allownegativereputation" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
2525
<FIELD NAME="grademaxgrade" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2626
<FIELD NAME="gradescalefactor" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
27+
<FIELD NAME="gradepass" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="grade needed to pass the grading"/>
2728
<FIELD NAME="gradecat" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2829
<FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
2930
<FIELD NAME="needsreview" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

db/upgrade.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,17 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
314314
upgrade_mod_savepoint(true, 2025031200, 'moodleoverflow');
315315
}
316316

317+
if ($oldversion < 2025112701) {
318+
// Define table moodleoverflow to be edited.
319+
$table = new xmldb_table('moodleoverflow');
320+
321+
// Create the field for the passing grade.
322+
$field = new xmldb_field('gradepass', XMLDB_TYPE_INTEGER, '10', null, null, null, 0, 'gradescalefactor');
323+
if (!$dbman->field_exists($table, $field)) {
324+
$dbman->add_field($table, $field);
325+
}
326+
327+
upgrade_mod_savepoint(true, 2025112701, 'moodleoverflow');
328+
}
317329
return true;
318330
}

lang/en/moodleoverflow.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@
165165
$string['give_a_reason'] = 'Give a reason (optional)';
166166
$string['gotoindex'] = 'Manage preferences';
167167
$string['grademaxgradeerror'] = 'Maximum grade must be a positive integer different than 0';
168+
$string['gradepasserror'] = 'Grade pass must be a positive integer';
169+
$string['gradepassvalidationerror'] = 'Grade pass can not be greater than the max grade';
168170
$string['gradesreport'] = 'Grades report';
169171
$string['gradesupdated'] = 'Grades updated';
170172
$string['helpamountofactivity'] = 'Help icon for activity';

mod_form.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,17 @@ public function definition() {
175175

176176
$mform->addElement('text', 'grademaxgrade', get_string('modgrademaxgrade', 'grades'));
177177
$mform->setType('grademaxgrade', PARAM_INT);
178-
$mform->addRule('grademaxgrade', get_string('grademaxgradeerror', 'moodleoverflow'), 'regex', '/^[0-9]+$/', 'client');
178+
$mform->addRule('grademaxgrade', get_string('grademaxgradeerror', 'moodleoverflow'), 'regex', '/^[1-9][0-9]*$/', 'client');
179179

180180
$mform->addElement('text', 'gradescalefactor', get_string('scalefactor', 'moodleoverflow'));
181181
$mform->addHelpButton('gradescalefactor', 'scalefactor', 'moodleoverflow');
182182
$mform->setType('gradescalefactor', PARAM_INT);
183-
$mform->addRule('gradescalefactor', get_string('scalefactorerror', 'moodleoverflow'), 'regex', '/^[0-9]+$/', 'client');
183+
$mform->addRule('gradescalefactor', get_string('scalefactorerror', 'moodleoverflow'), 'regex', '/^[1-9][0-9]*$/', 'client');
184+
185+
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
186+
$mform->addHelpButton('gradepass', 'gradepass', 'grades');
187+
$mform->setType('gradepass', PARAM_INT);
188+
$mform->addRule('gradepass', get_string('gradepasserror', 'moodleoverflow'), 'regex', '/^(0|[1-9][0-9]*)$/', 'client');
184189

185190
if ($this->_features->gradecat) {
186191
$mform->addElement(
@@ -299,6 +304,18 @@ public function data_postprocessing($data) {
299304
}
300305
}
301306

307+
/**
308+
* Handles data preprocessing.
309+
* @param array $defaultvalues
310+
* @return void
311+
*/
312+
public function data_preprocessing(&$defaultvalues) {
313+
parent::data_preprocessing($defaultvalues);
314+
if (isset($defaultvalues['gradepass'])) {
315+
$defaultvalues['gradepass'] = (int)$defaultvalues['gradepass'];
316+
}
317+
}
318+
302319
/**
303320
* Validates set data in mod_form
304321
* @param array $data
@@ -309,6 +326,11 @@ public function data_postprocessing($data) {
309326
public function validation($data, $files): array {
310327
$errors = parent::validation($data, $files);
311328

329+
// Validate the grade settings.
330+
if (isset($data['gradepass']) && isset($data['grademaxgrade']) && $data['gradepass'] > $data['grademaxgrade']) {
331+
$errors['gradepass'] = get_string('gradepassvalidationerror', 'moodleoverflow');
332+
}
333+
312334
// Validate that the limited answer settings.
313335
$currenttime = time();
314336
$isstarttime = !empty($data['la_starttime']);

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

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

29-
$plugin->version = 2025112700;
29+
$plugin->version = 2025112701;
3030
$plugin->requires = 2024100700.00; // Require Moodle 4.5.
3131
$plugin->supported = [405, 501];
3232
$plugin->component = 'mod_moodleoverflow';

0 commit comments

Comments
 (0)