Skip to content

Commit

Permalink
Merge pull request #347 from Opencast-Moodle/update/403
Browse files Browse the repository at this point in the history
Update for Moodle 4.3
  • Loading branch information
justusdieckmann authored Nov 15, 2023
2 parents d608ec2 + bfeacf1 commit 4f3a315
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 54 deletions.
19 changes: 13 additions & 6 deletions classes/local/activitymodulemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static function create_module_for_series($courseid, $ocinstanceid, $title
}

// Create an LTI modinfo object.
$moduleinfo = self::build_activity_modinfo($pluginid, $ocinstanceid, $title, $sectionid, $seriesid, opencasttype::SERIES,
$introtext, $introformat, $availability, $allowdownload);
$moduleinfo = self::build_activity_modinfo($pluginid, $course, $ocinstanceid, $title, $sectionid, $seriesid,
opencasttype::SERIES, $introtext, $introformat, $availability, $allowdownload);

// Add the Opencast Activity series module to the given course.
// This does not check any capabilities to add modules to courses by purpose.
Expand Down Expand Up @@ -158,7 +158,7 @@ public static function create_module_for_episode($courseid, $ocinstanceid, $titl
}

// Create an Opencast Activity modinfo object.
$moduleinfo = self::build_activity_modinfo($pluginid, $ocinstanceid, $title, $sectionid, $episodeuuid,
$moduleinfo = self::build_activity_modinfo($pluginid, $course, $ocinstanceid, $title, $sectionid, $episodeuuid,
opencasttype::EPISODE, $introtext, $introformat, $availability, $allowdownload);

// Add the Opencast Activity episode module to the given course.
Expand All @@ -172,6 +172,7 @@ public static function create_module_for_episode($courseid, $ocinstanceid, $titl
* Helperfunction to create a modinfo class, holding the Opencast LTI module information.
*
* @param int $pluginid
* @param \stdClass $course
* @param int $ocinstanceid Opencast instance id
* @param string $title
* @param int $sectionid
Expand All @@ -184,10 +185,10 @@ public static function create_module_for_episode($courseid, $ocinstanceid, $titl
*
* @return object
*/
public static function build_activity_modinfo($pluginid, $ocinstanceid, $title, $sectionid, $opencastid, $type,
public static function build_activity_modinfo($pluginid, $course, $ocinstanceid, $title, $sectionid, $opencastid, $type,
$introtext = '', $introformat = FORMAT_HTML, $availability = null,
$allowdownload = false) {
global $CFG;
global $DB;

// Create standard class object.
$moduleinfo = new \stdClass();
Expand All @@ -211,13 +212,19 @@ public static function build_activity_modinfo($pluginid, $ocinstanceid, $title,
$moduleinfo->groupmode = NOGROUPS;
$moduleinfo->groupingid = 0;
$moduleinfo->availability = $availability;
$moduleinfo->completion = $CFG->completiondefault;

// Populate the modinfo object with opencast activity specific parameters.
$moduleinfo->type = $type;
$moduleinfo->opencastid = $opencastid;
$moduleinfo->ocinstanceid = $ocinstanceid;

// Apply completion defaults.
$module = $DB->get_record('modules', array('name' => 'opencast'), '*', MUST_EXIST);
$defaults = \core_completion\manager::get_default_completion($course, $module);
foreach ($defaults as $key => $value) {
$moduleinfo->$key = $value;
}

// Return modinfo.
return $moduleinfo;
}
Expand Down
21 changes: 14 additions & 7 deletions classes/local/ltimodulemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ public static function create_module_for_series($ocinstanceid, $courseid, $title
}

// Create an LTI modinfo object.
$moduleinfo = self::build_lti_modinfo($pluginid, $title, $sectionid, $toolid, 'series=' . $seriesid, $introtext,
$introformat, $availability);
$moduleinfo = self::build_lti_modinfo($pluginid, $course, $title, $sectionid, $toolid, 'series=' . $seriesid,
$introtext, $introformat, $availability);

// Add the LTI series module to the given course (this doesn't check any capabilities to add modules to courses by purpose).
$modulecreated = \add_moduleinfo($moduleinfo, $course);
Expand Down Expand Up @@ -376,7 +376,7 @@ public static function create_module_for_episode($ocinstanceid, $courseid, $titl
}

// Create an LTI modinfo object.
$moduleinfo = self::build_lti_modinfo($pluginid, $title, $sectionid, $toolid, 'id=' . $episodeuuid, $introtext,
$moduleinfo = self::build_lti_modinfo($pluginid, $course, $title, $sectionid, $toolid, 'id=' . $episodeuuid, $introtext,
$introformat, $availability);

// Add the LTI episode module to the given course. This doesn't check any capabilities to add modules to courses by purpose.
Expand All @@ -397,6 +397,7 @@ public static function create_module_for_episode($ocinstanceid, $courseid, $titl
* Helperfunction to create a modinfo class, holding the Opencast LTI module information.
*
* @param int $pluginid
* @param \stdClass $course
* @param string $title
* @param int $sectionid
* @param int $toolid
Expand All @@ -407,9 +408,9 @@ public static function create_module_for_episode($ocinstanceid, $courseid, $titl
*
* @return object
*/
public static function build_lti_modinfo($pluginid, $title, $sectionid, $toolid, $instructorcustomparameters, $introtext = '',
$introformat = FORMAT_HTML, $availability = null) {
global $CFG;
public static function build_lti_modinfo($pluginid, $course, $title, $sectionid, $toolid, $instructorcustomparameters,
$introtext = '', $introformat = FORMAT_HTML, $availability = null) {
global $DB;

// Create standard class object.
$moduleinfo = new \stdClass();
Expand All @@ -432,7 +433,13 @@ public static function build_lti_modinfo($pluginid, $title, $sectionid, $toolid,
$moduleinfo->groupmode = NOGROUPS;
$moduleinfo->groupingid = 0;
$moduleinfo->availability = $availability;
$moduleinfo->completion = $CFG->completiondefault;

// Apply completion defaults.
$module = $DB->get_record('modules', array('name' => 'opencast'), '*', MUST_EXIST);
$defaults = \core_completion\manager::get_default_completion($course, $module);
foreach ($defaults as $key => $value) {
$moduleinfo->$key = $value;
}

// Populate the modinfo object with LTI specific parameters.
$moduleinfo->typeid = $toolid;
Expand Down
23 changes: 11 additions & 12 deletions classes/setting_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,26 @@ class setting_helper {
* @throws \coding_exception
*/
public static function validate_workflow_setting($data) {
if ($data == null) {
return false;
}

// Hack to get the opencast instance id.
$category = optional_param('category', null, PARAM_RAW);
if ($category) {
$ocinstanceid = intval(ltrim($category, 'block_opencast_instance_'));
$ocinstanceid = intval(str_replace('block_opencast_instance_', '', $category));
} else {
$section = optional_param('section', null, PARAM_RAW);
$ocinstanceid = intval(ltrim($section, 'block_opencast_importvideossettings_'));
$ocinstanceid = intval(str_replace('block_opencast_importvideossettings_', '', $section));
}

// Do only if a workflow was set.
if ($data != null) {
// Get an APIbridge instance.
$apibridge = \block_opencast\local\apibridge::get_instance($ocinstanceid);
// Get an APIbridge instance.
$apibridge = \block_opencast\local\apibridge::get_instance($ocinstanceid);

// Verify if the given value is a valid Opencast workflow.
if (!$apibridge->check_if_workflow_exists($data)) {
return get_string('workflow_not_existing', 'block_opencast');
}
return false;
// Verify if the given value is a valid Opencast workflow.
if (!$apibridge->check_if_workflow_exists($data)) {
return get_string('workflow_not_existing', 'block_opencast');
}

return false;
}

Expand Down
43 changes: 34 additions & 9 deletions tests/behat/behat_block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,41 @@ public function i_should_watch_the_video_in_opencast() {
}

/**
* adds a breakpoints
* stops the execution until you hit enter in the console
* @Then /^breakpoint in ocblock/
* Checks whether the given lti tool has the given custom parameter.
*
* @Then /^the lti tool "([^"]*)" should have the custom parameter "([^"]*)"$/
*
* @param string $ltitoolname
* @param string $customparameter
*/
public function breakpoint_in_ocblock() {
fwrite(STDOUT, "\033[s \033[93m[Breakpoint] Press \033[1;93m[RETURN]\033[0;93m to continue...\033[0m");
while (fgets(STDIN, 1024) == '') {
continue;
public function the_lti_tool_should_have_the_custom_parameter($ltitoolname, $customparameter) {
global $DB;

$ltitool = $DB->get_record('lti', ['name' => $ltitoolname]);
if ($ltitool->instructorcustomparameters !== $customparameter) {
throw new ExpectationException("$ltitoolname has custom parameter \"$ltitool->instructorcustomparameters\"" .
" instead of expected \"$customparameter\"", $this->getSession());
}
}

/**
* Checks whether the given lti tool has the given custom parameter.
*
* @Then /^the lti tool "([^"]*)" in the course "([^"]*)" should have the custom parameter "([^"]*)"$/
*
* @param string $ltitoolname
* @param string $course
* @param string $customparameter
*/
public function the_lti_tool_in_the_course_should_have_the_custom_parameter($ltitoolname, $course, $customparameter) {
global $DB;

$cid = $this->get_course_id($course);

$ltitool = $DB->get_record('lti', ['name' => $ltitoolname, 'course' => $cid]);
if ($ltitool->instructorcustomparameters !== $customparameter) {
throw new ExpectationException("$ltitoolname has custom parameter \"$ltitool->instructorcustomparameters\"".
" instead of expected \"$customparameter\"", $this->getSession());
}
fwrite(STDOUT, "\033[u");
return;
}
}
6 changes: 1 addition & 5 deletions tests/behat/block_opencast_addlti.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ Feature: Add Opencast LTI series module as Teacher
Then I should see "Course 1" in the "#page-header" "css_element"
And I should see "The 'Opencast videos' series module has been added to this course."
And I should see "Opencast videos" in the "li.activity" "css_element"
And I am on "Course 1" course homepage with editing mode on
And I open "Opencast videos" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Preconfigured tool" matches value "Opencast series"
# Now, the field "Custom parameters" should also contain the Opencast series ID, but we can't test that with Behat
And the lti tool "Opencast videos" should have the custom parameter "series=1234-1234-1234-1234-1234"
And I am on "Course 1" course homepage
And I click on "Go to overview..." "link"
Then "View Opencast LTI series module in course" "link" should exist
Expand Down
19 changes: 4 additions & 15 deletions tests/behat/block_opencast_cleanup_backup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ Feature: Restore courses as Teacher
And I click on "Add module and return to overview" "button"
And I click on "Add Opencast episode module to course" "link"
And I click on "Add module and return to course" "button"
And I open "Opencast videos" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Custom parameters" matches value "series=1234-1234-1234-1234-1234"
When I click on "Cancel" "button"
And I open "Test video" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Custom parameters" matches value "id=abcd-abcd-abcd-abcd"
When I click on "Cancel" "button"
Then the lti tool "Opencast videos" should have the custom parameter "series=1234-1234-1234-1234-1234"
And the lti tool "Test video" should have the custom parameter "id=abcd-abcd-abcd-abcd"
When I backup "Course 1" course using this options:
| Confirmation | Filename | test_backup.mbz |
| Schema | Include videos from Opencast instance Default in this course | 0 |
Expand All @@ -99,13 +93,8 @@ Feature: Restore courses as Teacher
Then I should see "The import of the selected videos into this course was scheduled"
And I run the scheduled task "\block_opencast\task\cleanup_imported_episodes_cron"
And I am on "Course 1 copy 1" course homepage with editing mode on
And I open "Opencast videos" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Custom parameters" matches value "series=84bab8de-5688-46a1-9af0-5ce9122eeb6a"
When I click on "Cancel" "button"
And I open "Test video" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Custom parameters" matches value "id=abcd-abcd-abcd-abcd"
Then the lti tool "Opencast videos" in the course "Course 1 copy 1" should have the custom parameter "series=84bab8de-5688-46a1-9af0-5ce9122eeb6a"
Then the lti tool "Test video" in the course "Course 1 copy 1" should have the custom parameter "id=abcd-abcd-abcd-abcd"
And I run all adhoc tasks
And the following config values are set as admin:
| config | value | plugin |
Expand Down

0 comments on commit 4f3a315

Please sign in to comment.