Skip to content

Commit

Permalink
added hook for gradebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico committed Aug 28, 2024
1 parent d579cab commit f337bf9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mod/bigbluebuttonbn/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
56 changes: 56 additions & 0 deletions mod/bigbluebuttonbn/classes/local/extension/gradebook_addons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_bigbluebuttonbn\local\extension;

require_once("$CFG->libdir/gradelib.php");

use stdClass;

/**
* 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 gradebook_addons {

/**
* @var stdClass $modinstance The instance of the activity in the database
*/
protected $modinstance;

/**
* Constructor
*
* @param stdClass $modinstance 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);
}
13 changes: 13 additions & 0 deletions mod/bigbluebuttonbn/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@ function bigbluebuttonbn_grade_item_update(stdclass $bigbluebuttonbn, $grades=NU
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
}

// Hook for extensions. We allow extensions to update the grade item. This takes precedence over the default behaviour.
$extensions = extension::gradebook_addons_instances($bigbluebuttonbn);
foreach ($extensions as $extension) {
$grade_item = $extension->grade_item_update($grades);
// Only one extension can update the grade item. The first one that does will be used.
if ($grade_item) {
return $grade_item;
}
}

// Since the grade item is not updated by any extension, we update it here.
$params = array('itemname' => $bigbluebuttonbn->name);
if ($bigbluebuttonbn->grade > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE;
Expand All @@ -785,5 +797,6 @@ function bigbluebuttonbn_grade_item_update(stdclass $bigbluebuttonbn, $grades=NU
} else {
$params['gradetype'] = GRADE_TYPE_NONE;
}

return grade_update('mod/bigbluebuttonbn', $bigbluebuttonbn->course, 'mod', 'bigbluebuttonbn', $bigbluebuttonbn->id, 0, $grades, $params);
}

0 comments on commit f337bf9

Please sign in to comment.