diff --git a/SSO.php b/SSO.php index e0acf77..51fb146 100644 --- a/SSO.php +++ b/SSO.php @@ -93,10 +93,10 @@ $targetserver->name = $servername; $targetserver->appkey = panopto_get_app_key($servername); - $ssosynctask->set_custom_data(array( + $ssosynctask->set_custom_data([ 'userid' => $USER->id, 'targetserver' => $targetserver - )); + ]); switch ($selectedssotype) { case 'sync': diff --git a/block_panopto.php b/block_panopto.php index 10fa0b2..7e40e3e 100644 --- a/block_panopto.php +++ b/block_panopto.php @@ -78,8 +78,8 @@ public function instance_allow_config() { public function instance_config_save($data, $nolongerused = false) { // Add roles mapping. - $publisherroles = (isset($data->publisher)) ? $data->publisher : array(); - $creatorroles = (isset($data->creator)) ? $data->creator : array(); + $publisherroles = (isset($data->publisher)) ? $data->publisher : []; + $creatorroles = (isset($data->creator)) ? $data->creator : []; // Get the current role mappings set for the current course from the db. $mappings = \panopto_data::get_course_role_mappings($this->page->course->id); @@ -154,11 +154,11 @@ public function get_content() { $this->content->text = ''; $this->content->footer = ''; - $params = array('id' => self::CONTENTID, 'courseid' => $COURSE->id); + $params = ['id' => self::CONTENTID, 'courseid' => $COURSE->id]; $this->page->requires->yui_module('moodle-block_panopto-asyncload', 'M.block_panopto.asyncload.init', - array($params), + [$params], null, true); @@ -212,7 +212,7 @@ public function get_content() { public function applicable_formats() { // Since block is dealing with courses and enrollment's the only possible. // place where Panopto block can be used is the course. - return array('course-view' => true); + return ['course-view' => true]; } /** diff --git a/build_category_structure.php b/build_category_structure.php index 965c19d..c0f650b 100644 --- a/build_category_structure.php +++ b/build_category_structure.php @@ -35,8 +35,8 @@ require_once(dirname(__FILE__) . '/lib/panopto_category_data.php'); // Populate list of servernames to select from. -$aserverarray = array(); -$appkeyarray = array(); +$aserverarray = []; +$appkeyarray = []; $numservers = get_config('block_panopto', 'server_number'); $numservers = isset($numservers) ? $numservers : 0; diff --git a/classes/categorytasks.php b/classes/categorytasks.php index 56afa0d..c2edbf4 100644 --- a/classes/categorytasks.php +++ b/classes/categorytasks.php @@ -56,9 +56,9 @@ public static function coursecategorycreated(\core\event\course_category_created if (get_config('block_panopto', 'enforce_category_structure')) { $task = new \block_panopto\task\ensure_category(); - $task->set_custom_data(array( + $task->set_custom_data([ 'categoryid' => $event->contextinstanceid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -82,9 +82,9 @@ public static function coursecategoryupdated(\core\event\course_category_updated if (get_config('block_panopto', 'enforce_category_structure')) { $task = new \block_panopto\task\ensure_category(); - $task->set_custom_data(array( + $task->set_custom_data([ 'categoryid' => $event->contextinstanceid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); diff --git a/classes/panopto_provision_form.php b/classes/panopto_provision_form.php index 10c84b2..b12d6ce 100644 --- a/classes/panopto_provision_form.php +++ b/classes/panopto_provision_form.php @@ -48,7 +48,7 @@ public function definition() { $mform = & $this->_form; $selectquery = 'id <> 1'; $coursesraw = $DB->get_records_select('course', $selectquery, null, 'id, shortname, fullname'); - $courses = array(); + $courses = []; if ($coursesraw) { foreach ($coursesraw as $course) { $courses[$course->id] = $course->shortname . ': ' . $course->fullname; diff --git a/classes/panopto_unprovision_form.php b/classes/panopto_unprovision_form.php index 6475c5a..0443be5 100644 --- a/classes/panopto_unprovision_form.php +++ b/classes/panopto_unprovision_form.php @@ -46,7 +46,7 @@ public function definition() { $coursesraw = $DB->get_records_sql( 'SELECT id, shortname, fullname FROM {course} WHERE id IN (SELECT moodleid FROM {block_panopto_foldermap})' ); - $courses = array(); + $courses = []; if ($coursesraw) { foreach ($coursesraw as $course) { $courses[$course->id] = $course->shortname . ': ' . $course->fullname; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index b550e82..68263f1 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -123,7 +123,7 @@ public static function get_users_in_context(\core_privacy\local\request\userlist } $enrolledusers = \get_enrolled_users($context); - $enrolleduserids = array(); + $enrolleduserids = []; foreach ($enrolledusers as $user) { $enrolleduserids[] = $user->id; } @@ -155,7 +155,7 @@ public static function export_user_data(\core_privacy\local\request\approved_con \panopto_user_info_valid($panoptouser->FirstName) && \panopto_user_info_valid($panoptouser->LastName) && \panopto_user_info_valid($panoptouser->Email)) { - $subcontext = array(); + $subcontext = []; $subcontext[] = \get_string('pluginname', 'block_panopto'); $subcontext[] = $currentpanopto->servername; @@ -184,7 +184,7 @@ public static function delete_data_for_users(\core_privacy\local\request\approve $currentpanopto->servername = $panoptoserver->name; $currentpanopto->applicationkey = $panoptoserver->appkey; - $userids = array(); + $userids = []; foreach ($targetusers as $targetuser) { // Search for user in panopto, if they exist then export the below data, if they do not exist then skip. $panoptouser = $currentpanopto->get_user_by_key($instancename . '\\' . $targetuser->username); diff --git a/classes/rollingsync.php b/classes/rollingsync.php index 6baf6a8..42a17dd 100644 --- a/classes/rollingsync.php +++ b/classes/rollingsync.php @@ -67,7 +67,7 @@ public static function coursecreated(\core\event\course_created $event) { if (!empty($tool)) { // Default intro should be a folderview. $draftideditor = file_get_submitted_draft_itemid('introeditor'); - file_prepare_draft_area($draftideditor, null, null, null, null, array('subdirs' => true)); + file_prepare_draft_area($draftideditor, null, null, null, null, ['subdirs' => true]); $moduleinfo = new stdClass(); $moduleinfo->modulename = 'lti'; @@ -82,13 +82,13 @@ public static function coursecreated(\core\event\course_created $event) { $moduleinfo->visible = true; $moduleinfo->intro = ''; $moduleinfo->icon = 'https://static-contents.panopto.com/prod/panopto_logo_moodle_tool_60x60.png'; - $moduleinfo->introeditor = array('text' => $moduleinfo->intro, 'format' => FORMAT_HTML, 'itemid' => $draftideditor); + $moduleinfo->introeditor = ['text' => $moduleinfo->intro, 'format' => FORMAT_HTML, 'itemid' => $draftideditor]; create_module($moduleinfo); } } if (get_config('block_panopto', 'auto_add_block_to_new_courses')) { - $course = $DB->get_record('course', array('id' => $event->courseid)); + $course = $DB->get_record('course', ['id' => $event->courseid]); if ($event->courseid == SITEID) { $pagetypepattern = 'site-index'; @@ -98,7 +98,7 @@ public static function coursecreated(\core\event\course_created $event) { $page = new moodle_page(); $page->set_course($course); - $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('panopto')), $pagetypepattern); + $page->blocks->add_blocks([BLOCK_POS_LEFT => ['panopto']], $pagetypepattern); } if (!\panopto_data::is_main_block_configured() || @@ -110,12 +110,12 @@ public static function coursecreated(\core\event\course_created $event) { if ($allowautoprovision == 'oncoursecreation') { $task = new \block_panopto\task\provision_course(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $event->courseid, 'relateduserid' => $event->relateduserid, 'contextid' => $event->contextid, 'eventtype' => 'role' - )); + ]); $task->execute(); } } @@ -155,23 +155,64 @@ public static function courserestored(\core\event\course_restored $event) { return; } + // Which course or courses to provision. + $provisionduringcopy = get_config('block_panopto', 'provisioning_during_copy'); + $panoptodata = new \panopto_data($newcourseid); $originalpanoptodata = new \panopto_data($originalcourseid); + // This is target or course where we are doing copy or import. $istargetcourseprovisioned = isset($panoptodata->servername) && !empty($panoptodata->servername) && isset($panoptodata->applicationkey) && !empty($panoptodata->applicationkey) && isset($panoptodata->sessiongroupid) && !empty($panoptodata->sessiongroupid); + // This is course which we are copying or importing. $isoriginalcourseprovisioned = isset($originalpanoptodata->servername) && !empty($originalpanoptodata->servername) && isset($originalpanoptodata->applicationkey) && !empty($originalpanoptodata->applicationkey) && isset($originalpanoptodata->sessiongroupid) && !empty($originalpanoptodata->sessiongroupid); - // If any is provisioned, check if we need to provision the other course. - if ($istargetcourseprovisioned || $isoriginalcourseprovisioned) { - // Source course not provisioned, lets provision with target servername and applicationkey. - if (!$isoriginalcourseprovisioned) { + if ($provisionduringcopy == 'both') { + // If any is provisioned, check if we need to provision the other course. + if ($istargetcourseprovisioned || $isoriginalcourseprovisioned) { + if (!$isoriginalcourseprovisioned) { + // Provision original course. + $panoptodata = new \panopto_data($newcourseid); + $originalpanoptodata->servername = $panoptodata->servername; + $originalpanoptodata->applicationkey = $panoptodata->applicationkey; + $originalprovisioninginfo = $originalpanoptodata->get_provisioning_info(); + $originalprovisioneddata = $originalpanoptodata->provision_course($originalprovisioninginfo, false); + if (isset($originalprovisioneddata->Id) && !empty($originalprovisioneddata->Id)) { + $isoriginalcourseprovisioned = true; + } + } + + if (!$istargetcourseprovisioned) { + // Provision target course. + $originalpanoptodata = new \panopto_data($originalcourseid); + $panoptodata->servername = $originalpanoptodata->servername; + $panoptodata->applicationkey = $originalpanoptodata->applicationkey; + $provisioninginfo = $panoptodata->get_provisioning_info(); + $targetprovisioneddata = $panoptodata->provision_course($provisioninginfo, false); + if (isset($targetprovisioneddata->Id) && !empty($targetprovisioneddata->Id)) { + $istargetcourseprovisioned = true; + } + } + } else { + // Neither course is provisioned. + + // Provision target course using automatic operation server. + $targetserver = panopto_get_target_panopto_server(); + $panoptodata->servername = $targetserver->name; + $panoptodata->applicationkey = $targetserver->appkey; + $provisioninginfo = $panoptodata->get_provisioning_info(); + $targetprovisioneddata = $panoptodata->provision_course($provisioninginfo, false); + if (isset($targetprovisioneddata->Id) && !empty($targetprovisioneddata->Id)) { + $istargetcourseprovisioned = true; + } + + // Provision original course using target course servername and applicationkey. $panoptodata = new \panopto_data($newcourseid); $originalpanoptodata->servername = $panoptodata->servername; $originalpanoptodata->applicationkey = $panoptodata->applicationkey; @@ -181,44 +222,23 @@ public static function courserestored(\core\event\course_restored $event) { $isoriginalcourseprovisioned = true; } } - - // Target course not provisioned, lets provision with original servername and applicationkey. - if (!$istargetcourseprovisioned) { - $originalpanoptodata = new \panopto_data($originalcourseid); - $panoptodata->servername = $originalpanoptodata->servername; - $panoptodata->applicationkey = $originalpanoptodata->applicationkey; + } else if ($provisionduringcopy == 'onlytarget') { + // Provision new course only if source is already provisioned. + if ($isoriginalcourseprovisioned && !$istargetcourseprovisioned) { + // Provision target course. + $targetserver = new \panopto_data($originalcourseid); + $panoptodata->servername = $targetserver->servername; + $panoptodata->applicationkey = $targetserver->applicationkey; $provisioninginfo = $panoptodata->get_provisioning_info(); $targetprovisioneddata = $panoptodata->provision_course($provisioninginfo, false); if (isset($targetprovisioneddata->Id) && !empty($targetprovisioneddata->Id)) { $istargetcourseprovisioned = true; } } - } else { - // Neither course is provisioned. - - // Provision target course using automatic operation server. - $targetserver = panopto_get_target_panopto_server(); - $panoptodata->servername = $targetserver->name; - $panoptodata->applicationkey = $targetserver->appkey; - $provisioninginfo = $panoptodata->get_provisioning_info(); - $targetprovisioneddata = $panoptodata->provision_course($provisioninginfo, false); - if (isset($targetprovisioneddata->Id) && !empty($targetprovisioneddata->Id)) { - $istargetcourseprovisioned = true; - } - - // Provision original course using target course servername and applicationkey. - $panoptodata = new \panopto_data($newcourseid); - $originalpanoptodata->servername = $panoptodata->servername; - $originalpanoptodata->applicationkey = $panoptodata->applicationkey; - $originalprovisioninginfo = $originalpanoptodata->get_provisioning_info(); - $originalprovisioneddata = $originalpanoptodata->provision_course($originalprovisioninginfo, false); - if (isset($originalprovisioneddata->Id) && !empty($originalprovisioneddata->Id)) { - $isoriginalcourseprovisioned = true; - } } - // We should only perform the import if both the target and the source courses are provisioned in panopto. - if ($istargetcourseprovisioned && $isoriginalcourseprovisioned) { + // We should only perform the import if source course is provisioned in panopto. + if ($isoriginalcourseprovisioned) { // If courses are provisioned to different servers, log an error and return. if (strcmp($panoptodata->servername, $originalpanoptodata->servername) !== 0) { @@ -255,10 +275,10 @@ public static function userenrolmentdeleted(\core\event\user_enrolment_deleted $ } $task = new \block_panopto\task\sync_user(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $event->courseid, 'userid' => $event->relateduserid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -279,10 +299,10 @@ public static function userenrolmentupdated(\core\event\user_enrolment_updated $ } $task = new \block_panopto\task\sync_user(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $event->courseid, 'userid' => $event->relateduserid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -304,10 +324,10 @@ public static function roleassigned(core\event\role_assigned $event) { if (get_config('block_panopto', 'sync_on_enrolment')) { $task = new \block_panopto\task\sync_user(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $event->courseid, 'userid' => $event->relateduserid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -330,10 +350,10 @@ public static function roleunassigned(core\event\role_unassigned $event) { if (get_config('block_panopto', 'sync_on_enrolment')) { $task = new \block_panopto\task\sync_user(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $event->courseid, 'userid' => $event->relateduserid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -357,9 +377,9 @@ public static function userloggedin(\core\event\user_loggedin $event) { if (get_config('block_panopto', 'sync_after_login')) { $task = new \block_panopto\task\sync_user_login(); - $task->set_custom_data(array( + $task->set_custom_data([ 'userid' => $event->userid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); @@ -384,9 +404,9 @@ public static function userloggedinas(\core\event\user_loggedinas $event) { if (get_config('block_panopto', 'sync_after_login')) { $task = new \block_panopto\task\sync_user_login(); - $task->set_custom_data(array( + $task->set_custom_data([ 'userid' => $event->relateduserid - )); + ]); if (get_config('block_panopto', 'async_tasks')) { \core\task\manager::queue_adhoc_task($task); diff --git a/db/access.php b/db/access.php index 96a91d2..5d417a4 100644 --- a/db/access.php +++ b/db/access.php @@ -24,50 +24,50 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'block/panopto:provision_course' => array( +$capabilities = [ + 'block/panopto:provision_course' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ) - ), - 'block/panopto:provision_multiple' => array( + ] + ], + 'block/panopto:provision_multiple' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW - ) - ), - 'block/panopto:provision_asteacher' => array( + ] + ], + 'block/panopto:provision_asteacher' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array() - ), - 'block/panopto:provision_aspublisher' => array( + 'archetypes' => [] + ], + 'block/panopto:provision_aspublisher' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array() - ), - 'block/panopto:addinstance' => array( + 'archetypes' => [] + ], + 'block/panopto:addinstance' => [ 'riskbitmask' => RISK_SPAM | RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/site:manageblocks' - ), - 'block/panopto:myaddinstance' => array('captype' => 'write', + ], + 'block/panopto:myaddinstance' => ['captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'user' => CAP_ALLOW, - ), + ], 'clonepermissionsfrom' => 'moodle/my:manageblocks' - ) -); + ] +]; /* End of file access.php */ diff --git a/db/events.php b/db/events.php index d783894..4de6a60 100644 --- a/db/events.php +++ b/db/events.php @@ -24,55 +24,55 @@ defined('MOODLE_INTERNAL') || die(); -$observers = array( - array( +$observers = [ + [ 'eventname' => '\core\event\course_created', 'callback' => 'block_panopto_rollingsync::coursecreated', - ), + ], // Event when a course is imported or backed up. - array( + [ 'eventname' => '\core\event\course_restored', 'callback' => 'block_panopto_rollingsync::courserestored', - ), - array( + ], + [ 'eventname' => '\core\event\course_deleted', 'callback' => 'block_panopto_rollingsync::coursedeleted', - ), + ], // User unenroled event. - array( + [ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => 'block_panopto_rollingsync::userenrolmentdeleted', - ), + ], // User unenroled event. - array( + [ 'eventname' => '\core\event\user_enrolment_updated', 'callback' => 'block_panopto_rollingsync::userenrolmentupdated', - ), + ], // User enroled event. - array( + [ 'eventname' => '\core\event\role_assigned', 'callback' => 'block_panopto_rollingsync::roleassigned', - ), + ], // User Enrollment changed event. - array( + [ 'eventname' => '\core\event\role_unassigned', 'callback' => 'block_panopto_rollingsync::roleunassigned', - ), + ], // User loggedin and loggedinas events. - array( + [ 'eventname' => '\core\event\user_loggedin', 'callback' => 'block_panopto_rollingsync::userloggedin', - ), - array( + ], + [ 'eventname' => '\core\event\user_loggedinas', 'callback' => 'block_panopto_rollingsync::userloggedinas', - ), - array( + ], + [ 'eventname' => '\core\event\course_category_updated', 'callback' => 'block_panopto_categorytasks::coursecategoryupdated', - ), - array( + ], + [ 'eventname' => '\core\event\course_category_created', 'callback' => 'block_panopto_categorytasks::coursecategorycreated', - ) -); + ] +]; diff --git a/db/upgrade.php b/db/upgrade.php index a863a58..1ce8ae7 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -133,12 +133,12 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { $table = new xmldb_table('block_panopto_importmap'); if (!$dbman->table_exists($table)) { - $importfields = array(); + $importfields = []; $importfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true); $importfields[] = new xmldb_field('target_moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $importfields[] = new xmldb_field('import_moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); - $importkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); + $importkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, ['id'], null, null); foreach ($importfields as $importfield) { // Conditionally launch add field import_moodle_id. @@ -157,8 +157,8 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { if ($oldversion < 2017031303) { // Get the roles using the old method so we can update current customers to the new tables. - $pubroles = array(); - $creatorroles = array(); + $pubroles = []; + $creatorroles = []; // Get publisher roles as string and explode to array. $existingcoursemappings = $DB->get_records( @@ -171,12 +171,12 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { $creatortable = new xmldb_table('block_panopto_creatormap'); if (!$dbman->table_exists($creatortable)) { - $mappingfields = array(); + $mappingfields = []; $mappingfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true); $mappingfields[] = new xmldb_field('moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $mappingfields[] = new xmldb_field('role_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); - $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); + $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, ['id'], null, null); foreach ($mappingfields as $mappingfield) { $creatortable->addField($mappingfield); @@ -192,7 +192,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { foreach ($creatorroles as $creatorrole) { if (!empty($creatorrole)) { - $row = (object) array('moodle_id' => $existingmapping->moodleid, 'role_id' => $creatorrole); + $row = (object) ['moodle_id' => $existingmapping->moodleid, 'role_id' => $creatorrole]; $DB->insert_record('block_panopto_creatormap', $row); } } @@ -203,12 +203,12 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { $publishertable = new xmldb_table('block_panopto_publishermap'); if (!$dbman->table_exists($publishertable)) { - $mappingfields = array(); + $mappingfields = []; $mappingfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true); $mappingfields[] = new xmldb_field('moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $mappingfields[] = new xmldb_field('role_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); - $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); + $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, ['id'], null, null); foreach ($mappingfields as $mappingfield) { $publishertable->addField($mappingfield); @@ -224,7 +224,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { foreach ($pubroles as $pubrole) { if (!empty($pubrole)) { - $row = (object) array('moodle_id' => $existingmapping->moodleid, 'role_id' => $pubrole); + $row = (object) ['moodle_id' => $existingmapping->moodleid, 'role_id' => $pubrole]; $DB->insert_record('block_panopto_publishermap', $row); } } @@ -241,7 +241,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { // Define table table where we will place all of our old/broken folder mappings. So customers can keep the data if needed. $oldfoldermaptable = new xmldb_table('block_panopto_old_foldermap'); if (!$dbman->table_exists($oldfoldermaptable)) { - $mappingfields = array(); + $mappingfields = []; $mappingfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true); $mappingfields[] = @@ -256,7 +256,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { new xmldb_field('publisher_mapping', XMLDB_TYPE_CHAR, '20', null, null, null, '1', 'panopto_app_key'); $mappingfields[] = new xmldb_field('creator_mapping', XMLDB_TYPE_CHAR, '20', null, null, null, '3,4', 'publisher_mapping'); - $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); + $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, ['id'], null, null); foreach ($mappingfields as $mappingfield) { $oldfoldermaptable->addField($mappingfield); } @@ -265,7 +265,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } // Delete any existing tasks since those would be from the old plug-in generation. - $DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), array('%block_panopto%task%')); + $DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), ['%block_panopto%task%']); // Panopto savepoint reached. upgrade_block_savepoint(true, 2017110600, 'panopto'); @@ -289,7 +289,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { // So we can know which categories are linked to Panopto folders. $categorymaptable = new xmldb_table('block_panopto_categorymap'); if (!$dbman->table_exists($categorymaptable)) { - $mappingfields = array(); + $mappingfields = []; $mappingfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true); $mappingfields[] = new xmldb_field('category_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'id'); @@ -297,7 +297,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { new xmldb_field('panopto_id', XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null, 'category_id'); $mappingfields[] = new xmldb_field('panopto_server', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'panopto_id'); - $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); + $mappingkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, ['id'], null, null); foreach ($mappingfields as $mappingfield) { $categorymaptable->addField($mappingfield); } @@ -336,8 +336,8 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { $categorymaptable = new xmldb_table('block_panopto_categorymap'); if ($dbman->table_exists($foldermaptable)) { - $moodleidindex = new xmldb_index('mdl_blocpanofold_moo_ix', XMLDB_INDEX_NOTUNIQUE, array('moodleid'), array()); - $serverindex = new xmldb_index('mdl_blocpanofold_pan_ix', XMLDB_INDEX_NOTUNIQUE, array('panopto_server'), array()); + $moodleidindex = new xmldb_index('mdl_blocpanofold_moo_ix', XMLDB_INDEX_NOTUNIQUE, ['moodleid'], []); + $serverindex = new xmldb_index('mdl_blocpanofold_pan_ix', XMLDB_INDEX_NOTUNIQUE, ['panopto_server'], []); if (!$dbman->index_exists($foldermaptable, $moodleidindex)) { $dbman->add_index($foldermaptable, $moodleidindex); @@ -351,8 +351,8 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } if ($dbman->table_exists($importmaptable)) { - $targetidindex = new xmldb_index('mdl_blocpanoimpo_tar_ix', XMLDB_INDEX_NOTUNIQUE, array('target_moodle_id'), array()); - $importidindex = new xmldb_index('mdl_blocpanoimpo_imp_ix', XMLDB_INDEX_NOTUNIQUE, array('import_moodle_id'), array()); + $targetidindex = new xmldb_index('mdl_blocpanoimpo_tar_ix', XMLDB_INDEX_NOTUNIQUE, ['target_moodle_id'], []); + $importidindex = new xmldb_index('mdl_blocpanoimpo_imp_ix', XMLDB_INDEX_NOTUNIQUE, ['import_moodle_id'], []); if (!$dbman->index_exists($importmaptable, $targetidindex)) { $dbman->add_index($importmaptable, $targetidindex); @@ -366,7 +366,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } if ($dbman->table_exists($creatormaptable)) { - $moodleidindex = new xmldb_index('mdl_blocpanocrea_moo_ix', XMLDB_INDEX_NOTUNIQUE, array('moodle_id'), array()); + $moodleidindex = new xmldb_index('mdl_blocpanocrea_moo_ix', XMLDB_INDEX_NOTUNIQUE, ['moodle_id'], []); if (!$dbman->index_exists($creatormaptable, $moodleidindex)) { $dbman->add_index($creatormaptable, $moodleidindex); @@ -376,7 +376,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } if ($dbman->table_exists($publishermaptable)) { - $moodleidindex = new xmldb_index('mdl_blocpanopubl_moo_ix', XMLDB_INDEX_NOTUNIQUE, array('moodle_id'), array()); + $moodleidindex = new xmldb_index('mdl_blocpanopubl_moo_ix', XMLDB_INDEX_NOTUNIQUE, ['moodle_id'], []); if (!$dbman->index_exists($publishermaptable, $moodleidindex)) { $dbman->add_index($publishermaptable, $moodleidindex); @@ -386,8 +386,8 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } if ($dbman->table_exists($oldfoldermaptable)) { - $moodleidindex = new xmldb_index('mdl_blocpanooldfold_moo_ix', XMLDB_INDEX_NOTUNIQUE, array('moodleid'), array()); - $serverindex = new xmldb_index('mdl_blocpanooldfold_pan_ix', XMLDB_INDEX_NOTUNIQUE, array('panopto_server'), array()); + $moodleidindex = new xmldb_index('mdl_blocpanooldfold_moo_ix', XMLDB_INDEX_NOTUNIQUE, ['moodleid'], []); + $serverindex = new xmldb_index('mdl_blocpanooldfold_pan_ix', XMLDB_INDEX_NOTUNIQUE, ['panopto_server'], []); if (!$dbman->index_exists($oldfoldermaptable, $moodleidindex)) { $dbman->add_index($oldfoldermaptable, $moodleidindex); @@ -401,7 +401,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) { } if ($dbman->table_exists($categorymaptable)) { - $serverindex = new xmldb_index('mdl_blocpanocate_cat_ix', XMLDB_INDEX_NOTUNIQUE, array('category_id'), array()); + $serverindex = new xmldb_index('mdl_blocpanocate_cat_ix', XMLDB_INDEX_NOTUNIQUE, ['category_id'], []); if (!$dbman->index_exists($categorymaptable, $serverindex)) { $dbman->add_index($categorymaptable, $serverindex); diff --git a/lang/en/block_panopto.php b/lang/en/block_panopto.php index 32bdb83..0930d97 100644 --- a/lang/en/block_panopto.php +++ b/lang/en/block_panopto.php @@ -81,19 +81,20 @@ $string['block_panopto_async_tasks_desc'] = 'When selected, the login, enrolment, unenrolment, category enforcement, and delete user tasks happen asynchronously. If this option is deselected, these operations happen in the event handler synchronously. As it is difficult to detect the failure in a timely manner. we do not recommend this option.'; $string['block_panopto_auto_add_block_to_new_courses'] = 'Automatically add a Panopto block to new courses'; $string['block_panopto_auto_add_block_to_new_courses_desc'] = "When selected this will automatically insert a Panopto block into all new Moodle course pages."; -$string['block_panopto_auto_provision'] = 'Automatically provision courses'; $string['block_panopto_auto_insert_lti_link_to_new_courses'] = 'Automatically create an LTI tool link for new courses'; $string['block_panopto_auto_insert_lti_link_to_new_courses_desc'] = "When selected this will automatically insert a folder view course tool link to your automatic operation Panopto server into the first available section of your Moodle course page. Note: This feature requires that you add the following custom parameter to the Pre-configured LTI tool you wish to be embedded into the course: panopto_course_embed_tool=true"; $string['block_panopto_auto_provision'] = 'Automatically provision courses'; -$string['block_panopto_auto_provision_desc'] = 'This option can be set to automatically provision a Panopto course folder when a course is created. This option can also be set to automatically provision a course when the Panopto block is first viewed on it.'; +$string['block_panopto_auto_provision_desc'] = 'This option can be set to automatically provision a Panopto course folder when a course is created. This option can also be set to automatically provision a course when the Panopto block is first viewed on it. Please note that even if this value is \'Do not provision new courses\', courses may still be automatically provisioned if \'Automatically Grant Permissions when Importing a Course\' is selected.'; $string['block_panopto_auto_sync_imports'] = 'Automatically Grant Permissions when Importing a Course'; -$string['block_panopto_auto_sync_imports_desc'] = 'When selected, Panopto automatically grants viewer permissions when importing a course.'; +$string['block_panopto_auto_sync_imports_desc'] = 'When selected, Panopto automatically grants viewer permissions when importing a course. This setting must also be selected for Panopto\'s Course Copy V2 process.'; $string['block_panopto_automatic_operation_target_server'] = 'Automatic operation target server'; $string['block_panopto_automatic_operation_target_server_desc'] = 'Select the Panopto server that will be targeted for the \'Automatically provision new courses\', \'Sync user on login\' and \'Enforce category structure\' tasks'; $string['block_panopto_check_server_status'] = 'Check server health before loading block'; $string['block_panopto_check_server_status_desc'] = 'When selected, the target Panopto server is checked to ensure that it is running to avoid potentially long timeout calls when the server is unreachable. This is deselected by default as it uses a platform / OS-dependent feature. This should only be selected if you have been advised to do so by Panopto Support.'; $string['block_panopto_check_server_interval'] = 'Server health check interval'; $string['block_panopto_check_server_interval_desc'] = 'How often the server health check should attempt to connect to the Panopto server. The result will be saved and cached until the next health check.'; +$string['block_panopto_copy_provision'] = 'Copy course provisioning'; +$string['block_panopto_copy_provision_desc'] = 'This option can be set to determine which course or courses we want to provision during copy or import process.'; $string['block_panopto_creator_mapping'] = 'Creator role mapping'; $string['block_panopto_creator_mapping_desc'] = 'Select which course roles are set as Creators in new Panopto course folders.'; $string['block_panopto_enforce_category_after_course_provision'] = 'Create Category Folders on Course (Re)provision'; @@ -125,7 +126,7 @@ $string['block_panopto_sync_after_login'] = 'Authenticate and Sync to Panopto on Moodle Login (not recommended)'; $string['block_panopto_sync_after_login_desc'] = 'When selected, users are authenticated with Panopto and their permissions are synced when logging in to Moodle. Typically, authentication and permission sync will occur when a user accesses Panopto in the course and as such, we only recommend that organizations turn this setting on if they do not place the Panopto block in Moodle (not recommended). Additionally, log-in time will be extended if this option is selected.'; $string['block_panopto_sync_after_provisioning'] = 'Sync Enrolled Users after Successfully Provisioning (not recommended)'; -$string['block_panopto_sync_after_provisioning_desc'] = 'When selected, all users enrolled in a course will be synchronized after provisioning. Typically, when a user accesses the Panopto block in a course, authentication and permission sync of that course happen. As such, we only recommend that organizations turn this setting on if they do not place the Panopto block in Moodle (not recommended).'; +$string['block_panopto_sync_after_provisioning_desc'] = 'When selected, all users enrolled in a course that is active and visible will be synchronized after provisioning. Typically, when a user accesses the Panopto block in a course, authentication and permission sync of that course happen. As such, we only recommend that organizations turn this setting on if they do not place the Panopto block in Moodle (not recommended).'; $string['block_panopto_sync_on_enrolment'] = 'Sync Users after Class Enrolment (optional)'; $string['block_panopto_sync_on_enrolment_desc'] = 'When selected, the permission when a student is enrolled into a course is synchronized with a valid Panopto folder. When disabled, users will be synced with Panopto when the user views the Panopto block. If you do not intend to use the block in a course, or if a course has embedded Panopto content directly into the course homepage (content will load before the block syncs in this case), this feature can be enabled. Note: Enabling this feature may cause a performance slowdown when enroling users.'; $string['block_panopto_wsdl_proxy_host'] = 'WSDL Proxy Host'; @@ -236,9 +237,11 @@ $string['privacy:metadata:block_panopto:username'] = 'Your username is sent to Panopto to allow it to create a Panopto account using the Moodle username as the Panopto username.'; $string['provision'] = 'Provision'; $string['provision_access_error'] = 'Course already provisioned to a Panopto folder and the current user does not have access to perform operations on that folder (User needs at least viewer access to target Panopto folder).'; +$string['provision_both_on_copy'] = 'Provision both courses during copy or import process.'; $string['provision_course_link_text'] = 'Provision course'; $string['provision_courses'] = 'Provision courses'; $string['provision_error'] = 'Error provisioning course, please check logs for more details.'; +$string['provision_only_target_on_copy'] = 'Only provision the target course during a copy or import process, as long as the source course is already provisioned.'; $string['provision_successful'] = 'Successfully provisioned course folder with Id: {$a}'; $string['provisioncourseselect'] = 'Select courses to provision.'; $string['provisioncourseselect_help'] = 'Multiple selections are possible by Ctrl-clicking (Windows) or Cmd-clicking (Mac).'; diff --git a/lib/block_panopto_bulk_lib.php b/lib/block_panopto_bulk_lib.php index 679dd63..7ff59d8 100644 --- a/lib/block_panopto_bulk_lib.php +++ b/lib/block_panopto_bulk_lib.php @@ -244,7 +244,7 @@ function panopto_bulk_sanitize_and_get_mappings($params, $skipimports) { $upgradestep = get_string('verifying_permission', 'block_panopto'); - $panoptocourseobjects = array(); + $panoptocourseobjects = []; $getunamepanopto = new \panopto_data(null); @@ -267,7 +267,7 @@ function panopto_bulk_sanitize_and_get_mappings($params, $skipimports) { $oldpanoptocourse = new stdClass; $oldpanoptocourse->panopto = new \panopto_data($oldcourse->moodleid); - $existingmoodlecourse = $DB->get_record('course', array('id' => $oldcourse->moodleid)); + $existingmoodlecourse = $DB->get_record('course', ['id' => $oldcourse->moodleid]); $moodlecourseexists = isset($existingmoodlecourse) && $existingmoodlecourse !== false; $hasvalidpanoptodata = isset($oldpanoptocourse->panopto->servername) && !empty($oldpanoptocourse->panopto->servername) && @@ -294,7 +294,7 @@ function panopto_bulk_sanitize_and_get_mappings($params, $skipimports) { panopto_bulk_display_access_error($getunamepanopto->panopto_decorate_username($getunamepanopto->uname)); // If the user does not have access on even one of the folders return nothing. - return array(); + return []; } } else { // Shouldn't hit this case, but in the case a row in the DB has invalid data move it to the old_foldermap. @@ -311,7 +311,7 @@ function panopto_bulk_sanitize_and_get_mappings($params, $skipimports) { panopto_bulk_display_access_error($getunamepanopto->panopto_decorate_username($getunamepanopto->uname)); // If the user does not have access on even one of the folders return nothing. - return array(); + return []; } else { if (isset($oldpanoptocourse->provisioninginfo->couldnotfindmappedfolder) && $oldpanoptocourse->provisioninginfo->couldnotfindmappedfolder === true) { @@ -330,7 +330,7 @@ function panopto_bulk_sanitize_and_get_mappings($params, $skipimports) { foreach ($courseimports as $courseimport) { $importpanopto = new \panopto_data($courseimport); - $existingmoodlecourse = $DB->get_record('course', array('id' => $courseimport)); + $existingmoodlecourse = $DB->get_record('course', ['id' => $courseimport]); $moodlecourseexists = isset($existingmoodlecourse) && $existingmoodlecourse !== false; $hasvalidpanoptodata = isset($importpanopto->servername) && !empty($importpanopto->servername) && diff --git a/lib/block_panopto_lib.php b/lib/block_panopto_lib.php index 54cc942..b627791 100644 --- a/lib/block_panopto_lib.php +++ b/lib/block_panopto_lib.php @@ -102,7 +102,7 @@ function panopto_validate_auth_code($payload, $authcode) { * @param string $apiurl */ function panopto_generate_wsdl_service_params($apiurl) { - $serviceparams = array('wsdl_url' => $apiurl); + $serviceparams = ['wsdl_url' => $apiurl]; // Check to see if the user set any proxy options. $proxyhost = get_config('block_panopto', 'wsdl_proxy_host'); @@ -134,7 +134,7 @@ function panopto_get_configured_panopto_servers() { // Increment numservers by 1 to take into account starting at 0. ++$numservers; - $targetserverarray = array(); + $targetserverarray = []; for ($serverwalker = 1; $serverwalker <= $numservers; ++$serverwalker) { // Generate strings corresponding to potential servernames in the config. @@ -188,7 +188,7 @@ function panopto_get_target_panopto_server() { * */ function panopto_get_valid_panopto_servers() { - $ret = array(); + $ret = []; $numservers = get_config('block_panopto', 'server_number'); $numservers = isset($numservers) ? $numservers : 0; @@ -350,7 +350,7 @@ function panopto_get_all_roles_at_context_and_contextlevel($targetcontext) { "LEFT JOIN {role_names} rn ON (rn.contextid = :targetcontext AND rn.roleid = r.id) " . "ORDER BY r.sortorder ASC"; return $DB->get_records_sql($sql, - array('targetcontext' => $targetcontext->id, 'targetcontextlevel' => $targetcontext->contextlevel)); + ['targetcontext' => $targetcontext->id, 'targetcontextlevel' => $targetcontext->contextlevel]); } /** diff --git a/lib/lti/auth.php b/lib/lti/auth.php index 2f58429..01ca6ca 100644 --- a/lib/lti/auth.php +++ b/lib/lti/auth.php @@ -165,15 +165,15 @@ if (empty($courseid)) { $courseid = 1; - $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); } else { $context = context_course::instance($courseid); - $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); $PAGE->set_context($context); $PAGE->set_course($course); } -// Specific logic for Moodle 4.2 +// Specific logic for Moodle 4.2. $ismoodle42minimum = empty($CFG->version) ? false : $CFG->version >= 2023042400.00; if ($ismoodle42minimum) { $panoptodata = new \panopto_data($course->id); @@ -234,7 +234,7 @@ } } - // If we get to this point we know this is a plug-in based request and will not support grading + // If we get to this point we know this is a plug-in based request and will not support grading. $lti->custom->grading_not_supported = true; list($endpoint, $params) = panoptoblock_lti_utility::get_launch_data($lti, $nonce); diff --git a/lib/lti/panoptoblock_lti_utility.php b/lib/lti/panoptoblock_lti_utility.php index 166992d..f90132f 100644 --- a/lib/lti/panoptoblock_lti_utility.php +++ b/lib/lti/panoptoblock_lti_utility.php @@ -318,10 +318,10 @@ public static function get_launch_data($instance, $nonce = '') { )); $launchcontainer = lti_get_launch_container($instance, $typeconfig); - $returnurlparams = array('course' => $course->id, + $returnurlparams = ['course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->typeid, - 'sesskey' => sesskey()); + 'sesskey' => sesskey()]; // Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns. $url = new \moodle_url('/mod/lti/return.php', $returnurlparams); @@ -368,7 +368,7 @@ public static function get_launch_data($instance, $nonce = '') { $plugins = core_component::get_plugin_list('ltisource'); foreach (array_keys($plugins) as $plugin) { $pluginparams = component_callback('ltisource_'.$plugin, 'before_launch', - array($instance, $endpoint, $requestparams), array()); + [$instance, $endpoint, $requestparams], []); if (!empty($pluginparams) && is_array($pluginparams)) { $requestparams = array_merge($requestparams, $pluginparams); @@ -406,7 +406,7 @@ public static function get_launch_data($instance, $nonce = '') { $params = $requestparams; } - return array($endpoint, $params); + return [$endpoint, $params]; } /** @@ -423,9 +423,9 @@ public static function get_course_tool($courseid) { $targetservername = null; - $blockexists = $DB->get_record('block', array('name' => 'panopto'), 'name'); + $blockexists = $DB->get_record('block', ['name' => 'panopto'], 'name'); if (!empty($blockexists)) { - $targetservername = $DB->get_field('block_panopto_foldermap', 'panopto_server', array('moodleid' => $courseid)); + $targetservername = $DB->get_field('block_panopto_foldermap', 'panopto_server', ['moodleid' => $courseid]); } // If the course if not provisioned with the Panopto block then get the default panopto server fqdn. @@ -743,9 +743,9 @@ private static function get_target_server_name($courseid) { $targetservername = null; - $blockexists = $DB->get_record('block', array('name' => 'panopto'), 'name'); + $blockexists = $DB->get_record('block', ['name' => 'panopto'], 'name'); if (!empty($blockexists)) { - $targetservername = $DB->get_field('block_panopto_foldermap', 'panopto_server', array('moodleid' => $courseid)); + $targetservername = $DB->get_field('block_panopto_foldermap', 'panopto_server', ['moodleid' => $courseid]); } // If the course if not provisioned with the Panopto block then get the default panopto server fqdn. diff --git a/lib/panopto_category_data.php b/lib/panopto_category_data.php index cb69b62..80ccd0b 100644 --- a/lib/panopto_category_data.php +++ b/lib/panopto_category_data.php @@ -178,7 +178,7 @@ public static function get_panopto_category_id($moodlecategoryid, $targetserver) return $DB->get_field( 'block_panopto_categorymap', 'panopto_id', - array('category_id' => $moodlecategoryid, 'panopto_id' => $targetserver) + ['category_id' => $moodlecategoryid, 'panopto_id' => $targetserver] ); } @@ -189,7 +189,7 @@ public static function get_panopto_category_id($moodlecategoryid, $targetserver) */ public static function get_panopto_servername($moodlecategoryid) { global $DB; - return $DB->get_field('block_panopto_categorymap', 'panopto_server', array('category_id' => $moodlecategoryid)); + return $DB->get_field('block_panopto_categorymap', 'panopto_server', ['category_id' => $moodlecategoryid]); } /** @@ -218,11 +218,11 @@ public function ensure_category_branch($usehtmloutput, $leafcoursedata) { } else { try { - $targetcategory = $DB->get_record('course_categories', array('id' => $this->moodlecategoryid)); + $targetcategory = $DB->get_record('course_categories', ['id' => $this->moodlecategoryid]); // Check if multilanguage categories are being used. // If they are being used strip html from category name, and take first. If not just return category/folder name. - $multilanguagefilter = new filter_multilang('', array()); + $multilanguagefilter = new filter_multilang('', []); $cleancategoryname = $multilanguagefilter->filter($targetcategory->name); // Some users have categories with no name, so default it to id. @@ -239,7 +239,7 @@ public function ensure_category_branch($usehtmloutput, $leafcoursedata) { \panopto_data::print_log_verbose(get_string('ensure_category_branch_start', 'block_panopto', $branchinfo)); } - $categoryheirarchy = array(); + $categoryheirarchy = []; if (isset($leafcoursedata) && !empty($leafcoursedata)) { // We don't need to pass a name into this constructor since we can assume course folders exist. @@ -256,7 +256,7 @@ public function ensure_category_branch($usehtmloutput, $leafcoursedata) { $targetcategory->id ); - $currentcategory = $DB->get_record('course_categories', array('id' => $targetcategory->parent)); + $currentcategory = $DB->get_record('course_categories', ['id' => $targetcategory->parent]); while (isset($currentcategory) && !empty($currentcategory)) { $currentcategoryname = !empty(trim($currentcategory->name)) ? $currentcategory->name : $currentcategory->id; @@ -267,7 +267,7 @@ public function ensure_category_branch($usehtmloutput, $leafcoursedata) { $currentcategory->id ); - $currentcategory = $DB->get_record('course_categories', array('id' => $currentcategory->parent)); + $currentcategory = $DB->get_record('course_categories', ['id' => $currentcategory->parent]); } $this->ensure_session_manager(); @@ -305,12 +305,12 @@ public function ensure_category_branch($usehtmloutput, $leafcoursedata) { */ private function save_category_data_to_table($categorybranchdata, $usehtmloutput, $leafcoursedata) { global $DB; - $row = (object) array( + $row = (object) [ 'category_id' => null, 'panopto_id' => null, 'panopto_server' => $this->servername, 'panopto_app_key' => $this->applicationkey - ); + ]; $ensuredbranch = ''; $leafcoursesessiongroupid = (isset($leafcoursedata) && !empty($leafcoursedata)) ? $leafcoursedata->sessiongroupid : null; @@ -391,10 +391,10 @@ private static function update_category_row($row) { $oldrow = $DB->get_record( 'block_panopto_categorymap', - array( + [ 'category_id' => $row->category_id, 'panopto_server' => $row->panopto_server - ) + ] ); if ($oldrow) { diff --git a/lib/panopto_data.php b/lib/panopto_data.php index 5c20c7b..c7beed7 100644 --- a/lib/panopto_data.php +++ b/lib/panopto_data.php @@ -136,11 +136,11 @@ class panopto_data { * @return array */ public static function getpossiblefoldernamestyles() { - return array( + return [ 'fullname' => get_string('name_style_fullname', 'block_panopto'), 'shortname' => get_string('name_style_shortname', 'block_panopto'), 'combination' => get_string('name_style_combination', 'block_panopto') - ); + ]; } /** * Returns an array of possible values for the Panopto folder name style @@ -148,11 +148,22 @@ public static function getpossiblefoldernamestyles() { * @return array */ public static function getpossibleprovisiontypes() { - return array( + return [ 'off' => get_string('autoprovision_off', 'block_panopto'), 'oncoursecreation' => get_string('autoprovision_new_courses', 'block_panopto'), 'onblockview' => get_string('autoprovision_on_block_view', 'block_panopto') - ); + ]; + } + /** + * Returns an array of possible values for copy provisioning. + * + * @return array + */ + public static function getpossiblecopyprovisiontypes() { + return [ + 'both' => get_string('provision_both_on_copy', 'block_panopto'), + 'onlytarget' => get_string('provision_only_target_on_copy', 'block_panopto'), + ]; } /** * Return the possible list of SSO sync types @@ -160,11 +171,11 @@ public static function getpossibleprovisiontypes() { * @return array */ public static function getpossiblessosynctypes() { - return array( + return [ 'nosync' => get_string('sso_type_nosync', 'block_panopto'), 'sync' => get_string('sso_type_sync', 'block_panopto'), 'asyncsync' => get_string('sso_type_asyncsync', 'block_panopto') - ); + ]; } /** @@ -175,7 +186,7 @@ public static function getpossiblessosynctypes() { public static function remove_all_panopto_adhoc_tasks() { global $DB; - return $DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), array('%block_panopto%task%')); + return $DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), ['%block_panopto%task%']); } /** @@ -193,7 +204,7 @@ public function __construct($moodlecourseid) { // Get servername and application key specific to Moodle course if ID is specified. if (isset($moodlecourseid) && !empty($moodlecourseid)) { $foldermapdata = $DB->get_record('block_panopto_foldermap', - array('moodleid' => $moodlecourseid), 'panopto_server,panopto_id'); + ['moodleid' => $moodlecourseid], 'panopto_server,panopto_id'); if (!empty($foldermapdata)) { $this->servername = $foldermapdata->panopto_server; $this->sessiongroupid = $foldermapdata->panopto_id; @@ -381,7 +392,7 @@ public function provision_course($provisioninginfo, $skipusersync) { $currentblockversion = $DB->get_record( 'config_plugins', - array('plugin' => 'block_panopto', 'name' => 'version'), + ['plugin' => 'block_panopto', 'name' => 'version'], 'value' ); @@ -395,9 +406,9 @@ public function provision_course($provisioninginfo, $skipusersync) { $coursecontext = context_course::instance($this->moodlecourseid); $enrolledusers = get_enrolled_users($coursecontext); - $courseinfo->viewers = array(); - $courseinfo->creators = array(); - $courseinfo->publishers = array(); + $courseinfo->viewers = []; + $courseinfo->creators = []; + $courseinfo->publishers = []; // Sync every user enrolled in the course. foreach ($enrolledusers as $enrolleduser) { @@ -433,7 +444,7 @@ public function provision_course($provisioninginfo, $skipusersync) { $targetcategory = $DB->get_field( 'course', 'category', - array('id' => $this->moodlecourseid) + ['id' => $this->moodlecourseid] ); if (isset($targetcategory) && !empty($targetcategory)) { @@ -554,7 +565,7 @@ public function get_provisioning_info() { $coursenameinfo = $DB->get_record( 'course', - array('id' => $this->moodlecourseid), + ['id' => $this->moodlecourseid], 'fullname,shortname' ); @@ -612,7 +623,7 @@ public function get_new_folder_name($shortname, $longname) { $coursenameinfo = $DB->get_record( 'course', - array('id' => $this->moodlecourseid), + ['id' => $this->moodlecourseid], 'fullname,shortname' ); @@ -656,11 +667,11 @@ public function get_new_folder_name($shortname, $longname) { public function copy_panopto_content($originalcourseid) { global $USER; - $importresults = array(); + $importresults = []; $coursecopytask = new stdClass; $coursecopytask->IdProviderName = $this->instancename; - $coursecopytask->SourceCourseContexts = array($originalcourseid); + $coursecopytask->SourceCourseContexts = [$originalcourseid]; $coursecopytask->TargetCourseContext = $this->moodlecourseid; // The api call takes an array but moodle logging can't handle this well so an extra variable is needed for logging. @@ -710,8 +721,8 @@ public function copy_panopto_content($originalcourseid) { 'CURLOPT_VERBOSE' => false, 'CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_HEADER' => false, - 'CURLOPT_HTTPHEADER' => array('Content-Type: application/json', - 'Cookie: .ASPXAUTH='.$aspxauthcookie) + 'CURLOPT_HTTPHEADER' => ['Content-Type: application/json', + 'Cookie: .ASPXAUTH='.$aspxauthcookie] ]; $sockettimeout = get_config('block_panopto', 'panopto_socket_timeout'); @@ -766,8 +777,8 @@ public function copy_panopto_content($originalcourseid) { * @return array */ public function init_and_sync_import_ccv1($newimportid) { - $importresults = array(); - $handledimports = array(); + $importresults = []; + $handledimports = []; self::print_log_verbose(get_string('init_import_target', 'block_panopto', $this->moodlecourseid)); self::print_log_verbose(get_string('init_import_source', 'block_panopto', $newimportid)); @@ -788,11 +799,11 @@ public function init_and_sync_import_ccv1($newimportid) { if (!isset($importpanopto->sessiongroupid)) { self::print_log(get_string('import_not_mapped', 'block_panopto')); } else if (!isset($provisioninginfo->accesserror)) { - $sessiongroupids = array(); + $sessiongroupids = []; $sessiongroupids[] = $importpanopto->sessiongroupid; // We need to make sure this course gets access to anything the course it imported had access to. $nestedimports = self::get_import_list($newimportid); - $nestedimportresults = array(); + $nestedimportresults = []; foreach ($nestedimports as $nestedimportid) { $nestedimportpanopto = new \panopto_data($nestedimportid); // If we are importing a nested child make sure we have not already imported. @@ -940,16 +951,17 @@ public function sync_external_user($userid) { self::print_log_verbose(get_string('attempt_sync_user', 'block_panopto', $userid)); self::print_log_verbose(get_string('attempt_sync_user_server', 'block_panopto', $this->servername)); - $userinfo = $DB->get_record('user', array('id' => $userid)); + $userinfo = $DB->get_record('user', ['id' => $userid]); + $istempuser = $this->is_temp_user(isset($userinfo) ? $userinfo->username : "", isset($userinfo) ? $userinfo->email : ""); - // Only sync if we find an existing user with the given id. - if (isset($userinfo) && ($userinfo !== false)) { + // Only sync if we find an existing user with the given id, and if not temp user. + if (isset($userinfo) && ($userinfo !== false) && !$istempuser) { $instancename = get_config('block_panopto', 'instance_name'); $currentcourses = enrol_get_users_courses($userid, true); // Go through each course. - $groupstosync = array(); + $groupstosync = []; foreach ($currentcourses as $course) { $coursecontext = context_course::instance($course->id); @@ -1011,7 +1023,7 @@ public function sync_external_user($userid) { */ public static function add_new_course_import($courseid, $newimportid) { global $DB; - $rowarray = array('target_moodle_id' => $courseid, 'import_moodle_id' => $newimportid); + $rowarray = ['target_moodle_id' => $courseid, 'import_moodle_id' => $newimportid]; $currentrow = $DB->get_record('block_panopto_importmap', $rowarray); if (!$currentrow) { @@ -1032,12 +1044,12 @@ public static function get_import_list($courseid) { $courseimports = $DB->get_records( 'block_panopto_importmap', - array('target_moodle_id' => $courseid), + ['target_moodle_id' => $courseid], null, 'id,import_moodle_id' ); - $retarray = array(); + $retarray = []; if (isset($courseimports) && !empty($courseimports)) { foreach ($courseimports as $courseimport) { $retarray[] = $courseimport->import_moodle_id; @@ -1057,12 +1069,12 @@ public static function get_import_target_list($courseid) { $courseimports = $DB->get_records( 'block_panopto_importmap', - array('import_moodle_id' => $courseid), + ['import_moodle_id' => $courseid], null, 'id,target_moodle_id' ); - $retarray = array(); + $retarray = []; if (isset($courseimports) && !empty($courseimports)) { foreach ($courseimports as $courseimport) { $retarray[] = $courseimport->target_moodle_id; @@ -1078,7 +1090,7 @@ public static function get_import_target_list($courseid) { * @param string $sessionshavespecificorder session ordering */ public function get_session_list($sessionshavespecificorder) { - $sessionlist = array(); + $sessionlist = []; if ($this->servername && $this->applicationkey && $this->sessiongroupid) { $this->ensure_session_manager(); } @@ -1217,7 +1229,7 @@ public static function get_moodle_course_id($sessiongroupid) { global $DB; return $DB->get_records( 'block_panopto_foldermap', - array('panopto_id' => $sessiongroupid), + ['panopto_id' => $sessiongroupid], null, 'id,moodleid' ); @@ -1230,7 +1242,7 @@ public static function get_moodle_course_id($sessiongroupid) { */ public static function get_panopto_course_id($moodlecourseid) { global $DB; - return $DB->get_field('block_panopto_foldermap', 'panopto_id', array('moodleid' => $moodlecourseid)); + return $DB->get_field('block_panopto_foldermap', 'panopto_id', ['moodleid' => $moodlecourseid]); } /** @@ -1240,7 +1252,7 @@ public static function get_panopto_course_id($moodlecourseid) { */ public static function get_panopto_servername($moodlecourseid) { global $DB; - return $DB->get_field('block_panopto_foldermap', 'panopto_server', array('moodleid' => $moodlecourseid)); + return $DB->get_field('block_panopto_foldermap', 'panopto_server', ['moodleid' => $moodlecourseid]); } /** @@ -1281,13 +1293,13 @@ public function check_course_role_mappings() { public static function get_course_role_mappings($moodlecourseid) { global $DB; - $pubroles = array(); - $creatorroles = array(); + $pubroles = []; + $creatorroles = []; // Get creator roles as an array. $creatorrolesraw = $DB->get_records( 'block_panopto_creatormap', - array('moodle_id' => $moodlecourseid), + ['moodle_id' => $moodlecourseid], 'id,role_id' ); @@ -1300,7 +1312,7 @@ public static function get_course_role_mappings($moodlecourseid) { // Get publisher roles as an array. $pubrolesraw = $DB->get_records( 'block_panopto_publishermap', - array('moodle_id' => $moodlecourseid), + ['moodle_id' => $moodlecourseid], 'id,role_id' ); @@ -1310,7 +1322,7 @@ public static function get_course_role_mappings($moodlecourseid) { } } - return array('publisher' => $pubroles, 'creator' => $creatorroles); + return ['publisher' => $pubroles, 'creator' => $creatorroles]; } /** @@ -1325,14 +1337,14 @@ public static function get_course_role_mappings($moodlecourseid) { */ public static function set_course_foldermap($moodlecourseid, $sessiongroupid, $servername, $appkey, $externalcourseid) { global $DB; - $row = (object) array( + $row = (object) [ 'moodleid' => $moodlecourseid, 'panopto_id' => $sessiongroupid, 'panopto_server' => $servername, 'panopto_app_key' => $appkey - ); + ]; - $oldrecord = $DB->get_record('block_panopto_foldermap', array('moodleid' => $moodlecourseid)); + $oldrecord = $DB->get_record('block_panopto_foldermap', ['moodleid' => $moodlecourseid]); if ($oldrecord) { $row->id = $oldrecord->id; @@ -1351,15 +1363,15 @@ public static function set_course_foldermap($moodlecourseid, $sessiongroupid, $s */ public static function set_panopto_course_id($moodlecourseid, $sessiongroupid) { global $DB; - if ($DB->get_records('block_panopto_foldermap', array('moodleid' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_foldermap', ['moodleid' => $moodlecourseid])) { return $DB->set_field( 'block_panopto_foldermap', 'panopto_id', $sessiongroupid, - array('moodleid' => $moodlecourseid) + ['moodleid' => $moodlecourseid] ); } else { - $row = (object) array('moodleid' => $moodlecourseid, 'panopto_id' => $sessiongroupid); + $row = (object) ['moodleid' => $moodlecourseid, 'panopto_id' => $sessiongroupid]; return $DB->insert_record('block_panopto_foldermap', $row); } } @@ -1372,15 +1384,15 @@ public static function set_panopto_course_id($moodlecourseid, $sessiongroupid) { */ public static function set_panopto_server_name($moodlecourseid, $panoptoservername) { global $DB; - if ($DB->get_records('block_panopto_foldermap', array('moodleid' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_foldermap', ['moodleid' => $moodlecourseid])) { return $DB->set_field( 'block_panopto_foldermap', 'panopto_server', $panoptoservername, - array('moodleid' => $moodlecourseid) + ['moodleid' => $moodlecourseid] ); } else { - $row = (object) array('moodleid' => $moodlecourseid, 'panopto_server' => $panoptoservername); + $row = (object) ['moodleid' => $moodlecourseid, 'panopto_server' => $panoptoservername]; return $DB->insert_record('block_panopto_foldermap', $row); } } @@ -1393,15 +1405,15 @@ public static function set_panopto_server_name($moodlecourseid, $panoptoserverna */ public static function set_panopto_app_key($moodlecourseid, $panoptoappkey) { global $DB; - if ($DB->get_records('block_panopto_foldermap', array('moodleid' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_foldermap', ['moodleid' => $moodlecourseid])) { return $DB->set_field( 'block_panopto_foldermap', 'panopto_app_key', $panoptoappkey, - array('moodleid' => $moodlecourseid) + ['moodleid' => $moodlecourseid] ); } else { - $row = (object) array('moodleid' => $moodlecourseid, 'panopto_app_key' => $panoptoappkey); + $row = (object) ['moodleid' => $moodlecourseid, 'panopto_app_key' => $panoptoappkey]; return $DB->insert_record('block_panopto_foldermap', $row); } } @@ -1417,21 +1429,21 @@ public static function set_course_role_mappings($moodlecourseid, $publisherroles global $DB; // Delete all old records to prevent non-existant mapping staying when they shouldn't. - $DB->delete_records('block_panopto_publishermap', array('moodle_id' => $moodlecourseid)); + $DB->delete_records('block_panopto_publishermap', ['moodle_id' => $moodlecourseid]); foreach ($publisherroles as $pubrole) { if (!empty($pubrole)) { - $row = (object) array('moodle_id' => $moodlecourseid, 'role_id' => $pubrole); + $row = (object) ['moodle_id' => $moodlecourseid, 'role_id' => $pubrole]; $DB->insert_record('block_panopto_publishermap', $row); } } // Delete all old records to prevent non-existant mapping staying when they shouldn't. - $DB->delete_records('block_panopto_creatormap', array('moodle_id' => $moodlecourseid)); + $DB->delete_records('block_panopto_creatormap', ['moodle_id' => $moodlecourseid]); foreach ($creatorroles as $creatorrole) { if (!empty($creatorrole)) { - $row = (object) array('moodle_id' => $moodlecourseid, 'role_id' => $creatorrole); + $row = (object) ['moodle_id' => $moodlecourseid, 'role_id' => $creatorrole]; $DB->insert_record('block_panopto_creatormap', $row); } } @@ -1446,8 +1458,8 @@ public static function set_course_role_mappings($moodlecourseid, $publisherroles */ public static function delete_panopto_relation($moodlecourseid, $movetoinactivetable) { global $DB; - $deletedrecords = array(); - $existingrecords = $DB->get_records('block_panopto_foldermap', array('moodleid' => $moodlecourseid)); + $deletedrecords = []; + $existingrecords = $DB->get_records('block_panopto_foldermap', ['moodleid' => $moodlecourseid]); if ($existingrecords) { if ($movetoinactivetable) { $DB->insert_records('block_panopto_old_foldermap', $existingrecords); @@ -1455,37 +1467,37 @@ public static function delete_panopto_relation($moodlecourseid, $movetoinactivet $deletedrecords['foldermap'] = $DB->delete_records( 'block_panopto_foldermap', - array('moodleid' => $moodlecourseid) + ['moodleid' => $moodlecourseid] ); } // Clean up any creator role mappings. - if ($DB->get_records('block_panopto_creatormap', array('moodle_id' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_creatormap', ['moodle_id' => $moodlecourseid])) { $DB->delete_records( 'block_panopto_creatormap', - array('moodle_id' => $moodlecourseid) + ['moodle_id' => $moodlecourseid] ); } // Clean up any publisher role mappings. - if ($DB->get_records('block_panopto_publishermap', array('moodle_id' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_publishermap', ['moodle_id' => $moodlecourseid])) { $DB->delete_records( 'block_panopto_publishermap', - array('moodle_id' => $moodlecourseid) + ['moodle_id' => $moodlecourseid] ); } - if ($DB->get_records('block_panopto_importmap', array('target_moodle_id' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_importmap', ['target_moodle_id' => $moodlecourseid])) { $deletedrecords['imports'] = $DB->delete_records( 'block_panopto_importmap', - array('target_moodle_id' => $moodlecourseid) + ['target_moodle_id' => $moodlecourseid] ); } - if ($DB->get_records('block_panopto_importmap', array('import_moodle_id' => $moodlecourseid))) { + if ($DB->get_records('block_panopto_importmap', ['import_moodle_id' => $moodlecourseid])) { $deletedrecords['exports'] = $DB->delete_records( 'block_panopto_importmap', - array('import_moodle_id' => $moodlecourseid) + ['import_moodle_id' => $moodlecourseid] ); } @@ -1513,7 +1525,7 @@ public function get_course_options() { global $DB; $panoptofolders = $this->get_creator_folders_list(); - $options = array(); + $options = []; $containsmappedfolder = false; if (!empty($panoptofolders)) { @@ -1538,7 +1550,7 @@ public function get_course_options() { ? $folderinfo->IsAssignmentFolder : false; - if ((!$DB->get_records('block_panopto_foldermap', array('panopto_id' => $folderinfo->Id)) + if ((!$DB->get_records('block_panopto_foldermap', ['panopto_id' => $folderinfo->Id]) || ($this->sessiongroupid === $folderinfo->Id)) && !$isassignmentfolder) { @@ -1558,13 +1570,13 @@ public function get_course_options() { if (empty($options)) { if (isset($panoptofolders) && empty($this->sessiongroupid)) { - $options = array('Error' => '-- No Courses Available --'); + $options = ['Error' => '-- No Courses Available --']; } else if (!isset($panoptofolders) && empty($this->sessiongroupid)) { - $options = array('Error' => '-- Unable to retrieve course list --'); + $options = ['Error' => '-- Unable to retrieve course list --']; } } - return array('courses' => $options, 'selected' => $this->sessiongroupid); + return ['courses' => $options, 'selected' => $this->sessiongroupid]; } /** @@ -1575,7 +1587,7 @@ public function get_course_options() { * @return array */ public static function build_capability_to_roles($roles, $capability) { - $assigncaps = array(); + $assigncaps = []; foreach ($roles as $role) { if (isset($role) && trim($role) !== '') { $assigncaps[$role] = $capability; @@ -1598,13 +1610,13 @@ public static function build_and_assign_context_capability_to_roles($context, $r $processed = false; $assigned = self::build_capability_to_roles($roles, $capability); - $existing = array(); + $existing = []; // Extract the existing capabilities that have been assigned for context, role and capability. foreach ($roles as $roleid) { // Only query the DB if $roleid is not null. if ($roleid && $DB->record_exists('role_capabilities', - array('contextid' => $context->id, 'roleid' => $roleid, 'capability' => $capability))) { + ['contextid' => $context->id, 'roleid' => $roleid, 'capability' => $capability])) { $existing[$roleid] = $capability; } } @@ -1764,8 +1776,8 @@ public function is_folder_inheriting_permissions($folderid) { 'CURLOPT_VERBOSE' => false, 'CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_HEADER' => false, - 'CURLOPT_HTTPHEADER' => array('Content-Type: application/json', - 'Cookie: .ASPXAUTH='.$aspxauthcookie) + 'CURLOPT_HTTPHEADER' => ['Content-Type: application/json', + 'Cookie: .ASPXAUTH='.$aspxauthcookie] ]; $sockettimeout = get_config('block_panopto', 'panopto_socket_timeout'); @@ -1814,7 +1826,23 @@ public function get_cm_for_course($courseid) { "JOIN {lti} m ON (m.id = cm.instance) " . "WHERE md.name = :name AND cm.course = :course"; return $DB->get_records_sql($sql, - array('name' => 'lti', 'course' => $courseid)); + ['name' => 'lti', 'course' => $courseid]); + } + + /** + * Check if username format is from a temp user. + * + * @param string $username User name + * @param string $email User email + */ + public function is_temp_user($username, $email) { + // Match the following pattern for username "adfake@panopto.com.1690123065". + // Temp users are expected to have a GUID instead of a valid email address. + $usernamepattern = '/^([a-zA-Z0-9._%+-]+)@[a-zA-Z0-9.-]+\.\d+$/'; + $isinvalidemail = filter_var($email, FILTER_VALIDATE_EMAIL) === false; + $matchesusernamepattern = preg_match($usernamepattern, $username) === 1; + + return $isinvalidemail && $matchesusernamepattern; } /** diff --git a/lib/panopto_session_soap_client.php b/lib/panopto_session_soap_client.php index 5774e30..5d0ee69 100644 --- a/lib/panopto_session_soap_client.php +++ b/lib/panopto_session_soap_client.php @@ -162,11 +162,11 @@ public function provision_external_course_with_roles($fullname, $externalcoursei $this->sessionmanagementserviceprovision = new SessionManagementServiceProvision($this->serviceparams); } - $rolestoensure = array( + $rolestoensure = [ "Viewer", "Creator", "Publisher" - ); + ]; $rolelist = new SessionManagementStructArrayOfAccessRole($rolestoensure); $provisionparams = new SessionManagementStructProvisionExternalCourseWithRoles( @@ -201,16 +201,16 @@ public function set_external_course_access_for_roles($fullname, $externalcoursei } if (!is_array($folderids)) { - $folderids = array($folderids); + $folderids = [$folderids]; } $folderidlist = new SessionManagementStructArrayOfguid($folderids); - $rolestoensure = array( + $rolestoensure = [ "Viewer", "Creator", "Publisher" - ); + ]; $rolelist = new SessionManagementStructArrayOfAccessRole($rolestoensure); $courseaccessparams = new SessionManagementStructSetExternalCourseAccessForRoles( @@ -246,16 +246,16 @@ public function set_copied_external_course_access_for_roles($fullname, $external } if (!is_array($folderids)) { - $folderids = array($folderids); + $folderids = [$folderids]; } $folderidlist = new SessionManagementStructArrayOfguid($folderids); - $rolestoensure = array( + $rolestoensure = [ "Viewer", "Creator", "Publisher" - ); + ]; $rolelist = new SessionManagementStructArrayOfAccessRole($rolestoensure); $copiedaccessparams = new SessionManagementStructSetCopiedExternalCourseAccessForRoles( @@ -289,7 +289,7 @@ public function get_folders_by_id($folderids) { } if (!is_array($folderids)) { - $folderids = array($folderids); + $folderids = [$folderids]; } $folderidlist = new SessionManagementStructArrayOfguid($folderids); @@ -317,7 +317,7 @@ public function get_folders_by_external_id($folderids) { } if (!is_array($folderids)) { - $folderids = array($folderids); + $folderids = [$folderids]; } $folderidlist = new SessionManagementStructArrayOfstring($folderids); @@ -415,7 +415,7 @@ public function get_creator_folders_list() { } } else if ($totalresults === 0) { // In this case folderlist will be null but that is handled poorly in the UI. - $folderlist = array(); + $folderlist = []; } return $folderlist; @@ -492,7 +492,8 @@ public function get_extended_creator_folders_list() { if ($this->sessionmanagementserviceget->GetExtendedCreatorFoldersList($folderlistparams)) { $retobj = $this->sessionmanagementserviceget->getResult(); - $folderlist = array_merge($folderlist, $retobj->GetExtendedCreatorFoldersListResult->Results->ExtendedFolder); + $folderlist = + array_merge($folderlist, $retobj->GetExtendedCreatorFoldersListResult->Results->ExtendedFolder); } else { return $this->handle_error( $this->sessionmanagementserviceget->getLastError()['SessionManagementServiceGet::GetCreatorFoldersList'] @@ -504,7 +505,7 @@ public function get_extended_creator_folders_list() { } } else if ($totalresults === 0) { // In this case folderlist will be null but that is handled poorly in the UI. - $folderlist = array(); + $folderlist = []; } return $folderlist; @@ -621,11 +622,11 @@ public function get_session_list($folderid, $sessionshavespecificorder) { : SessionManagementEnumSessionSortField::VALUE_DATE; $sortincreasing = $sessionshavespecificorder; $states = new SessionManagementStructArrayOfSessionState( - array( + [ SessionManagementEnumSessionState::VALUE_BROADCASTING, SessionManagementEnumSessionState::VALUE_COMPLETE, SessionManagementEnumSessionState::VALUE_RECORDING - ) + ] ); $sessionrequest = new SessionManagementStructListSessionsRequest( diff --git a/lib/panopto_timeout_soap_client.php b/lib/panopto_timeout_soap_client.php index 603f1c8..e7916cc 100644 --- a/lib/panopto_timeout_soap_client.php +++ b/lib/panopto_timeout_soap_client.php @@ -128,7 +128,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = f $lastresponseheaders = $this->__getLastResponseHeaders(); preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $lastresponseheaders, $matches); - $this->panoptocookies = array(); + $this->panoptocookies = []; foreach ($matches[1] as $item) { parse_str($item, $cookie); $this->panoptocookies = array_merge($this->panoptocookies, $cookie); @@ -140,8 +140,8 @@ public function __doRequest($request, $location, $action, $version, $one_way = f 'CURLOPT_VERBOSE' => false, 'CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_HEADER' => true, - 'CURLOPT_HTTPHEADER' => array('Content-Type: text/xml', - 'SoapAction: ' . $action) + 'CURLOPT_HTTPHEADER' => ['Content-Type: text/xml', + 'SoapAction: ' . $action] ]; if (!is_null($this->socket_timeout)) { @@ -161,14 +161,16 @@ public function __doRequest($request, $location, $action, $version, $one_way = f } // Depending on Moodle settings Moodle will not include connect headers in the header size. This will break all curl calls from here. - $options['CURLOPT_SUPPRESS_CONNECT_HEADERS'] = 0; + if (defined('CURLOPT_SUPPRESS_CONNECT_HEADERS')) { + $options['CURLOPT_SUPPRESS_CONNECT_HEADERS'] = 0; + } $response = $curl->post($location, $request, $options); // Get cookies. $actualresponseheaders = (isset($curl->info["header_size"])) ? substr($response, 0, $curl->info["header_size"]) : ""; preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $actualresponseheaders, $matches); - $this->panoptocookies = array(); + $this->panoptocookies = []; foreach ($matches[1] as $item) { parse_str($item, $cookie); $this->panoptocookies = array_merge($this->panoptocookies, $cookie); diff --git a/panopto_content.php b/panopto_content.php index d8b8ed1..896ebe2 100644 --- a/panopto_content.php +++ b/panopto_content.php @@ -35,7 +35,7 @@ try { $courseid = required_param('courseid', PARAM_INT); - $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); require_login($course); require_sesskey(); header('Content-Type: text/html; charset=utf-8'); @@ -59,9 +59,9 @@ ($allowautoprovision == 'onblockview')) { $task = new \block_panopto\task\provision_course(); - $task->set_custom_data(array( + $task->set_custom_data([ 'courseid' => $courseid - )); + ]); try { $task->execute(); @@ -120,7 +120,7 @@ // Get all Completed. $sessionlist = $panoptodata->get_session_list($courseinfo->DeliveriesHaveSpecifiedOrder); - $livesessions = array(); + $livesessions = []; if (is_array($sessionlist) && !empty($sessionlist)) { foreach ($sessionlist as $sessionobj) { diff --git a/provision_course.php b/provision_course.php index f19a337..8fedad8 100644 --- a/provision_course.php +++ b/provision_course.php @@ -36,8 +36,8 @@ global $courses; // Populate list of servernames to select from. -$aserverarray = array(); -$appkeyarray = array(); +$aserverarray = []; +$appkeyarray = []; $numservers = get_config('block_panopto', 'server_number'); $numservers = isset($numservers) ? $numservers : 0; @@ -101,7 +101,7 @@ // Course context. require_capability('block/panopto:provision_course', $context); - $courses = array($courseidparam); + $courses = [$courseidparam]; $editcourseurl = new moodle_url($returnurl); $PAGE->navbar->add(get_string('pluginname', 'block_panopto'), $editcourseurl); } else { diff --git a/provision_course_internal.php b/provision_course_internal.php index ca369fe..ca4ebc2 100644 --- a/provision_course_internal.php +++ b/provision_course_internal.php @@ -36,8 +36,8 @@ global $courses; // Populate list of servernames to select from. -$aserverarray = array(); -$appkeyarray = array(); +$aserverarray = []; +$appkeyarray = []; $numservers = get_config('block_panopto', 'server_number'); $numservers = isset($numservers) ? $numservers : 0; diff --git a/reinitialize_imports.php b/reinitialize_imports.php index e3f9659..1a1237d 100644 --- a/reinitialize_imports.php +++ b/reinitialize_imports.php @@ -91,7 +91,7 @@ function reinitialize_all_imports() { $courseimports = $DB->get_records('block_panopto_importmap'); - $coursepanoptoarray = array(); + $coursepanoptoarray = []; \panopto_data::print_log(get_string('begin_reinitializing_imports', 'block_panopto')); @@ -102,7 +102,7 @@ function reinitialize_all_imports() { if (!isset($coursepanoptoarray[$courseimport->target_moodle_id])) { $targetpanopto = new \panopto_data($courseimport->target_moodle_id); - $targetmoodlecourse = $DB->get_record('course', array('id' => $courseimport->target_moodle_id)); + $targetmoodlecourse = $DB->get_record('course', ['id' => $courseimport->target_moodle_id]); $targetcourseexists = isset($targetmoodlecourse) && $targetmoodlecourse !== false; $hasvalidpanoptodata = isset($targetpanopto->servername) && !empty($targetpanopto->servername) && diff --git a/settings.php b/settings.php index 93b8ed0..d048604 100644 --- a/settings.php +++ b/settings.php @@ -87,7 +87,7 @@ // The next setting requires a Panopto server and appkey combo to be properly set. if (!isset($targetserverarray) || empty($targetserverarray)) { - $targetserverarray = array(get_string('add_a_panopto_server', 'block_panopto')); + $targetserverarray = [get_string('add_a_panopto_server', 'block_panopto')]; } $settings->add( @@ -190,6 +190,17 @@ ) ); + $possiblecopyprovisiontypes = \panopto_data::getpossiblecopyprovisiontypes(); + $settings->add( + new admin_setting_configselect( + 'block_panopto/provisioning_during_copy', + get_string('block_panopto_copy_provision', 'block_panopto'), + get_string('block_panopto_copy_provision_desc', 'block_panopto'), + 'both', + $possiblecopyprovisiontypes + ) + ); + $settings->add( new admin_setting_configcheckbox( 'block_panopto/auto_insert_lti_link_to_new_courses', @@ -264,7 +275,7 @@ 'block_panopto/publisher_system_role_mapping', get_string('block_panopto_publisher_system_role_mapping', 'block_panopto'), get_string('block_panopto_publisher_system_role_mapping_desc', 'block_panopto'), - array(), + [], $systemrolearray ); $systempublishersetting->set_updatedcallback('panopto_update_system_publishers'); @@ -279,7 +290,7 @@ 'block_panopto/publisher_role_mapping', get_string('block_panopto_publisher_mapping', 'block_panopto'), get_string('block_panopto_publisher_mapping_desc', 'block_panopto'), - array(), + [], $courserolearray ) ); @@ -289,7 +300,7 @@ 'block_panopto/creator_role_mapping', get_string('block_panopto_creator_mapping', 'block_panopto'), get_string('block_panopto_creator_mapping_desc', 'block_panopto'), - array(3, 4), + [3, 4], $courserolearray ) ); diff --git a/unprovision_course.php b/unprovision_course.php index 6730162..a3144ee 100644 --- a/unprovision_course.php +++ b/unprovision_course.php @@ -69,7 +69,7 @@ // Course context. require_capability('block/panopto:provision_course', $context); - $courses = array($courseidparam); + $courses = [$courseidparam]; $editcourseurl = new moodle_url($returnurl); $PAGE->navbar->add(get_string('pluginname', 'block_panopto'), $editcourseurl); } else { diff --git a/version.php b/version.php index 12e8036..3b1c58b 100644 --- a/version.php +++ b/version.php @@ -29,14 +29,14 @@ // Plugin version should normally be the same as the internal version. // If an admin wants to install with an older version number, however, set that here. -$plugin->version = 2023091800; +$plugin->version = 2024012500; -// Requires this Moodle version - 2.7. -$plugin->requires = 2014051200; +// Requires this Moodle version - 4.1.0. +$plugin->requires = 2022112800; $plugin->cron = 0; $plugin->component = 'block_panopto'; $plugin->maturity = MATURITY_STABLE; -$plugin->dependencies = array( +$plugin->dependencies = [ 'mod_forum' => ANY_VERSION -); +]; /* End of file version.php */ diff --git a/yui/asyncload/asyncload.js b/yui/asyncload/asyncload.js index 5602abb..7b0fb77 100644 --- a/yui/asyncload/asyncload.js +++ b/yui/asyncload/asyncload.js @@ -1,60 +1,77 @@ -YUI.add('moodle-block_panopto-asyncload', - function(Y) { - +/* global YUI */ +YUI.add( + "moodle-block_panopto-asyncload", + function (Y) { + // eslint-disable-next-line camelcase M.block_panopto = M.block_panopto || {}; M.block_panopto.asyncload = { - init: function(params) { - + init: function (params) { // Find the div containing the Panotpo block's content. - var mynode = Y.one('#' + params.id); + var mynode = Y.one("#" + params.id); if (mynode) { - // Execute on DOM load. - Y.on('domready', function() { - var ioconfig = { - method: 'POST', - sync: false, - timeout: 60000, - data: { - 'sesskey': M.cfg.sesskey, - 'courseid': params.courseid - }, - on: { - success: function(id, o) { - try { - // Remove loading text. - mynode.removeChild(Y.one('#loading_text')); - // Add Panopto content to block display. - mynode.set('innerHTML', o.responseText); - } catch (err) { - Y.log(err.message); - } + Y.on( + "domready", + function () { + var ioconfig = { + method: "POST", + sync: false, + timeout: 60000, + data: { + sesskey: M.cfg.sesskey, + courseid: params.courseid, }, - failure: function(id, o) { - try { - // Remove loading text. - mynode.removeChild(Y.one('#loading_text')); - // Display error in block. - mynode.set('innerHTML', o.responseText); - } catch(err) { - Y.log(err.message); - } - } - } - - }; - - Y.io(M.cfg.wwwroot + '/blocks/panopto/panopto_content.php', ioconfig); + on: { + success: function (id, o) { + try { + // Remove loading text. + mynode.removeChild( + Y.one("#loading_text") + ); + // Add Panopto content to block display. + mynode.set( + "innerHTML", + o.responseText + ); + } catch (err) { + Y.log(err.message); + } + }, + failure: function (id, o) { + try { + // Remove loading text. + mynode.removeChild( + Y.one("#loading_text") + ); + // Display error in block. + mynode.set( + "innerHTML", + o.responseText + ); + } catch (err) { + Y.log(err.message); + } + }, + }, + }; - }, [], false); + Y.io( + M.cfg.wwwroot + + "/blocks/panopto/panopto_content.php", + ioconfig + ); + }, + [], + false + ); } else { - Y.log('Couldn\'t find element with id: ' + params.id); + Y.log("Couldn't find element with id: " + params.id); } - - } + }, }; - - }, '@VERSION@', {requires: ['console', 'node', 'io-base', 'querystring-stringify-simple']} + }, + "@VERSION@", + { requires: ["console", "node", "io-base", "querystring-stringify-simple"] } );