Skip to content

Commit f337bf9

Browse files
committed
added hook for gradebook
1 parent d579cab commit f337bf9

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

mod/bigbluebuttonbn/classes/extension.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use cm_info;
2020
use mod_bigbluebuttonbn\local\extension\action_url_addons;
2121
use mod_bigbluebuttonbn\local\extension\custom_completion_addons;
22+
use mod_bigbluebuttonbn\local\extension\gradebook_addons;
2223
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
2324
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
2425
use stdClass;
@@ -217,4 +218,23 @@ public static function delete_instance(int $id): void {
217218
$fmclass->delete_instance($id);
218219
}
219220
}
221+
222+
/**
223+
* Get all gradebook addons classes.
224+
*
225+
* @return array of gradebook addon classes.
226+
*/
227+
public static function gradebook_addons_classes(): array {
228+
return self::get_classes_implementing(gradebook_addons::class);
229+
}
230+
231+
/**
232+
* Get all gradebook addons classes instances
233+
*
234+
* @param stdClass|null $modinstance
235+
* @return array of gradebook addon classes instances
236+
*/
237+
public static function gradebook_addons_instances(stdClass $modinstance): array {
238+
return self::get_instances_implementing(gradebook_addons::class, [$modinstance]);
239+
}
220240
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace mod_bigbluebuttonbn\local\extension;
18+
19+
require_once("$CFG->libdir/gradelib.php");
20+
21+
use stdClass;
22+
23+
/**
24+
* A class to deal with broker addons in a subplugin
25+
*
26+
* @package mod_bigbluebuttonbn
27+
* @copyright 2024 onwards, Blindside Networks Inc
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
30+
*/
31+
abstract class gradebook_addons {
32+
33+
/**
34+
* @var stdClass $modinstance The instance of the activity in the database
35+
*/
36+
protected $modinstance;
37+
38+
/**
39+
* Constructor
40+
*
41+
* @param stdClass $modinstance BigBlueButton instance
42+
*/
43+
public function __construct(stdClass $modinstance) {
44+
$this->modinstance = $modinstance;
45+
}
46+
47+
/**
48+
* Update the grade item for a given activity
49+
*/
50+
abstract public function grade_item_update($grades=NULL);
51+
52+
/**
53+
* Update the grade(s) for the supplied user
54+
*/
55+
abstract public function update_grades($userid=0, $nullifnone=true);
56+
}

mod/bigbluebuttonbn/lib.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,18 @@ function bigbluebuttonbn_grade_item_update(stdclass $bigbluebuttonbn, $grades=NU
776776
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
777777
require_once($CFG->libdir.'/gradelib.php');
778778
}
779+
780+
// Hook for extensions. We allow extensions to update the grade item. This takes precedence over the default behaviour.
781+
$extensions = extension::gradebook_addons_instances($bigbluebuttonbn);
782+
foreach ($extensions as $extension) {
783+
$grade_item = $extension->grade_item_update($grades);
784+
// Only one extension can update the grade item. The first one that does will be used.
785+
if ($grade_item) {
786+
return $grade_item;
787+
}
788+
}
789+
790+
// Since the grade item is not updated by any extension, we update it here.
779791
$params = array('itemname' => $bigbluebuttonbn->name);
780792
if ($bigbluebuttonbn->grade > 0) {
781793
$params['gradetype'] = GRADE_TYPE_VALUE;
@@ -785,5 +797,6 @@ function bigbluebuttonbn_grade_item_update(stdclass $bigbluebuttonbn, $grades=NU
785797
} else {
786798
$params['gradetype'] = GRADE_TYPE_NONE;
787799
}
800+
788801
return grade_update('mod/bigbluebuttonbn', $bigbluebuttonbn->course, 'mod', 'bigbluebuttonbn', $bigbluebuttonbn->id, 0, $grades, $params);
789802
}

0 commit comments

Comments
 (0)