diff --git a/classes/local/activitymodulemanager.php b/classes/local/activitymodulemanager.php index 04e995be..b0380ff8 100644 --- a/classes/local/activitymodulemanager.php +++ b/classes/local/activitymodulemanager.php @@ -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. @@ -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. @@ -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 @@ -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(); @@ -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; } diff --git a/classes/local/ltimodulemanager.php b/classes/local/ltimodulemanager.php index 4fa6d78f..eeb17566 100644 --- a/classes/local/ltimodulemanager.php +++ b/classes/local/ltimodulemanager.php @@ -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); @@ -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. @@ -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 @@ -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(); @@ -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; diff --git a/classes/setting_helper.php b/classes/setting_helper.php index 973dbd00..d58578ea 100644 --- a/classes/setting_helper.php +++ b/classes/setting_helper.php @@ -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; }