diff --git a/classes/api.php b/classes/api.php index 7cd5be3..9cf5cc5 100644 --- a/classes/api.php +++ b/classes/api.php @@ -125,7 +125,7 @@ public function get_auth_token() { } else if ($token !== '' && $now <= $expiretime) { mtrace('Token is valid.'); - //define url for the next function + // Define url for the next function. $url = get_config('tool_opensesame', 'baseurl') . '/v1/content?customerIntegrationId=' . get_config('tool_opensesame', 'customerintegrationid') . '&limit=10'; $this->get_open_sesame_course_list($token, $url); @@ -160,13 +160,13 @@ public function add_open_sesame_course($osdataobject, $token) { $stringcategories = $osdataobject->oscategories; - //php compare each array elements choose the element that has the most items in it. + // PHP compare each array elements choose the element that has the most items in it. $result = []; $string = $stringcategories; $firstdimension = explode(',', $string); // Divide by , symbol foreach ($firstdimension as $temp) { - // Take each result of division and explode it by , symbol and save to result + // Take each result of division and explode it by , symbol and save to result. $pos = strpos($temp, '|'); if ($pos !== false) { $newtemp = substr_replace($temp, '', $pos, strlen('|')); @@ -209,10 +209,10 @@ public function add_open_sesame_course($osdataobject, $token) { $this->create_course_image($courseid, $thumbnailurl); $scormpackagedownloadurl = $osdataobject->packagedownloadurl; $allowedtype = get_config('tool_opensesame', 'allowedtypes'); - if($allowedtype == SCORM_TYPE_LOCAL){ + if ($allowedtype == SCORM_TYPE_LOCAL) { $this->get_open_sesame_scorm_package($token, $scormpackagedownloadurl, $courseid); } - if ($allowedtype == SCORM_TYPE_AICCURL){ + if ($allowedtype == SCORM_TYPE_AICCURL) { $this->get_open_sesame_scorm_package($token, $aicclaunchurl, $courseid); } @@ -241,7 +241,7 @@ public function determineurl(&$paging) { public function get_open_sesame_course_list($token, $url) { global $DB; - //Integrator issues request with access token + // Integrator issues request with access token. $this->setHeader(['content_type: application/json', sprintf('Authorization: Bearer %s', $token)]); $response = $this->get($url); $statuscode = $this->get_http_code(); @@ -308,9 +308,9 @@ public function create_course_image($courseid, $thumbnailurl) { 'filepath' => '/', // Any path beginning and ending in /. 'filename' => 'courseimage' . $courseid . '.jpg', // Any filename. ]; - //create course image + // Create course image. $fs = get_file_storage(); - //make sure there is not an image file to prevent an image file conflict + // Make sure there is not an image file to prevent an image file conflict. $fs->delete_area_files($context->id, 'course', 'overviewfiles', 0); // Create a new file containing the text 'hello world'. $fs->create_file_from_url($fileinfo, $thumbnailurl); @@ -320,7 +320,7 @@ public function get_open_sesame_scorm_package($token, $scormpackagedownloadurl, mtrace('calling get_open_sesame_scorm_package'); global $CFG, $USER; require_once($CFG->dirroot . '/lib/filestorage/file_storage.php'); - //Integrator issues request with access token + // Integrator issues request with access token. $this->setHeader([sprintf('Authorization: Bearer %s', $token)]); $url = $scormpackagedownloadurl . '?standard=scorm'; @@ -329,9 +329,9 @@ public function get_open_sesame_scorm_package($token, $scormpackagedownloadurl, $filename = 'scorm_' . $courseid . '.zip'; $path = $CFG->tempdir . '/filestorage/' . $filename; - //Download to temp directory + // Download to temp directory. download_file_content($url, $headers, null, true, 300, 20, false, $path, false); - //create a file from temporary folder in the user file draft area + // Create a file from temporary folder in the user file draft area. $context = context_course::instance($courseid); $fs = get_file_storage(); @@ -343,15 +343,15 @@ public function get_open_sesame_scorm_package($token, $scormpackagedownloadurl, 'filepath' => '/', // Any path beginning and ending in /. 'filename' => $filename, // Any filename. ]; - //clear file area + // Clear file area. $fs->delete_area_files($context->id, 'mod_scorm', 'package', 0); // Create a new file scorm.zip package inside of course. $fs->create_file_from_pathname($fileinfo, $path); - //create a new user draft file from mod_scorm package + // Create a new user draft file from mod_scorm package. // Get an unused draft itemid which will be used $draftitemid = file_get_submitted_draft_itemid('packagefile'); - // Copy the existing files which were previously uploaded into the draft area + // Copy the existing files which were previously uploaded into the draft area. file_prepare_draft_area( $draftitemid, $context->id, 'mod_scorm', 'package', 0); $modinfo = get_fast_modinfo($courseid); @@ -372,9 +372,9 @@ public function create_course_scorm_mod($courseid, $draftitemid) { require_once($CFG->dirroot . '/mod/scorm/mod_form.php'); require_once($CFG->dirroot . '/completion/criteria/completion_criteria.php'); - //get course + // Get course. $course = $DB->get_record('course', ['id' => $courseid]); - //check course for modules + // Check course for modules. $modscorm = 19; @@ -384,7 +384,7 @@ public function create_course_scorm_mod($courseid, $draftitemid) { ['course' => $courseid, 'module' => $modscorm], $strictness = IGNORE_MISSING ); - //found a course module scorm for this course update the activity + // Found a course module scorm for this course update the activity. if ($cmid && $cmid !== null) { $update = $cmid; // Check the course module exists. @@ -405,13 +405,13 @@ public function create_course_scorm_mod($courseid, $draftitemid) { $cm->instance, $cm->id); mtrace('preparing course scorm mod'); - //below returns an array of $cm , $moduleinfo + // Below returns an array of $cm , $moduleinfo. update_moduleinfo($cm, $moduleinfo, $course); } - //only add a course module if none exist + // Only add a course module if none exist if (!$cmid) { - //create top course section + // Create top course section. $section = 0; $sectionreturn = 0; $add = 'scorm'; @@ -449,14 +449,14 @@ public function get_default_modinfo($courseid, $draftitemid, $module, $add = '0' = null, $coursemodule = null) { global $CFG; $moduleinfo = new \stdClass(); - //$moduleinfo->name is required + $moduleinfo->name = 'scorm_' . $courseid; $moduleinfo->introeditor = ['text' => '', 'format' => '1', 'itemid' => '']; $moduleinfo->showdescription = 0; $moduleinfo->mform_isexpanded_id_packagehdr = 1; require_once($CFG->dirroot . '/mod/scorm/lib.php'); - //change scorm type depending on setting in config file default is SCORM_TYPE_LOCAL alternative option is SCORM_TYPE_AICCURL. + // Change scorm type depending on setting in config file default is SCORM_TYPE_LOCAL alternative option is SCORM_TYPE_AICCURL. $moduleinfo->scormtype = get_config('tool_opensesame', 'allowedtypes'); @@ -465,7 +465,7 @@ public function get_default_modinfo($courseid, $draftitemid, $module, $add = '0' } $moduleinfo->packagefile = $draftitemid; - //update frequency is daily; + // Update frequency is daily. $moduleinfo->updatefreq = 2; $moduleinfo->popup = 0; $moduleinfo->width = 100; @@ -509,7 +509,7 @@ public function get_aicc_url($courseid){ public function set_self_enrollment($courseid, $active) { mtrace('calling set_self_enrollment'); global $DB; - // get enrollment plugin + // Get enrollment plugin. $instance = $DB->get_record('enrol', ['courseid' => $courseid, 'enrol' => 'self']); $enrolplugin = enrol_get_plugin($instance->enrol); diff --git a/classes/task/opensesamesync.php b/classes/task/opensesamesync.php index cf5459c..8c57e49 100644 --- a/classes/task/opensesamesync.php +++ b/classes/task/opensesamesync.php @@ -18,6 +18,7 @@ use context_course; use tool_opensesame\api; +defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/lib/filelib.php'); require_once($CFG->dirroot . '/course/lib.php'); @@ -59,7 +60,7 @@ public function execute($testing = null) { * */ $api = new api; $token = $api->get_auth_token(); - //$api->get_open_sesame_course_list($token); + mtrace('opensesame just finished.'); return true; } diff --git a/db/tasks.php b/db/tasks.php index 252311b..312f5c3 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -22,18 +22,18 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -// List of tasks. +defined('MOODLE_INTERNAL') || die(); + $tasks = [ - // First task configuration. - [ - 'classname' => 'tool_opensesame\task\opensesamesync', - 'blocking' => 0, - 'minute' => '*', - 'hour' => 'R', - 'day' => '*', - 'dayofweek' => '*', - 'month' => '*' - ], - // Second task configuration. + + [ + 'classname' => 'tool_opensesame\task\opensesamesync', + 'blocking' => 0, + 'minute' => '*', + 'hour' => 'R', + 'day' => '*', + 'dayofweek' => '*', + 'month' => '*' + ], ]; diff --git a/db/upgrade.php b/db/upgrade.php index a6ade38..3153e61 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -22,8 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Upgrade the plugin. * diff --git a/index.php b/index.php deleted file mode 100644 index 12ef488..0000000 --- a/index.php +++ /dev/null @@ -1,60 +0,0 @@ -. -// -///** -// * Index.php -// * -// * @package tool -// * @subpackage opensesame -// * @copyright 2023 Felicia Wilkes -// * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later -// */ -// -//require('../../../config.php'); -////require_once($CFG->libdir . '/adminlib.php'); -////admin_externalpage_setup('toolopensesame'); -// -////protect the page -//require_login(); -////only Site admins -//if (!is_siteadmin()) { -// print_error('noprermissions', 'core'); -//} -// -////set up the page for display -//$PAGE->set_context(context_system::instance()); -//$PAGE->set_pagelayout('admin'); -//$PAGE->set_heading($SITE->fullname); -//$PAGE->set_title($SITE->fullname . ': ' . get_string('pluginname', 'tool_opensesame')); -//$PAGE->set_url('/tool/opensesame/index.php'); -//$PAGE->set_pagetype('admin-' . $PAGE->pagetype); -// -//echo $OUTPUT->header(); -//echo $OUTPUT->heading(get_string('pluginname', 'tool_opensesame')); -// -////testing opensesame task in userinterface -//$task = new \tool_opensesame\task\opensesamesync(); -// -//echo html_writer::tag('div', html_writer::tag('p', $task->get_name())); -//try { -// $task->execute(true); -//} catch (Exception $e) { -// echo $OUTPUT->notification($e->getMessage(), 'error'); -// echo $OUTPUT->footer(); -// die; -//} -//echo $OUTPUT->notification('Successfully executed.', 'success'); -//echo $OUTPUT->footer(); \ No newline at end of file diff --git a/lang/en/tool_opensesame.php b/lang/en/tool_opensesame.php index fd0de53..7edf4f0 100644 --- a/lang/en/tool_opensesame.php +++ b/lang/en/tool_opensesame.php @@ -49,4 +49,4 @@ $string['opensesameintegration'] = 'Integration Settings'; $string['pluginname'] = 'OpenSesame Integration'; $string['statuscode400'] = - '400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error'; \ No newline at end of file + '400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error'; diff --git a/settings.php b/settings.php index a17f1dd..b097216 100644 --- a/settings.php +++ b/settings.php @@ -1,4 +1,6 @@ add('courses', new admin_category('opensesameintegration', new lang_string('opensesamecat', 'tool_opensesame')), ); - // places the link to the settingspage under the new category + // Places the link to the settingspage under the new category. $settings = new admin_settingpage('tool_opensesame', get_string('opensesameintegration', 'tool_opensesame')); - //creating new settings to add the new settingspage + // Creating new settings to add the new settingspage. if (!is_array($CFG->forced_plugin_settings['tool_opensesame'])) { $settings->add(new admin_setting_configtext('tool_opensesame/clientid', get_string('clientid', 'tool_opensesame'), @@ -50,14 +52,12 @@ get_string('customerintegrationid', 'tool_opensesame'), get_string('customerintegrationiddesc', 'tool_opensesame'), '')); - // add scorm type select + // Add scorm type select. // Types allowed. - //DEF-730 BEGINNING + require_once($CFG->dirroot . '/mod/scorm/lib.php'); $options = array( - //SCORM_TYPE_LOCAL = 'local' - //SCORM_TYPE_AICCURL = 'aiccurl' - //'both' => new lang_string('localandaiccurl', 'tool_opensesame'), + SCORM_TYPE_LOCAL => new lang_string('onlylocal', 'tool_opensesame'), SCORM_TYPE_AICCURL => new lang_string('onlyaiccurl', 'tool_opensesame') ); @@ -65,7 +65,7 @@ $desc = get_string('allowedtypes_desc', 'tool_opensesame'); $default = SCORM_TYPE_LOCAL; $settings->add(new admin_setting_configselect('tool_opensesame/allowedtypes', $name, $desc, $default, $options)); - //DEF-730 END - //add to the admin settings for opensesameintegration + + // Add to the admin settings for opensesameintegration. $ADMIN->add('opensesameintegration', $settings); } diff --git a/version.php b/version.php index 81acd89..9379446 100644 --- a/version.php +++ b/version.php @@ -22,5 +22,5 @@ */ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2023013103; // The current plugin version (Date: YYYYMMDDXX). -$plugin->requires = 2020061500; // Requires this Moodle version. 3.9 +$plugin->requires = 2020061500; // Requires this Moodle version. 3.9. $plugin->component = 'tool_opensesame'; // Full name of the plugin (used for diagnostics).