diff --git a/classes/local/cmi5_connectors.php b/classes/local/cmi5_connectors.php index ed4bc2b..9e0491c 100755 --- a/classes/local/cmi5_connectors.php +++ b/classes/local/cmi5_connectors.php @@ -70,6 +70,7 @@ public function cmi5launch_get_send_request_to_cmi5_player_get() { public function cmi5launch_create_course($id, $tenanttoken, $filename) { global $DB, $CFG; + $settings = cmi5launch_settings($id); // Build URL to import course to. @@ -101,10 +102,36 @@ public function cmi5launch_create_course($id, $tenanttoken, $filename) { * @param $password - password. * @param $newtenantname - the name the new tenant will be, retreived from Tenant Name textbox. */ - public function cmi5launch_create_tenant($urltosend, $username, $password, $newtenantname) { + public function cmi5launch_create_tenant($newtenantname) { + + global $CFG, $cmi5launchid; + + $settings = cmi5launch_settings($cmi5launchid); + //$actor = $USER->username; + $username = $settings['cmi5launchbasicname']; + $playerurl = $settings['cmi5launchplayerurl']; + $password = $settings['cmi5launchbasepass']; global $CFG; + // Build URL for launch URL request. + $url = $playerurl . "/api/v1/tenant"; + + echo "
"; + echo "basicname: " . $username; + echo "
"; + + echo "
"; + echo "password: " . $password; + echo "
"; + + echo "
"; + echo "URL: " . $url; + echo "
"; + + echo "
"; + echo "newtenantname: " . $newtenantname; + echo "
"; // The body of the request must be made as array first. $data = array( 'code' => $newtenantname); @@ -116,7 +143,7 @@ public function cmi5launch_create_tenant($urltosend, $username, $password, $newt $data = json_encode($data); // Sends the stream to the specified URL. - $result = $this->cmi5launch_send_request_to_cmi5_player_post('cmi5launch_stream_and_send', $data, $urltosend, $filetype, $username, $password); + $result = $this->cmi5launch_send_request_to_cmi5_player_post('cmi5launch_stream_and_send', $data, $url, $filetype, $username, $password); // Check result and display message if not 200. $resulttest = $this->cmi5launch_connectors_error_message($result, "creating the tenant"); @@ -125,7 +152,7 @@ public function cmi5launch_create_tenant($urltosend, $username, $password, $newt // Decode returned response into array. $returnedinfo = json_decode($result, true); - + echo"It worked"; // Return an array with tenant name and info. return $returnedinfo; } else { diff --git a/classes/local/cmi5launch_helpers.php b/classes/local/cmi5launch_helpers.php deleted file mode 100644 index f12c6ea..0000000 --- a/classes/local/cmi5launch_helpers.php +++ /dev/null @@ -1,35 +0,0 @@ -. - -/** - * Helper class. This is where I instantiate classes that help function AND unit test but need a class - * // to be mocked because stupid phpunit testing wont mock global functions - * or add methods as they are depreciated. - * - * @copyright 2023 Megan Bohland - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace mod_cmi5launch\local; - - -class cmi5launch_helpers -{ - - - - -} \ No newline at end of file diff --git a/db/install.xml b/db/install.xml index 106b457..bf944f6 100755 --- a/db/install.xml +++ b/db/install.xml @@ -89,7 +89,7 @@ - + @@ -128,7 +128,7 @@ - + diff --git a/db/upgrade.php b/db/upgrade.php index 31131c4..b833a77 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -42,6 +42,23 @@ function xmldb_cmi5launch_upgrade($oldversion) { global $DB; $dbman = $DB->get_manager(); + // Change masteryscore to number type because of decimal + if ($oldversion < 2024061115) { + + // Changing type of field masteryscore on table cmi5launch_sessions to int. + $tablesessions = new xmldb_table('cmi5launch_sessions'); + $tableaus = new xmldb_table('cmi5launch_aus'); + $field = new xmldb_field('masteryscore', XMLDB_TYPE_NUMBER, '10', null, null, null, null, 'launchmode'); + $field2 = new xmldb_field('masteryscore', XMLDB_TYPE_NUMBER, '10', null, null, null, null, 'activitytype'); + + // Launch change of type for field masteryscore in both tables. + $dbman->change_field_type($tablesessions, $field); + $dbman->change_field_type($tableaus, $field2); + // Cmi5launch savepoint reached. + upgrade_mod_savepoint(true, 2024061115, 'cmi5launch'); + } + + if ($oldversion < 2024032112) { // Define index lmsid (not unique) to be dropped form cmi5launch_sessions. diff --git a/lang/en/cmi5launch.php b/lang/en/cmi5launch.php index c45043f..b5b70e2 100755 --- a/lang/en/cmi5launch.php +++ b/lang/en/cmi5launch.php @@ -73,11 +73,16 @@ // Cmi5 grades admin. // Start Default LRS Admin Settings. -$string['cmi5launchgradesettings'] = 'Default values for cmi5 launch link activity settings'; +$string['cmi5launchgradesettings'] = 'Default values ;ppppfor cmi5 launch link activity settings'; $string['cmi5launchgradesettings_help'] = 'These are site-wide, default values used when creating a new activity. Each activity has the ability to override and provide alternative values.'; $string['othersettings'] = 'Additional settings'; +// Cmi5 settings + +// Header. +$string['cmi5launchsettingsheader'] = 'cmi5 player settings'; + // Cmi5 player root location. $string['cmi5launchplayerurl'] = 'cmi5 player URL'; $string['cmi5launchplayerurl_help'] = 'The url to communicate with cmi5 player, can include port number(e.g. http://player.example.com or http://localhost:63398). Must NOT include a trailing forward slash.'; @@ -89,13 +94,17 @@ $string['cmi5launchcontenturl_default'] = ''; // Cmi5 player credentials. -$string['cmi5launchtenantname'] = 'cmi5 player: basic username'; -$string['cmi5launchtenantname_help'] = 'The cmi5 tenant username.'; +$string['cmi5launchbasicname'] = 'cmi5 player: basic username'; +$string['cmi5launchbasicname_help'] = 'The cmi5 base username.'; +$string['cmi5launchbasicname_default'] = ''; + +$string['cmi5launchtenantname'] = 'cmi5 player: The cmi5 tenant username.'; +$string['cmi5launchtenantname_help'] = ' The tenant name attached to the token. Should only need to be used during initial setup. If for some reason the tenant name is changed a new token will need to be generated.'; $string['cmi5launchtenantname_default'] = ''; -$string['cmi5launchtenantpass'] = 'cmi5 player: basic password'; -$string['cmi5launchtenantpass_help'] = 'The cmi5 tenant password (secret).'; -$string['cmi5launchtenantpass_default'] = ''; +$string['cmi5launchbasepass'] = 'cmi5 player: basic password'; +$string['cmi5launchbasepass_help'] = 'The cmi5 base password (secret).'; +$string['cmi5launchbasepass_default'] = ''; $string['cmi5launchtenanttoken'] = 'cmi5 player: bearer token'; $string['cmi5launchtenanttoken_help'] = 'The cmi5 tenant bearer token (should be a long string).'; diff --git a/settings.php b/settings.php index e87b379..9d129df 100755 --- a/settings.php +++ b/settings.php @@ -16,7 +16,6 @@ /* For global cmi5 settings */ - /** * Defines the version of cmi5launch * @@ -30,12 +29,158 @@ */ + + defined('MOODLE_INTERNAL') || die; +use mod_cmi5launch\local\cmi5_connectors; +?> + + +fulltree) { require_once($CFG->dirroot . '/mod/cmi5launch/locallib.php'); require_once($CFG->dirroot . '/mod/cmi5launch/settingslib.php'); + // Varibale to hold answer? +$nameanswer = ""; + + +// Ok let's try to get the answer from the ajax method +if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["variableName"])) { + $receivedVariable = $_POST["variableName"]; + echo "
"; + echo" We got it ! it is ! : ". $receivedVariable; + echo " IGOT IT!"; + // Process the received variable here +// Check for answer : +/////////// maybe come back to htis if (isset($_POST['tenantbutton'])) { + + // Get the answer + // $.get('myFile.php', js_answer: answer); + // $nameanswer = $_POST['cmi5launchtenantname']; + // echo it + // echo $_POST["name"]; + $sessionhelper = new cmi5_connectors; + $maketenant = $sessionhelper->cmi5launch_get_create_tenant(); + + // $pass = $_POST['tenantbutton']; + + echo " What is recieved var : "; + echo $receivedVariable; + $newtenantname = $maketenant($receivedVariable); + + echo $nameanswer; +} +// If it's null dont use it, if its not call func +if ($nameanswer != null) { + // Call func + echo" We got it ! it is ! : ". $nameanswer; + // $maketenant = $sessionhelper->cmi5launch_get_create_tenant(); +} + // MB // From scorm grading stuff. $yesno = array(0 => get_string('no'), @@ -92,6 +237,9 @@ get_string('cmi5launchuseactoremail_help', 'cmi5launch'), 1)); + // LEt's add a new header to separate cmi5 from lrs + $settings->add(new admin_setting_heading('cmi5launch/cmi5launchsettings', get_string('cmi5launchsettingsheader', 'cmi5launch'), '')); + $settings->add(new admin_setting_configtext_mod_cmi5launch('cmi5launch/cmi5launchplayerurl', get_string('cmi5launchplayerurl', 'cmi5launch'), @@ -104,24 +252,77 @@ get_string('cmi5launchcontenturl_default', 'cmi5launch'), PARAM_URL)); */ - $setting = new admin_setting_configtext('cmi5launch/cmi5launchtenantname', - get_string('cmi5launchtenantname', 'cmi5launch'), - get_string('cmi5launchtenantname_help', 'cmi5launch'), - get_string('cmi5launchtenantname_default', 'cmi5launch')); + + $setting = new admin_setting_configtext('cmi5launch/cmi5launchbasicname', + get_string('cmi5launchbasicname', 'cmi5launch'), + get_string('cmi5launchbasicname_help', 'cmi5launch'), + get_string('cmi5launchbasicname_default', 'cmi5launch')); $settings->add($setting); - $setting = new admin_setting_configtext('cmi5launch/cmi5launchtenantpass', - get_string('cmi5launchtenantpass', 'cmi5launch'), - get_string('cmi5launchtenantpass_help', 'cmi5launch'), - get_string('cmi5launchtenantpass_default', 'cmi5launch')); + $setting = new admin_setting_configtext('cmi5launch/cmi5launchbasepass', + get_string('cmi5launchbasepass', 'cmi5launch'), + get_string('cmi5launchbasepass_help', 'cmi5launch'), + get_string('cmi5launchbasepass_default', 'cmi5launch')); $settings->add($setting); + + +$warning = "OHNO"; + // $link = "Empty all results ".$warning.""; + // $clear_url = new moodle_url('/settings.php'); + // For form action we will call new tenant or new token + // Furthe we can set them as to apperar when made either here or in those funcs being called + + // Info we need to send? + //$newtenantname; + $link = "
+

+

+ +
+

+ "; + //$link =""; + + $setting = new admin_setting_configtext( + 'cmi5launch/cmi5launchtenantname', + get_string('cmi5launchtenantname', 'cmi5launch'), + " " . get_string('cmi5launchtenantname_help', 'cmi5launch') . $link, + + get_string('cmi5launchtenantname_default', 'cmi5launch') + ); + $settings->add($setting); +/* + echo"
"; + //echo ""; + //echo"Hey it worked and I cansee receivedVariable " . $receivedVariable; + echo "What is settings? Did we change it>???? "; + $toread = $settings['cmi5launchtenantname']; + var_dump($toread); + echo "
"; +*/ + $setting = new admin_setting_configtext('cmi5launch/cmi5launchtenanttoken', get_string('cmi5launchtenanttoken', 'cmi5launch'), get_string('cmi5launchtenanttoken_help', 'cmi5launch'), get_string('cmi5launchtenanttoken_default', 'cmi5launch')); $settings->add($setting); +/* + $editstring = "I am a button"; + + $url = new moodle_url("$CFG->wwwroot/my/index.php"); + $button = $OUTPUT->single_button($url, $editstring); + $PAGE->set_button($button); + $editstring2 = "I am another button"; + + $url = new moodle_url("$CFG->wwwroot/my/index.php"); + $button = $OUTPUT->single_button($url, $editstring2); + $PAGE->set_button($button); + + */ // MB. // Grade stuff I'm bringing over. // Default grade settings. @@ -156,4 +357,15 @@ $settings->add(new admin_setting_configselect('cmi5launch/MOD_CMI5LAUNCH_LAST_ATTEMPTlock', get_string('mod_cmi5launch_last_attempt_lock', 'cmi5launch'), get_string('mod_cmi5launch_last_attempt_lockdesc', 'cmi5launch'), 0, $yesno)); -} + + + } + + + +?> +
+ + + +
diff --git a/setup.php b/setup.php new file mode 100644 index 0000000..17a7f12 --- /dev/null +++ b/setup.php @@ -0,0 +1,127 @@ +. + +/** + * This page is a setup page to compliment settings and enable a user to commuicate with cmi5 player for tenant issues. + * + * @copyright 2023 Megan Bohland + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +use mod_cmi5launch\local\cmi5_connectors; + +?> + + + +libdir.'/tablelib.php'); +require_once($CFG->dirroot.'/mod/cmi5launch/locallib.php'); +require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->dirroot. '/reportbuilder/classes/local/report/column.php'); + +define('CMI5LAUNCH_REPORT_DEFAULT_PAGE_SIZE', 20); +define('CMI5LAUNCH_REPORT_ATTEMPTS_ALL_STUDENTS', 0); +define('CMI5LAUNCH_REPORT_ATTEMPTS_STUDENTS_WITH', 1); +define('CMI5LAUNCH_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2); +$PAGE->requires->jquery(); + +global $cmi5launch, $CFG; + +// External classes and functions. +$cmi5helper = new cmi5_connectors; +$createtenant = $cmi5helper->cmi5launch_get_create_tenant(); + +// Retrieve the name entered in previous pages prompt. This will be the new tenant name. + $fromsettings = required_param('variableName', PARAM_TEXT); + +// Button to return to settings page. +$link = "
+

+

+ +
+

"; +// Ensure a name was entered. +if ($fromsettings != null) { + + // Make the new tenant and grab results. + $tenant = $createtenant($fromsettings); + + // The return response should be an array and have 'id' and 'code' + $response = $tenant; + + //Do we need an if statement for response tyopo? + $name = $response['code']; + $id = $response['id']; + + + // maybe if we make the button link thing here and then just echo it we can save on repetitive code. + // if we have a response, we can save the tenant name to the settings + if ($name != null && $id != null) { + // Save the tenant name to the settings + $result = set_config('cmi5launchtenantname', $name, $plugin = 'cmi5launch'); + + + if ($result) { + + echo "Successfully made and saved new tenant"; + echo "Tenant name: " . $name . "
"; + echo "Tenant ID: " . $id . "
"; + + //Hopefully that worked? Now back to settings + $settingurl = new moodle_url($CFG->wwwroot . '/' . 'admin/settings.php', array('section' => 'modsettingcmi5launch')); + + } else { + echo "Failed to make tenant. Check connection to player and tenant name."; + //if fail shoudl we freeze and alert user with a window towith error message + + echo $link; + } + + } else { + + echo "Tenant name not retrieved from player. Check connection."; + + echo $link; + + } +} else { + echo "Tenant name not retrieved or blank. Please try again."; + + echo $link; +} +?> + + +
+ + +
+ diff --git a/version.php b/version.php index cadec7c..e5b7f56 100755 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024032112; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2024061115; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015111000; // Requires Moodle 3.0 version. $plugin->cron = 0; // Period for cron to check this module (secs).