diff --git a/mod/bigbluebuttonbn/classes/extension.php b/mod/bigbluebuttonbn/classes/extension.php index dff3546f33f2a..9eeed82960175 100644 --- a/mod/bigbluebuttonbn/classes/extension.php +++ b/mod/bigbluebuttonbn/classes/extension.php @@ -19,6 +19,7 @@ use cm_info; use mod_bigbluebuttonbn\local\extension\action_url_addons; use mod_bigbluebuttonbn\local\extension\custom_completion_addons; +use mod_bigbluebuttonbn\local\extension\gradebook_addons; use mod_bigbluebuttonbn\local\extension\mod_form_addons; use mod_bigbluebuttonbn\local\extension\mod_instance_helper; use stdClass; @@ -217,4 +218,23 @@ public static function delete_instance(int $id): void { $fmclass->delete_instance($id); } } + + /** + * Get all gradebook addons classes. + * + * @return array of gradebook addon classes. + */ + public static function gradebook_addons_classes(): array { + return self::get_classes_implementing(gradebook_addons::class); + } + + /** + * Get all gradebook addons classes instances + * + * @param stdClass|null $modinstance + * @return array of gradebook addon classes instances + */ + public static function gradebook_addons_instances(stdClass $modinstance): array { + return self::get_instances_implementing(gradebook_addons::class, [$modinstance]); + } } diff --git a/mod/bigbluebuttonbn/classes/local/extension/gradebook_addons.php b/mod/bigbluebuttonbn/classes/local/extension/gradebook_addons.php new file mode 100644 index 0000000000000..6c5bd7a50ccbe --- /dev/null +++ b/mod/bigbluebuttonbn/classes/local/extension/gradebook_addons.php @@ -0,0 +1,55 @@ +. + +namespace mod_bigbluebuttonbn\local\extension; + +use stdClass; +use mod_bigbluebuttonbn\instance; + +/** + * A class to deal with broker addons in a subplugin + * + * @package mod_bigbluebuttonbn + * @copyright 2024 onwards, Blindside Networks Inc + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) + */ +abstract class broker_meeting_events_addons { + + /** + * @var stdClass $modinstance The instance of the activity in the database + */ + protected $modinstance; + + /** + * Constructor + * + * @param instance $instance BigBlueButton instance + */ + public function __construct(stdClass $modinstance) { + $this->modinstance = $modinstance; + } + + /** + * Update the grade item for a given activity + */ + abstract public function grade_item_update($grades=NULL); + + /** + * Update the grade(s) for the supplied user + */ + abstract public function update_grades($userid=0, $nullifnone=true); +} diff --git a/mod/bigbluebuttonbn/lib.php b/mod/bigbluebuttonbn/lib.php index e7c649ba2714b..bad7251c22a62 100644 --- a/mod/bigbluebuttonbn/lib.php +++ b/mod/bigbluebuttonbn/lib.php @@ -72,7 +72,7 @@ function bigbluebuttonbn_supports($feature) { FEATURE_BACKUP_MOODLE2 => true, FEATURE_COMPLETION_TRACKS_VIEWS => true, FEATURE_COMPLETION_HAS_RULES => true, - FEATURE_GRADE_HAS_GRADE => false, + FEATURE_GRADE_HAS_GRADE => true, FEATURE_GRADE_OUTCOMES => false, FEATURE_SHOW_DESCRIPTION => true, FEATURE_MOD_PURPOSE => MOD_PURPOSE_COMMUNICATION, @@ -279,6 +279,42 @@ function bigbluebuttonbn_get_extra_capabilities() { return ['moodle/site:accessallgroups']; } +/** + * Create grade item for given activity. + * + * @param stdClass $bigbluebuttonbn record with extra cmidnumber + * @param array $grades optional array/object of grade(s); 'reset' means reset grades in gradebook + * @return int 0 if ok, error code otherwise + */ +function bigbluebuttonbn_grade_item_update($bigbluebuttonbn, $grades=null) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + // Hooks for extensions. + $extensions = extension::gradebook_addons_instances($bigbluebuttonbn); + foreach ($extensions as $extension) { + $extension->grade_item_update($grades); + } +} + +/** + * Update activity grades. + * + * @param stdClass $bigbluebuttonbn database record + * @param int $userid specific user only, 0 means all + * @param bool $nullifnone - not used + */ +function bigbluebuttonbn_update_grades($bigbluebuttonbn, $userid=0, $nullifnone=true) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + // Hooks for extensions. + $extensions = extension::gradebook_addons_instances($bigbluebuttonbn); + foreach ($extensions as $extension) { + $extension->update_grades($userid, $nullifnone); + } +} + /** * Called by course/reset.php *