Skip to content

Commit 5847d43

Browse files
committed
Minimum grade changes
* Minimum changes required to add manual grades to a BBB activity
1 parent e0a9cf2 commit 5847d43

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

mod/bigbluebuttonbn/lib.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com)
2525
*/
2626
defined('MOODLE_INTERNAL') || die;
27+
require_once("$CFG->libdir/gradelib.php");
2728

2829
use core_calendar\action_factory;
2930
use core_calendar\local\event\entities\action_interface;
@@ -72,7 +73,7 @@ function bigbluebuttonbn_supports($feature) {
7273
FEATURE_BACKUP_MOODLE2 => true,
7374
FEATURE_COMPLETION_TRACKS_VIEWS => true,
7475
FEATURE_COMPLETION_HAS_RULES => true,
75-
FEATURE_GRADE_HAS_GRADE => false,
76+
FEATURE_GRADE_HAS_GRADE => true,
7677
FEATURE_GRADE_OUTCOMES => false,
7778
FEATURE_SHOW_DESCRIPTION => true,
7879
FEATURE_MOD_PURPOSE => MOD_PURPOSE_COMMUNICATION,
@@ -111,6 +112,9 @@ function bigbluebuttonbn_add_instance($bigbluebuttonbn) {
111112

112113
// Call any active subplugin so to signal a new creation.
113114
extension::add_instance($bigbluebuttonbn);
115+
116+
bigbluebuttonbn_grade_item_update($bigbluebuttonbn);
117+
114118
return $bigbluebuttonbn->id;
115119
}
116120

@@ -138,6 +142,8 @@ function bigbluebuttonbn_update_instance($bigbluebuttonbn) {
138142
// Update a record.
139143
$DB->update_record('bigbluebuttonbn', $bigbluebuttonbn);
140144

145+
bigbluebuttonbn_grade_item_update($bigbluebuttonbn);
146+
141147
// Get the meetingid column in the bigbluebuttonbn table.
142148
$bigbluebuttonbn->meetingid = (string) $DB->get_field('bigbluebuttonbn', 'meetingid', ['id' => $bigbluebuttonbn->id]);
143149

@@ -757,3 +763,27 @@ function bigbluebuttonbn_course_backend_generator_create_activity(tool_generator
757763
function bigbluebuttonbn_is_branded(): bool {
758764
return true;
759765
}
766+
767+
/**
768+
* Update/create grade item for given BigBlueButtonBN activity
769+
*
770+
* @category grade
771+
* @param stdClass $instance A BBB instance object with extra cmidnumber
772+
* @param mixed $grades Optional array/object of grade(s); 'reset' means reset grades in gradebook
773+
* @return object grade_item
774+
*/
775+
function bigbluebuttonbn_grade_item_update(stdclass $bigbluebuttonbn, $grades=NULL) {
776+
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
777+
require_once($CFG->libdir.'/gradelib.php');
778+
}
779+
$params = array('itemname' => $bigbluebuttonbn->name);
780+
if ($bigbluebuttonbn->grade > 0) {
781+
$params['gradetype'] = GRADE_TYPE_VALUE;
782+
$params['grademax'] = $bigbluebuttonbn->grade;
783+
$params['grademin'] = 0;
784+
785+
} else {
786+
$params['gradetype'] = GRADE_TYPE_NONE;
787+
}
788+
return grade_update('mod/bigbluebuttonbn', $bigbluebuttonbn->course, 'mod', 'bigbluebuttonbn', $bigbluebuttonbn->id, 0, $grades, $params);
789+
}

mod/bigbluebuttonbn/mod_form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public function definition(): void {
9494
$this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
9595
// Now add subplugins form elements.
9696
$this->add_subplugins_elements();
97-
97+
// Add standard grading elements.
98+
$this->standard_grading_coursemodule_elements();
9899
// Add standard elements, common to all modules.
99100
$this->standard_coursemodule_elements();
100101
// Add standard buttons, common to all modules.

0 commit comments

Comments
 (0)