forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-74296 mod_bigbluebuttonbn: Fix completion indicator
* Completion view should work out of the box * Patch the _user_outline and _user_complete so it works with completion view, while implementing something better in MDL-74468
- Loading branch information
1 parent
ca583bd
commit 48d5ef1
Showing
7 changed files
with
184 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\helpers; | ||
|
||
use cm_info; | ||
use mod_bigbluebuttonbn\instance; | ||
use mod_bigbluebuttonbn\logger; | ||
use stdClass; | ||
|
||
/** | ||
* Utility class for all user information | ||
* | ||
* Used mainly in user_outline and user_complete | ||
* | ||
* @package mod_bigbluebuttonbn | ||
* @copyright 2022 onwards, Blindside Networks Inc | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Laurent David (laurent [at] call-learning [dt] fr) | ||
*/ | ||
class user_info { | ||
/** | ||
* Event to watch for. | ||
*/ | ||
const EVENT_TO_WATCH = [ | ||
'join' => logger::EVENT_JOIN, | ||
'play_recording' => logger::EVENT_PLAYED | ||
]; | ||
|
||
/** | ||
* Get user outline and complete info | ||
* | ||
* @param stdClass $course | ||
* @param stdClass $user | ||
* @param cm_info $mod | ||
* @return array[] an array of infos and timestamps (latest timestamp) | ||
*/ | ||
public static function get_user_info_outline(stdClass $course, stdClass $user, cm_info $mod): array { | ||
$completion = new \completion_info($course); | ||
$cdata = $completion->get_data($mod, false, $user->id); | ||
$logtimestamps = []; | ||
$infos = []; | ||
if (!empty($cdata->viewed) && $cdata->viewed) { | ||
$infos[] = get_string('report_room_view', 'mod_bigbluebuttonbn'); | ||
$logtimestamps[] = $cdata->timemodified; | ||
} | ||
$instance = instance::get_from_cmid($mod->id); | ||
foreach (self::EVENT_TO_WATCH as $eventtype => $logtype) { | ||
$logs = logger::get_user_completion_logs($instance, $user->id, [$logtype]); | ||
if ($logs) { | ||
$infos[] = get_string("report_{$eventtype}_info", 'mod_bigbluebuttonbn', count($logs)); | ||
$latesttime = array_reduce($logs, | ||
function($acc, $log) { | ||
return ($acc > $log->timecreated) ? $acc : $log->timecreated; | ||
}, 0); | ||
$logtimestamps[] = $latesttime; | ||
} | ||
} | ||
return [$infos, $logtimestamps]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
mod/bigbluebuttonbn/tests/local/helpers/user_info_test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?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\helpers; | ||
|
||
use mod_bigbluebuttonbn\instance; | ||
use mod_bigbluebuttonbn\logger; | ||
use mod_bigbluebuttonbn\test\testcase_helper_trait; | ||
|
||
/** | ||
* User information printing test | ||
* | ||
* @package mod_bigbluebuttonbn | ||
* @copyright 2022 - present, Blindside Networks Inc | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Laurent David ([email protected]) | ||
* @covers \mod_bigbluebuttonbn\local\helpers\user_info | ||
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\user_info | ||
*/ | ||
class user_info_test extends \advanced_testcase { | ||
use testcase_helper_trait; | ||
|
||
/** | ||
* Test user info outline | ||
* | ||
* @return void | ||
*/ | ||
public function test_get_user_info_outline() { | ||
$this->initialise_mock_server(); | ||
$this->resetAfterTest(); | ||
|
||
$generator = $this->getDataGenerator(); | ||
$user = $generator->create_and_enrol($this->get_course()); | ||
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(); | ||
$this->setUser($user); | ||
|
||
// Now create a couple of logs. | ||
$instance = instance::get_from_instanceid($bbactivity->id); | ||
$recordings = $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"]]); | ||
logger::log_meeting_joined_event($instance, 0); | ||
logger::log_recording_played_event($instance, $recordings[0]->id); | ||
[$logjoins, $logtimes] = user_info::get_user_info_outline($this->get_course(), $user, $bbactivitycm); | ||
$this->assertEquals([ | ||
'Has joined the room 1 time(s)', | ||
'Has played a recording 1 time(s)' | ||
], $logjoins); | ||
$this->assertCount(2, $logtimes); | ||
} | ||
/** | ||
* Test user info outline with several logs | ||
* | ||
* @return void | ||
*/ | ||
public function test_get_user_info_outline_several_logs() { | ||
$this->resetAfterTest(); | ||
|
||
$generator = $this->getDataGenerator(); | ||
$user = $generator->create_and_enrol($this->get_course()); | ||
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(); | ||
$this->setUser($user); | ||
|
||
// Now create a couple of logs. | ||
$instance = instance::get_from_instanceid($bbactivity->id); | ||
logger::log_meeting_joined_event($instance, 0); | ||
logger::log_meeting_joined_event($instance, 0); | ||
|
||
[$logjoins, $logtimes] = user_info::get_user_info_outline($this->get_course(), $user, $bbactivitycm); | ||
$this->assertEquals([ | ||
'Has joined the room 2 time(s)', | ||
], $logjoins); | ||
$this->assertCount(1, $logtimes); | ||
} | ||
} |