mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-03-09 06:27:21 -04:00
wt
This commit is contained in:
@@ -58,7 +58,7 @@ if ($courseid && $courseid != SITEID) {
|
||||
$course = $SITE;
|
||||
}
|
||||
|
||||
// Get or create dummy activity for this course
|
||||
// Get or create the dummy activity (visible, non-stealth).
|
||||
try {
|
||||
$dummy_cmid = filter_mediacms_get_dummy_activity($courseid, $type->id);
|
||||
} catch (Exception $e) {
|
||||
@@ -68,11 +68,9 @@ try {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// Get the dummy activity instance from DB
|
||||
$cm = get_coursemodule_from_id('lti', $dummy_cmid, 0, false, MUST_EXIST);
|
||||
$cm = get_coursemodule_from_id('lti', $dummy_cmid, 0, false, MUST_EXIST);
|
||||
$instance = $DB->get_record('lti', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||
|
||||
// Override with our media token for THIS launch only (doesn't save to DB)
|
||||
$custom_params = ["media_friendly_token=" . $mediatoken];
|
||||
|
||||
// Add embed parameters if provided (check !== '' instead of !empty() because '0' is a valid value)
|
||||
|
||||
@@ -11,7 +11,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Find the first LTI activity for the MediaCMS tool in a course, or create a
|
||||
* hidden dummy one if none exists.
|
||||
* visible dummy one if none exists. Repairs any existing stealth/hidden activity.
|
||||
*
|
||||
* @param int $courseid
|
||||
* @param int $typeid LTI tool type ID
|
||||
@@ -28,40 +28,41 @@ function filter_mediacms_get_dummy_activity($courseid, $typeid) {
|
||||
AND m.name = 'lti'
|
||||
AND lti.typeid = :typeid
|
||||
AND cm.deletioninprogress = 0
|
||||
ORDER BY cm.visible DESC, cm.visibleoncoursepage DESC
|
||||
LIMIT 1";
|
||||
|
||||
$existing = $DB->get_record_sql($sql, ['courseid' => $courseid, 'typeid' => $typeid]);
|
||||
if ($existing) {
|
||||
$cm = get_coursemodule_from_id('lti', $existing->id, 0, false, IGNORE_MISSING);
|
||||
if ($cm && !$cm->visible) {
|
||||
if ($cm && (!$cm->visible || !$cm->visibleoncoursepage)) {
|
||||
// Repair hidden or stealth activity so students can access it via LTI flow.
|
||||
set_coursemodule_visible($existing->id, 1);
|
||||
}
|
||||
return $existing->id;
|
||||
}
|
||||
|
||||
// Create a stealth dummy activity (accessible but hidden from the course page).
|
||||
// Create a fully visible dummy activity.
|
||||
$moduleinfo = new stdClass();
|
||||
$moduleinfo->course = $courseid;
|
||||
$moduleinfo->module = $DB->get_field('modules', 'id', ['name' => 'lti']);
|
||||
$moduleinfo->modulename = 'lti';
|
||||
$moduleinfo->section = 0;
|
||||
$moduleinfo->visible = 1;
|
||||
$moduleinfo->visibleoncoursepage = 0;
|
||||
$moduleinfo->availability = null;
|
||||
$moduleinfo->showdescription = 0;
|
||||
$moduleinfo->name = 'MediaCMS Filter Launcher';
|
||||
$moduleinfo->intro = '';
|
||||
$moduleinfo->introformat = FORMAT_HTML;
|
||||
$moduleinfo->typeid = $typeid;
|
||||
$moduleinfo->course = $courseid;
|
||||
$moduleinfo->module = $DB->get_field('modules', 'id', ['name' => 'lti']);
|
||||
$moduleinfo->modulename = 'lti';
|
||||
$moduleinfo->section = 0;
|
||||
$moduleinfo->visible = 1;
|
||||
$moduleinfo->visibleoncoursepage = 1;
|
||||
$moduleinfo->availability = null;
|
||||
$moduleinfo->showdescription = 0;
|
||||
$moduleinfo->name = 'MediaCMS Filter Launcher';
|
||||
$moduleinfo->intro = '';
|
||||
$moduleinfo->introformat = FORMAT_HTML;
|
||||
$moduleinfo->typeid = $typeid;
|
||||
$moduleinfo->instructorchoiceacceptgrades = 0;
|
||||
$moduleinfo->grade = 0;
|
||||
$moduleinfo->grade = 0;
|
||||
$moduleinfo->instructorchoicesendname = 1;
|
||||
$moduleinfo->instructorchoicesendemailaddr = 1;
|
||||
$moduleinfo->launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
|
||||
$moduleinfo->launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
|
||||
$moduleinfo->instructorcustomparameters = '';
|
||||
|
||||
$result = add_moduleinfo($moduleinfo, get_course($courseid));
|
||||
set_coursemodule_visible($result->coursemodule, 1, 0);
|
||||
|
||||
return $result->coursemodule;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,21 @@ foreach ($enrolled_courses as $enrolled_course) {
|
||||
|
||||
$publishdata_b64 = base64_encode(json_encode($publish_data));
|
||||
|
||||
// Use a course the user is actually enrolled in so they have mod/lti:view during
|
||||
// the OIDC flow. Fall back to SITEID only for admins with no course enrolments.
|
||||
$launch_courseid = SITEID;
|
||||
$launch_course = $SITE;
|
||||
foreach ($enrolled_courses as $ec) {
|
||||
if ((int)$ec->id !== SITEID) {
|
||||
$launch_courseid = (int)$ec->id;
|
||||
$launch_course = get_course($launch_courseid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get or create the dummy activity (visible, non-stealth).
|
||||
try {
|
||||
$dummy_cmid = filter_mediacms_get_dummy_activity(SITEID, $type->id);
|
||||
$dummy_cmid = filter_mediacms_get_dummy_activity($launch_courseid, $type->id);
|
||||
} catch (Exception $e) {
|
||||
throw new moodle_exception('cannotcreatedummyactivity', 'filter_mediacms');
|
||||
}
|
||||
@@ -73,6 +86,6 @@ $instance->instructorcustomparameters = 'publishdata=' . $publishdata_b64;
|
||||
$instance->name = 'MediaCMS My Media';
|
||||
|
||||
$typeconfig = lti_get_type_type_config($type->id);
|
||||
$content = lti_initiate_login($SITE->id, $dummy_cmid, $instance, $typeconfig, null, $instance->name);
|
||||
$content = lti_initiate_login($launch_course->id, $dummy_cmid, $instance, $typeconfig, null, $instance->name);
|
||||
|
||||
echo $content;
|
||||
|
||||
@@ -27,11 +27,9 @@ echo $OUTPUT->header();
|
||||
$attr = [
|
||||
'id' => 'contentframe',
|
||||
'src' => (new moodle_url('/filter/mediacms/lti_launch.php'))->out(false),
|
||||
'width' => '100%',
|
||||
'height' => '600px',
|
||||
'allowfullscreen' => 'true',
|
||||
'allow' => 'autoplay *; fullscreen *; encrypted-media *; camera *; microphone *;',
|
||||
'style' => 'border:none;display:block;',
|
||||
'style' => 'border:none;display:block;width:100%;height:calc(100vh - 120px);',
|
||||
];
|
||||
echo html_writer::tag('iframe', '', $attr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user