first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\meeting;
/**
* External service to check whether a user can join a meeting.
*
* This is mainly used by the mobile application.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class can_join extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
]);
}
/**
* Updates a recording
*
* @param int $cmid the bigbluebuttonbn course module id
* @param null|int $groupid
* @return array (empty array for now)
* @throws \restricted_context_exception
*/
public static function execute(
int $cmid,
?int $groupid = 0
): array {
// Validate the cmid ID.
[
'cmid' => $cmid,
'groupid' => $groupid,
] = self::validate_parameters(self::execute_parameters(), [
'cmid' => $cmid,
'groupid' => $groupid,
]);
$result = [
'can_join' => false,
'cmid' => $cmid,
];
$instance = instance::get_from_cmid($cmid);
if (empty($instance)) {
return $result;
}
// Validate the groupid.
if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
throw new restricted_context_exception();
}
$instance->set_group_id($groupid);
self::validate_context($instance->get_context());
$meeting = new meeting($instance);
$result['can_join'] = $meeting->can_join();
return $result;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'can_join' => new external_value(PARAM_BOOL, 'Can join session'),
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
]);
}
}
@@ -0,0 +1,110 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
/**
* External service to validate completion.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_validate extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
]);
}
/**
* Mark activity as complete
*
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
* @return array (empty array for now)
*/
public static function execute(
int $bigbluebuttonbnid
): array {
// Validate the bigbluebuttonbnid ID.
[
'bigbluebuttonbnid' => $bigbluebuttonbnid,
] = self::validate_parameters(self::execute_parameters(), [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
]);
$result = ['warnings' => []];
// Fetch the session, features, and profile.
$instance = instance::get_from_instanceid($bigbluebuttonbnid);
if ($instance) {
$context = $instance->get_context();
// Validate that the user has access to this activity.
self::validate_context($context);
// Get list with all the users enrolled in the course.
[$sort, $sqlparams] = users_order_by_sql('u');
if (has_capability('moodle/course:update', $context)) {
$users = get_enrolled_users($context, 'mod/bigbluebuttonbn:view', 0, 'u.*', $sort);
foreach ($users as $user) {
// Enqueue a task for processing the completion.
bigbluebutton_proxy::enqueue_completion_event($instance->get_instance_data(), $user->id);
}
} else {
$result['warnings'][] = [
'item' => 'mod_bigbluebuttonbn',
'itemid' => $instance->get_instance_id(),
'warningcode' => 'nopermissions',
'message' => get_string('nopermissions', 'error', 'completion_validate')
];
}
} else {
$result['warnings'][] = [
'item' => 'mod_bigbluebuttonbn',
'itemid' => $bigbluebuttonbnid,
'warningcode' => 'indexerrorbbtn',
'message' => get_string('index_error_bbtn', 'mod_bigbluebuttonbn', $bigbluebuttonbnid)
];
}
// We might want to return a status here or some warnings.
return $result;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'warnings' => new external_warnings(),
]);
}
}
+126
View File
@@ -0,0 +1,126 @@
<?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\external;
use core\notification;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\meeting;
/**
* External service to end a meeting.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class end_meeting extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
]);
}
/**
* Updates a recording
*
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
* @param int $groupid the groupid (either 0 or the groupid)
* @return array (empty array for now)
* @throws \invalid_parameter_exception
* @throws \moodle_exception
* @throws restricted_context_exception
*/
public static function execute(
int $bigbluebuttonbnid,
int $groupid
): array {
// Validate the bigbluebuttonbnid ID.
[
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'groupid' => $groupid,
] = self::validate_parameters(self::execute_parameters(), [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'groupid' => $groupid,
]);
// Fetch the session, features, and profile.
$instance = instance::get_from_instanceid($bigbluebuttonbnid);
if (empty($instance)) {
throw new \moodle_exception('Unknown Instance');
}
if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
throw new restricted_context_exception();
}
$instance->set_group_id($groupid);
$context = $instance->get_context();
// Validate that the user has access to this activity and to manage recordings.
self::validate_context($context);
if (!$instance->user_can_end_meeting()) {
throw new restricted_context_exception();
}
// Execute the end command.
$meeting = new meeting($instance);
try {
$meeting->end_meeting();
} catch (bigbluebutton_exception $e) {
return [
'warnings' => [
[
'item' => $instance->get_meeting_name(),
'itemid' => $instance->get_instance_id(),
'warningcode' => 'notFound',
'message' => $e->getMessage()
]
]
];
}
logger::log_meeting_ended_event($instance);
// Update the cache.
$meeting->update_cache();
notification::add(get_string('end_session_notification', 'mod_bigbluebuttonbn'), notification::INFO);
return [];
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'warnings' => new external_warnings(),
]);
}
}
@@ -0,0 +1,115 @@
<?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\external;
use core_course\external\helper_for_get_mods_by_courses;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\util as external_util;
/**
* External service to get activity per course
*
* This is mainly used by the mobile application.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_bigbluebuttonbns_by_courses extends external_api {
/**
* Describes the parameters for get_bigbluebuttonbns_by_courses.
*
* @return external_function_parameters
* @since Moodle 3.11
*/
public static function execute_parameters() {
return new external_function_parameters([
'courseids' => new external_multiple_structure(
new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, []
),
]
);
}
/**
* Returns a list of bigbluebuttonbns in a provided list of courses.
* If no list is provided all bigbluebuttonbns that the user can view will be returned.
*
* @param array $courseids course ids
* @return array of warnings and bigbluebuttonbns
* @since Moodle 3.11
*/
public static function execute($courseids = []) {
global $USER;
$warnings = [];
$returnedbigbluebuttonbns = [];
['courseids' => $courseids] = self::validate_parameters(self::execute_parameters(), ['courseids' => $courseids]);
$mycourses = [];
if (empty($courseids)) {
$mycourses = enrol_get_my_courses();
$courseids = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
[$courses, $warnings] = external_util::validate_courses($courseids, $mycourses);
// Get the bigbluebuttonbns in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$bigbluebuttonbns = get_all_instances_in_courses("bigbluebuttonbn", $courses, $USER->id);
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
helper_for_get_mods_by_courses::format_name_and_intro($bigbluebuttonbn, 'mod_bigbluebuttonbn');
$returnedbigbluebuttonbns[] = $bigbluebuttonbn;
}
}
$result = [
'bigbluebuttonbns' => $returnedbigbluebuttonbns,
'warnings' => $warnings
];
return $result;
}
/**
* Describes the get_bigbluebuttonbns_by_courses return value.
*
* @return external_single_structure
* @since Moodle 3.11
*/
public static function execute_returns() {
return new external_single_structure([
'bigbluebuttonbns' => new external_multiple_structure(
new external_single_structure(array_merge(
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
[
'meetingid' => new external_value(PARAM_RAW, 'Meeting id'),
'timemodified' => new external_value(PARAM_INT, 'Last time the instance was modified'),
]
))
),
'warnings' => new external_warnings(),
]
);
}
}
+117
View File
@@ -0,0 +1,117 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\exceptions\meeting_join_exception;
use mod_bigbluebuttonbn\meeting;
/**
* External service to create the meeting (if needed), check user limit, and return the join URL when we can join.
*
* This is mainly used by the mobile application.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_join_url extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
]);
}
/**
* Updates a recording
*
* @param int $cmid the bigbluebuttonbn course module id
* @param null|int $groupid
* @return array (empty array for now)
*
* @throws restricted_context_exception
*/
public static function execute(
int $cmid,
?int $groupid = 0
): array {
// Validate the cmid ID.
[
'cmid' => $cmid,
'groupid' => $groupid,
] = self::validate_parameters(self::execute_parameters(), [
'cmid' => $cmid,
'groupid' => $groupid,
]);
$result = ['warnings' => []];
$instance = instance::get_from_cmid($cmid);
if (empty($instance)) {
throw new \moodle_exception('nosuchinstance', 'mod_bigbluebuttonbn', null,
['entity' => get_string('module', 'course'), 'id' => $cmid]);
}
// Validate the groupid.
if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
throw new restricted_context_exception();
}
$instance->set_group_id($groupid);
// Validate that the user has access to this activity and to join the meeting.
self::validate_context($instance->get_context());
if (!$instance->can_join()) {
throw new restricted_context_exception();
}
try {
$result['join_url'] = meeting::join_meeting($instance);
} catch (meeting_join_exception $e) {
$result['warnings'][] = [
'item' => 'mod_bigbluebuttonbn',
'itemid' => $instance->get_instance_id(),
'warningcode' => $e->errorcode,
'message' => $e->getMessage()
];
}
return $result;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'join_url' => new external_value(PARAM_RAW, 'Can join session', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
]);
}
}
+156
View File
@@ -0,0 +1,156 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
/**
* External service to fetch a list of recordings from the BBB service.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_recordings extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
'tools' => new external_value(PARAM_RAW, 'a set of enabled tools', VALUE_DEFAULT,
'protect,unprotect,publish,unpublish,delete'),
'groupid' => new external_value(PARAM_INT, 'Group ID', VALUE_DEFAULT, null),
]);
}
/**
* Get a list of recordings
*
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id to which the recordings are referred.
* @param string|null $tools
* @param int|null $groupid
* @return array of warnings and status result
* @throws \invalid_parameter_exception
* @throws restricted_context_exception
*/
public static function execute(
int $bigbluebuttonbnid = 0,
?string $tools = 'protect,unprotect,publish,unpublish,delete',
?int $groupid = null
): array {
global $USER;
$returnval = [
'status' => false,
'warnings' => [],
];
// Validate the bigbluebuttonbnid ID.
[
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'tools' => $tools,
'groupid' => $groupid,
] = self::validate_parameters(self::execute_parameters(), [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'tools' => $tools,
'groupid' => $groupid,
]);
$tools = explode(',', $tools ?? 'protect,unprotect,publish,unpublish,delete');
// Fetch the session, features, and profile.
$instance = instance::get_from_instanceid($bigbluebuttonbnid);
if (!$instance) {
$returnval['warnings'][] = [
'item' => $bigbluebuttonbnid,
'warningcode' => 'nosuchinstance',
'message' => get_string('nosuchinstance', 'mod_bigbluebuttonbn',
(object) ['id' => $bigbluebuttonbnid, 'entity' => 'bigbluebuttonbn'])
];
} else {
$typeprofiles = bigbluebutton_proxy::get_instance_type_profiles();
$profilefeature = $typeprofiles[$instance->get_type()]['features'];
$showrecordings = in_array('all', $profilefeature) || in_array('showrecordings', $profilefeature);
if ($showrecordings) {
$context = $instance->get_context();
// Validate that the user has access to this activity.
self::validate_context($context);
if (!$instance->user_has_group_access($USER, $groupid)) {
new restricted_context_exception();
}
if ($groupid) {
$instance->set_group_id($groupid);
}
$recordings = $instance->get_recordings([], $instance->get_instance_var('recordings_deleted') ?? false);
$tabledata = recording_data::get_recording_table($recordings, $tools, $instance);
$returnval['tabledata'] = $tabledata;
$returnval['status'] = true;
} else {
$returnval['warnings'][] = [
'item' => $bigbluebuttonbnid,
'warningcode' => 'instanceprofilewithoutrecordings',
'message' => get_string('instanceprofilewithoutrecordings', 'mod_bigbluebuttonbn')
];
}
}
return $returnval;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'Whether the fetch was successful'),
'tabledata' => new external_single_structure([
'activity' => new external_value(PARAM_ALPHANUMEXT),
'ping_interval' => new external_value(PARAM_INT),
'locale' => new external_value(PARAM_TEXT),
'profile_features' => new external_multiple_structure(new external_value(PARAM_TEXT)),
'columns' => new external_multiple_structure(new external_single_structure([
'key' => new external_value(PARAM_ALPHA),
'label' => new external_value(PARAM_TEXT),
'width' => new external_value(PARAM_ALPHANUMEXT),
// See https://datatables.net/reference/option/columns.type .
'type' => new external_value(PARAM_ALPHANUMEXT, 'Column type', VALUE_OPTIONAL),
'sortable' => new external_value(PARAM_BOOL, 'Whether this column is sortable', VALUE_OPTIONAL, false),
'allowHTML' => new external_value(PARAM_BOOL, 'Whether this column contains HTML', VALUE_OPTIONAL, false),
'formatter' => new external_value(PARAM_ALPHANUMEXT, 'Formatter name', VALUE_OPTIONAL),
])),
'data' => new external_value(PARAM_RAW), // For now it will be json encoded.
], '', VALUE_OPTIONAL),
'warnings' => new external_warnings()
]);
}
}
@@ -0,0 +1,203 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
use mod_bigbluebuttonbn\recording;
/**
* External service to fetch a list of recordings from the BBB service.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_recordings_to_import extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'destinationinstanceid' => new external_value(
PARAM_INT,
'Id of the other BBB we target for importing recordings into.
The idea here is to remove already imported recordings.',
VALUE_REQUIRED
),
'sourcebigbluebuttonbnid' => new external_value(PARAM_INT,
'bigbluebuttonbn instance id',
VALUE_DEFAULT,
0),
'sourcecourseid' => new external_value(PARAM_INT,
'source courseid to filter by',
VALUE_DEFAULT,
0),
'tools' => new external_value(PARAM_RAW, 'a set of enabled tools', VALUE_DEFAULT,
'protect,unprotect,publish,unpublish,delete'),
'groupid' => new external_value(PARAM_INT, 'Group ID', VALUE_DEFAULT, null),
]);
}
/**
* Get a list of recordings
*
* @param int $destinationinstanceid the bigbluebuttonbn instance id where recordings have been already imported.
* @param int|null $sourcebigbluebuttonbnid the bigbluebuttonbn instance id to which the recordings are referred.
* @param int|null $sourcecourseid the source courseid to filter by
* @param string|null $tools
* @param int|null $groupid
* @return array of warnings and status result
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function execute(
int $destinationinstanceid,
?int $sourcebigbluebuttonbnid = 0,
?int $sourcecourseid = 0,
?string $tools = 'protect,unprotect,publish,unpublish,delete',
?int $groupid = null
): array {
global $USER, $DB;
$returnval = [
'status' => false,
'warnings' => [],
];
// Validate the sourcebigbluebuttonbnid ID.
[
'destinationinstanceid' => $destinationinstanceid,
'sourcebigbluebuttonbnid' => $sourcebigbluebuttonbnid,
'sourcecourseid' => $sourcecourseid,
'tools' => $tools,
'groupid' => $groupid
] = self::validate_parameters(self::execute_parameters(), [
'destinationinstanceid' => $destinationinstanceid,
'sourcebigbluebuttonbnid' => $sourcebigbluebuttonbnid,
'sourcecourseid' => $sourcecourseid,
'tools' => $tools,
'groupid' => $groupid
]);
$tools = explode(',', $tools ?? 'protect,unprotect,publish,unpublish,delete');
// Fetch the session, features, and profile.
$sourceinstance = null;
$sourcecourse = null;
if ($sourcecourseid) {
$sourcecourse = $DB->get_record('course', ['id' => $sourcecourseid], '*', MUST_EXIST);
}
if (!empty($sourcebigbluebuttonbnid)) {
$sourceinstance = instance::get_from_instanceid($sourcebigbluebuttonbnid);
if (!$sourceinstance) {
throw new \invalid_parameter_exception('Source Bigbluebutton Id is invalid');
}
$sourcecourse = $sourceinstance->get_course();
// Validate that the user has access to this activity.
self::validate_context($sourceinstance->get_context());
}
$destinstance = instance::get_from_instanceid($destinationinstanceid);
// Validate that the user has access to this activity.
self::validate_context($destinstance->get_context());
if (!$destinstance->user_has_group_access($USER, $groupid)) {
throw new \invalid_parameter_exception('Invalid group for this user ' . $groupid);
}
if ($groupid) {
$destinstance->set_group_id($groupid);
}
// Exclude itself from the list if in import mode.
$excludedids = [$destinstance->get_instance_id()];
if ($sourceinstance) {
$recordings = $sourceinstance->get_recordings($excludedids);
} else {
// There is a course id or a 0, so we fetch all recording including deleted recordings from this course.
$recordings = recording::get_recordings_for_course(
$sourcecourseid,
$excludedids,
true,
false,
($sourcecourseid == 0 || $sourcebigbluebuttonbnid == 0),
($sourcecourseid == 0 || $sourcebigbluebuttonbnid == 0)
);
}
if ($destinationinstanceid) {
// Remove recording already imported in this specific activity.
$destinationinstance = instance::get_from_instanceid($destinationinstanceid);
$importedrecordings = recording::get_recordings_for_instance(
$destinationinstance,
true,
true
);
// Unset from $recordings if recording is already imported.
// Recording $recordings are indexed by $id (moodle table column id).
foreach ($recordings as $index => $recording) {
foreach ($importedrecordings as $irecord) {
if ($irecord->get('recordingid') == $recording->get('recordingid')) {
unset($recordings[$index]);
}
}
}
}
$tabledata = recording_data::get_recording_table($recordings, $tools, $sourceinstance, $sourcecourseid);
$returnval['tabledata'] = $tabledata;
$returnval['status'] = true;
return $returnval;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'Whether the fetch was successful'),
'tabledata' => new external_single_structure([
'activity' => new external_value(PARAM_ALPHANUMEXT),
'ping_interval' => new external_value(PARAM_INT),
'locale' => new external_value(PARAM_TEXT),
'profile_features' => new external_multiple_structure(new external_value(PARAM_TEXT)),
'columns' => new external_multiple_structure(new external_single_structure([
'key' => new external_value(PARAM_ALPHA),
'label' => new external_value(PARAM_TEXT),
'width' => new external_value(PARAM_ALPHANUMEXT),
// See https://datatables.net/reference/option/columns.type .
'type' => new external_value(PARAM_ALPHANUMEXT, 'Column type', VALUE_OPTIONAL),
'sortable' => new external_value(PARAM_BOOL, 'Whether this column is sortable', VALUE_OPTIONAL, false),
'allowHTML' => new external_value(PARAM_BOOL, 'Whether this column contains HTML', VALUE_OPTIONAL, false),
'formatter' => new external_value(PARAM_ALPHANUMEXT, 'Formatter name', VALUE_OPTIONAL),
])),
'data' => new external_value(PARAM_RAW), // For now it will be json encoded.
], '', VALUE_OPTIONAL),
'warnings' => new external_warnings()
]);
}
}
+152
View File
@@ -0,0 +1,152 @@
<?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\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
use mod_bigbluebuttonbn\meeting;
/**
* External service to fetch meeting information.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class meeting_info extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
'updatecache' => new external_value(PARAM_BOOL, 'update cache ?', VALUE_DEFAULT, false),
]);
}
/**
* Fetch meeting information.
*
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
* @param int $groupid
* @param bool $updatecache
* @return array
* @throws \moodle_exception
* @throws restricted_context_exception
*/
public static function execute(
int $bigbluebuttonbnid,
int $groupid,
bool $updatecache = false
): array {
// Validate the bigbluebuttonbnid ID.
[
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'groupid' => $groupid,
'updatecache' => $updatecache,
] = self::validate_parameters(self::execute_parameters(), [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'groupid' => $groupid,
'updatecache' => $updatecache,
]);
// Fetch the session, features, and profile.
$instance = instance::get_from_instanceid($bigbluebuttonbnid);
$instance->set_group_id($groupid);
if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
throw new restricted_context_exception();
}
$context = $instance->get_context();
// Validate that the user has access to this activity and to manage recordings.
self::validate_context($context);
// Check if the BBB server is working.
$serverversion = bigbluebutton_proxy::get_server_version();
if ($serverversion === null) {
throw new \moodle_exception('general_error_no_answer', 'mod_bigbluebuttonbn',
bigbluebutton_proxy::get_server_not_available_url($instance),
bigbluebutton_proxy::get_server_not_available_message($instance));
}
$meetinginfo = (array) meeting::get_meeting_info_for_instance($instance, $updatecache);
// Make the structure WS friendly.
array_walk($meetinginfo['features'], function(&$value, $key){
$value = ['name' => $key, 'isenabled' => (bool) $value];
});
return $meetinginfo;
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'cmid' => new external_value(PARAM_INT, 'CM id'),
'userlimit' => new external_value(PARAM_INT, 'User limit'),
'bigbluebuttonbnid' => new external_value(PARAM_RAW, 'bigbluebuttonbn instance id'),
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
'meetingid' => new external_value(PARAM_RAW, 'Meeting id'),
'openingtime' => new external_value(PARAM_INT, 'Opening time', VALUE_OPTIONAL),
'closingtime' => new external_value(PARAM_INT, 'Closing time', VALUE_OPTIONAL),
'statusrunning' => new external_value(PARAM_BOOL, 'Status running', VALUE_OPTIONAL),
'statusclosed' => new external_value(PARAM_BOOL, 'Status closed', VALUE_OPTIONAL),
'statusopen' => new external_value(PARAM_BOOL, 'Status open', VALUE_OPTIONAL),
'statusmessage' => new external_value(PARAM_TEXT, 'Status message', VALUE_OPTIONAL),
'startedat' => new external_value(PARAM_INT, 'Started at', VALUE_OPTIONAL),
'moderatorcount' => new external_value(PARAM_INT, 'Moderator count', VALUE_OPTIONAL),
'participantcount' => new external_value(PARAM_INT, 'Participant count', VALUE_OPTIONAL),
'moderatorplural' => new external_value(PARAM_BOOL, 'Several moderators ?', VALUE_OPTIONAL),
'participantplural' => new external_value(PARAM_BOOL, 'Several participants ?', VALUE_OPTIONAL),
'canjoin' => new external_value(PARAM_BOOL, 'Can join'),
'ismoderator' => new external_value(PARAM_BOOL, 'Is moderator'),
'presentations' => new external_multiple_structure(
new external_single_structure([
'url' => new external_value(PARAM_URL, 'presentation URL'),
'iconname' => new external_value(PARAM_RAW, 'icon name'),
'icondesc' => new external_value(PARAM_TEXT, 'icon text'),
'name' => new external_value(PARAM_TEXT, 'presentation name'),
])
),
'joinurl' => new external_value(PARAM_URL, 'Join URL'),
'guestaccessenabled' => new external_value(PARAM_BOOL, 'Guest access enabled', VALUE_OPTIONAL),
'guestjoinurl' => new external_value(PARAM_URL, 'Guest URL', VALUE_OPTIONAL),
'guestpassword' => new external_value(PARAM_RAW, 'Guest join password', VALUE_OPTIONAL),
'features' => new external_multiple_structure(
new external_single_structure([
'name' => new external_value(PARAM_ALPHA, 'Feature name.'),
'isenabled' => new external_value(PARAM_BOOL, 'Whether the feature is enabled.'),
]), 'List of features for the instance', VALUE_OPTIONAL
),
]
);
}
}
@@ -0,0 +1,134 @@
<?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\external;
use coding_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_action;
use mod_bigbluebuttonbn\recording;
/**
* External service to update the details of one recording.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class update_recording extends external_api {
/**
* Updates a recording
*
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id, either the same as the one set in the recording or a new
* instance to import the recording into.
* @param int $recordingid
* @param string $action
* @param string|null $additionaloptions
* @return array (empty array for now)
*/
public static function execute(
int $bigbluebuttonbnid,
int $recordingid,
string $action,
string $additionaloptions = null
): array {
// Validate the bigbluebuttonbnid ID.
[
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'recordingid' => $recordingid,
'action' => $action,
'additionaloptions' => $additionaloptions,
] = self::validate_parameters(self::execute_parameters(), [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
'recordingid' => $recordingid,
'action' => $action,
'additionaloptions' => $additionaloptions,
]);
switch ($action) {
case 'delete':
case 'edit':
case 'protect':
case 'publish':
case 'unprotect':
case 'unpublish':
case 'import':
break;
default:
throw new coding_exception("Unknown action '{$action}'");
}
$instance = instance::get_from_instanceid($bigbluebuttonbnid);
$recordingcontext = $instance->get_context();
self::validate_context($recordingcontext);
require_capability('mod/bigbluebuttonbn:managerecordings', $recordingcontext);
require_capability("mod/bigbluebuttonbn:{$action}recordings", $recordingcontext);
// Fetch the session, features, and profile.
$recording = new recording($recordingid);
// Check both the recording instance context and the bbb context.
$relatedinstance = instance::get_from_instanceid($recording->get('bigbluebuttonbnid'));
if ($relatedinstance) {
$recordingcontext = $relatedinstance->get_context();
// Validate that the user has access to this activity and to manage recordings.
self::validate_context($recordingcontext);
require_capability('mod/bigbluebuttonbn:managerecordings', $recordingcontext);
require_capability("mod/bigbluebuttonbn:{$action}recordings", $recordingcontext);
}
$additionaloptionsobject = $additionaloptions ? json_decode($additionaloptions) : null;
// Specific action such as import, delete, publish, unpublish, edit,....
if (method_exists(recording_action::class, "$action")) {
forward_static_call(
['\mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_action', "$action"],
$recording,
$instance,
$additionaloptionsobject
);
}
return [];
}
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(
PARAM_INT,
'bigbluebuttonbn instance id, this might be a different one from the one set in recordingid in case of importing'
),
'recordingid' => new external_value(PARAM_INT, 'The moodle internal recording ID'),
'action' => new external_value(PARAM_ALPHANUMEXT, 'The action to perform'),
'additionaloptions' => new external_value(PARAM_RAW, 'Additional options', VALUE_REQUIRED, null),
]);
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
* @since Moodle 3.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([]);
}
}
@@ -0,0 +1,108 @@
<?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\external;
use context_module;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
/**
* External service to trigger the course module viewed event and update the module completion status
*
* This is mainly used by the mobile application.
*
* @package mod_bigbluebuttonbn
* @category external
* @copyright 2018 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class view_bigbluebuttonbn extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.0
*/
public static function execute_parameters() {
return new external_function_parameters([
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
]
);
}
/**
* Trigger the course module viewed event and update the module completion status.
*
* @param int $instanceid the bigbluebuttonbn instance id
* @return array of warnings and status result
* @since Moodle 3.0
*/
public static function execute($instanceid) {
global $CFG;
require_once($CFG->dirroot . "/mod/bigbluebuttonbn/lib.php");
['bigbluebuttonbnid' => $instanceid] = self::validate_parameters(
self::execute_parameters(),
['bigbluebuttonbnid' => $instanceid]
);
$instance = instance::get_from_instanceid($instanceid);
if (empty($instance)) {
return [
'status' => false,
'warnings' => [
[
'item' => 'mod_bigbluebuttonbn',
'itemid' => 0,
'warningcode' => 'nosuchinstance',
'message' => get_string('nosuchinstance', 'mod_bigbluebuttonbn',
(object) ['id' => $instanceid, 'entity' => 'bigbluebuttonbn'])
]
]
];
}
$context = context_module::instance($instance->get_cm_id());
self::validate_context($context);
require_capability('mod/bigbluebuttonbn:view', $context);
// Call the bigbluebuttonbn/lib API.
bigbluebuttonbn_view($instance->get_instance_data(), $instance->get_course(), $instance->get_cm(), $context);
return [
'status' => true,
'warnings' => []
];
}
/**
* Returns description of method result value
*
* @return \core_external\external_description
* @since Moodle 3.0
*/
public static function execute_returns() {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'warnings' => new external_warnings()
]
);
}
}