diff --git a/.clj-kondo/.cache/v1/lock b/.clj-kondo/.cache/v1/lock
new file mode 100644
index 0000000..e69de29
diff --git a/.lsp/.cache/db.transit.json b/.lsp/.cache/db.transit.json
new file mode 100644
index 0000000..52d4536
--- /dev/null
+++ b/.lsp/.cache/db.transit.json
@@ -0,0 +1 @@
+["^ ","~:classpath",["~#set",[]],"~:project-hash","","~:project-root","/var/www/html/moodle/mod/cmi5launch","~:kondo-config-hash","56f27dae6e4a876734bf42298a7d3dc91d05917f53c9d98543cfd410bd88afe0","~:dependency-scheme","jar","~:analysis",null,"~:analysis-checksums",["^ "],"~:project-analysis-type","~:project-and-full-dependencies","~:version",12,"~:stubs-generation-namespaces",["^1",[]]]
\ No newline at end of file
diff --git a/AUview.php b/AUview.php
index 13318ea..0e5506d 100755
--- a/AUview.php
+++ b/AUview.php
@@ -76,7 +76,7 @@
@@ -69,12 +59,15 @@ function totokenpage(){
// From scorm grading stuff.
$yesno = array(0 => get_string('no'),
1 => get_string('yes'));
-
+
// Default display settings.
$settings->add(new admin_setting_heading('cmi5launch/cmi5launchlrsfieldset',
get_string('cmi5launchlrsfieldset', 'cmi5launch'),
get_string('cmi5launchlrsfieldset_help', 'cmi5launch')));
+ // LRS settings
+ $settings->add(new admin_setting_heading('cmi5launch/cmi5lrssettings', get_string('cmi5lrssettingsheader', 'cmi5launch'), ''));
+
$settings->add(new admin_setting_configtext_mod_cmi5launch('cmi5launch/cmi5launchlrsendpoint',
get_string('cmi5launchlrsendpoint', 'cmi5launch'),
get_string('cmi5launchlrsendpoint_help', 'cmi5launch'),
@@ -121,87 +114,88 @@ function totokenpage(){
get_string('cmi5launchuseactoremail_help', 'cmi5launch'),
1));
- $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'),
- get_string('cmi5launchplayerurl_help', 'cmi5launch'),
- get_string('cmi5launchplayerurl_default', 'cmi5launch'), PARAM_URL));
-
- $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/cmi5launchbasepass',
- get_string('cmi5launchbasepass', 'cmi5launch'),
- get_string('cmi5launchbasepass_help', 'cmi5launch'),
- get_string('cmi5launchbasepass_default', 'cmi5launch'));
- $settings->add($setting);
+ // The first time user logs in there will be a button for setup.
+ $showbutton = false;
+ // If tenantname or id is false, this is a first time setup we'll have the new button.
+ $tenantid = get_config('cmi5launch', 'cmi5launchtenantid');
+ $tenantname = get_config('cmi5launch', 'cmi5launchtenantname');
+ if ($tenantid == null || $tenantid == false) {
+ $showbutton = true;
+ }
+ $settings->add(new admin_setting_heading('cmi5launch/cmi5launchsettings', get_string('cmi5launchsettingsheader', 'cmi5launch'), ''));
- // Buttons.
- $linktotenant = "
+ // We need to puck a diff thing for this button, we dont want the text baox available
+if ($showbutton) {
+ // show only a button, otherwise reg showing
+ $linktocmi5 = "
-
";
- $linktotoken = "
-
-
-
- Generate bearer token
-
-
-
- ";
- //$link ="Click me !";
-
- // Verify there is a tenant name and id. If there is, display it, if not allow them to make one.
- // Retrieves the string if there or false if not.
- $tenantname = get_config('cmi5launch', 'cmi5launchtenantname');
- $tenantid = get_config('cmi5launch', 'cmi5launchtenantid');
-
- // If niether are false.
- if ($tenantname != null && $tenantid != null) {
-
- $todisplay = "Tenant name is: " . $tenantname . ". Tenant id is: " . $tenantid . "
The tenant name and ID have been set. They cannot be changed without causing problems with existing cmi5 launch link activities. To change, plugin must be uninstalled and reinstalled.
";
- $setting = new admin_setting_description('cmi5launchtenantmessage', "cmi5launch tenant name and id:", $todisplay);
- $settings->add($setting);
-
+
+ //use this for the button instead of config text
+ $setting = new admin_setting_description('cmi5launchsetup', "
The tenant name and ID have been set. They cannot be changed without causing problems with existing cmi5 launch link activities. To change, plugin must be uninstalled and reinstalled.
";
+ $setting = new admin_setting_description('cmi5launchtenantmessage', "cmi5launch tenant name and id:", $todisplay);
+ $settings->add($setting);
- $setting=
- new admin_setting_configselect_with_lock(
- 'restore/restore_replace_keep_roles_and_enrolments',
- new lang_string('setting_keep_roles_and_enrolments', 'backup'),
- new lang_string('config_keep_roles_and_enrolments', 'backup'),
- array('value' => 0, 'locked' => 0),
- array(1 => get_string('yes'), 0 => get_string('no'))
+ // Token generate button.
+ $linktotoken = "
+
+
+
+ Generate new bearer token
+
+
+
+ ";
+ $setting = new admin_setting_configtext(
+ 'cmi5launch/cmi5launchtenanttoken',
+ get_string('cmi5launchtenanttoken', 'cmi5launch'),
+ get_string('cmi5launchtenanttoken_help', 'cmi5launch') . $linktotoken,
+ get_string('cmi5launchtenanttoken_default', 'cmi5launch')
);
- $settings->add($setting);
+ $settings->add($setting);
+
+ }
+
// MB.
// Grade stuff I'm bringing over.
@@ -241,7 +235,13 @@ function totokenpage(){
}
- ?>
+ ?>
+
+
+
+
@@ -251,4 +251,4 @@ function totokenpage(){
-
+
\ No newline at end of file
diff --git a/setupform.php b/setupform.php
new file mode 100644
index 0000000..c33b0df
--- /dev/null
+++ b/setupform.php
@@ -0,0 +1,83 @@
+.
+
+/**
+ * Page to create cmi5 connection, and tenant and token.
+ *
+ * @copyright 2023 Megan Bohland
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+// NEeded for moodle pae. sets up loabl
+require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
+// Include our class file
+require_once($CFG->dirroot.'/mod/cmi5launch/classes/local/setup_form.php');
+// Tell moodle about our page, tell it what the url is.\\
+$PAGE->set_url('/mod/cmi5launch/setupform.php');
+// Tell moodle the context, in this case the site context (it's system wide not a course or course page.)
+$PAGE->set_context(\context_system::instance());
+// Title tells what is on tab
+$PAGE->set_title(title: 'CMI5 Setup Form');
+
+// You want to initialze form in PHP before you echo to page. you dont want to rener while doing calcs
+
+// we want to display a form
+$mform = new setup_cmi5();
+
+// Form processing and displaying is done here.
+if ($mform->is_cancelled()) {
+ // If cancel was pressed, then redirect back to the settings page.
+ // in tutorial he goes back to the manage page, we will go back to settins page?
+ redirect(url: $CFG->wwwroot . '/admin/settings.php'. '?section=modsettingcmi5launch', message: "Cancelled");
+ //now he is dire ting to manage page which is equvalent to our cmi5setup page so we should redirect to that? why so many pages I wonder?
+ // redirect(url: $CFG->wwwroot . '/mod/cmi5launch/cmi5setup.php', message: 'Cancelled');
+
+} else if ($fromform = $mform->get_data()) {
+ // When the form is submitted, and the data is successfully validated,
+ // the `get_data()` function will return the data posted in the form.
+
+ // REtrieve data from form.
+ $cmi5url = $fromform->cmi5url;
+ $cmi5name = $fromform->cmi5name;
+ $cmi5password = $fromform->cmi5password;
+
+ // Save data to the database, and configure the settings.
+ $resulturl = set_config('cmi5launchplayerurl', $cmi5url, $plugin = 'cmi5launch');
+ $resultname = set_config('cmi5launchbasicname', $cmi5name, $plugin = 'cmi5launch');
+ $resultpass = set_config('cmi5launchbasepass', $cmi5password, $plugin = 'cmi5launch');
+
+
+ // As long as they are not null/false we can move on to the next form
+ if ($resulturl && $resultname && $resultpass){
+ //Move to next form
+ redirect(url: $CFG->wwwroot . '/mod/cmi5launch/tenantsetup.php', message: 'Successfully saved settings.');
+ }else{
+ // If for some reason they are null or false, then we will redirect back to the form.
+ redirect(url: $CFG->wwwroot . '/mod/cmi5launch/setupform.php', message: 'Failed to save to database. Please check database is accessable and try again.');
+
+ }
+
+};
+
+// Display page.
+echo $OUTPUT->header();
+// Display the form.
+$mform->display();
+
+echo $OUTPUT->footer();
+
+?>
diff --git a/templates/setup.mustache b/templates/setup.mustache
new file mode 100644
index 0000000..d90a1d2
--- /dev/null
+++ b/templates/setup.mustache
@@ -0,0 +1,27 @@
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see .
+}}
+{{!
+ @template mod_cmi5launch/setup
+
+
+ Example context (json):
+ {
+ }
+}}
+
+
This si the setup page
+
{{texttodisplay}}
\ No newline at end of file
diff --git a/tenantsetup.php b/tenantsetup.php
index 1300150..d429cbe 100644
--- a/tenantsetup.php
+++ b/tenantsetup.php
@@ -23,29 +23,22 @@
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');
+// Include our class file
+require_once($CFG->dirroot.'/mod/cmi5launch/classes/local/tenant_form.php');
+// Tell moodle about our page, tell it what the url is.\\
+$PAGE->set_url('/mod/cmi5launch/tenantsetup.php');
+// Tell moodle the context, in this case the site context (it's system wide not a course or course page.)
+$PAGE->set_context(\context_system::instance());
+// Title tells what is on tab
+$PAGE->set_title(title: 'Creating a tenant');
-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;
@@ -54,84 +47,88 @@ function goback(){
$cmi5helper = new cmi5_connectors;
$createtenant = $cmi5helper->cmi5launch_get_create_tenant();
-// Retrieve the name entered in previous page prompt.
-$fromsettings = required_param('variableName', PARAM_TEXT);
+// Instantiate form.
+$mform = new setup_tenant();
+
+// Form processing and displaying is done here.
+if ($mform->is_cancelled()) {
+
+ // If they cancel, redirect back to the setup page.
+ redirect(url: $CFG->wwwroot . '/mod/cmi5launch/setupform.php', message: 'Cancelled');
-// Return link/button to settings page.
- $link = "
-
-
-
- OK
-
-
- ";
+} else if ($fromform = $mform->get_data()) {
- // Maybe we can have a thing here if fromsettings equals a keyword, say token, call token making stuff.
- // after all it doesn't need input from user. but we should write a catch to warn there is no tenant
- // because it does need a tenant to make a token.
+ // Retrieve username.
+ $cmi5tenant = $fromform->cmi5tenant;
-
-if ($fromsettings != null) {
+ if ($cmi5tenant != null) {
+ // Make the new tenant and grab results.
+ // here is an aarea that could fail. Should we try catch or is that covered in the creat tenant call?
+ //TODO
+ $tenant = $createtenant($cmi5tenant);
- // Make the new tenant and grab results.
- $tenant = $createtenant($fromsettings);
+ // The return response should be json and have 'id' and 'code'
+ $response = $tenant;
- // The return response should be json and have 'id' and 'code'
- $response = $tenant;
+ // Save the code as the tenant name and ID as ID.
+ $name = $response['code'];
+ $id = $response['id'];
- // Save the code as the tenant name and ID as ID.
- $name = $response['code'];
- $id = $response['id'];
+ echo "Tenant code: " . $name . " ";
+ echo "Tenant ID: " . $id . " ";
- echo "Tenant code: " . $name . " ";
- echo "Tenant ID: " . $id . " ";
+ // check we have a tenant and is, and save them to db for later retrieval (particularly id)
+ if ($name != null && $id != null) {
- // check we have a tenant and is, and save them to db for later retrieval (particularly id)
- if ($name != null && $id != null) {
+ $result = set_config('cmi5launchtenantname', $name, $plugin = 'cmi5launch');
- $result = set_config('cmi5launchtenantname', $name, $plugin = 'cmi5launch');
-
- // But how can we save the id to DB when this page has no access to cmi5launch
- // What if te id is saved as a invisible settings?
- // Is that a thing?
- // But do we need an id? Probably not cause like...
- // It saves over itself and we don't need to keep records do we?
- // But then we would need to look it up with query right? Might be better to just save it someoien
- // Lets see if we can just make a setting here!
- $idresult = set_config('cmi5launchtenantid', $id, $plugin = 'cmi5launch');
+ $idresult = set_config('cmi5launchtenantid', $id, $plugin = 'cmi5launch');
- if($idresult && $result ){
-
- // If result is true then redirect back to settings page.
- $settingurl = new moodle_url($CFG->wwwroot . '/' . 'admin/settings.php', array('section' => 'modsettingcmi5launch'));
-
- redirect($settingurl, 'Successfully made and saved new tenant', 10);
+ if ($idresult && $result) {
+ // If result is true then redirect back to settings page.
+ // except now we dont want to redirect to settings! We want to go to
+ // The TOKEN setup form
+ // Wait, maybe it should do this automatically? Like they don't need to enter it sine we are making this make it for them, and we don't need them to
+ // press a button on a new form JUST to make a token. Lets do it behind the scenes and they can retrieve it if they want through an
+ //echo or settings page?
+// $settingurl = new moodle_url($CFG->wwwroot . '/' . 'admin/settings.php', array('section' => 'modsettingcmi5launch'));
+ redirect(url: $CFG->wwwroot . '/mod/cmi5launch/tokensetup.php', message: 'Tenant made and saved successfully');
+
+ // redirect($settingurl, 'Successfully made and saved new tenant', 10);
+
+ } else {
+ echo "Failed to save tenant to DB.";
+ echo " ";
+ echo "Tenant name: " . $name . " failed to save as setting. With result " . $result . " ";
+ //if fail shoudl we freeze and alert user with a window towith error message
+
+ echo $link;
+ }
} else {
- echo "Failed to save tenant to DB.";
- echo " ";
- echo "Tenant name: " . $name . " failed to save as setting. With result " . $result . " ";
- //if fail shoudl we freeze and alert user with a window towith error message
+
+ echo "Failed to make tenant. Check connection to player and tenant name (cannot reuse old tenant names).";
echo $link;
}
} else {
- echo "Failed to make tenant. Check connection to player and tenant name (cannot reuse old tenant names).";
+ // If there is no tenant name then alert user, when they click to clear take them back to settings page.
+ echo "Tenant name not retrieved or blank. Please try again.";
echo $link;
+
}
-} else {
-
- // If there is no tenant name then alert user, when they click to clear take them back to settings page.
- echo "Tenant name not retrieved or blank. Please try again.";
-
- echo $link;
}
+;
+echo $OUTPUT->header();
+
+// Display the form.
+$mform->display();
+echo $OUTPUT->footer();
?>
diff --git a/tokensetup.php b/tokensetup.php
index ca30cc3..4ee112d 100644
--- a/tokensetup.php
+++ b/tokensetup.php
@@ -23,25 +23,21 @@
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');
-
+// Include our class file
+require_once($CFG->dirroot.'/mod/cmi5launch/classes/local/token_form.php');
+// Tell moodle about our page, tell it what the url is.\\
+$PAGE->set_url('/mod/cmi5launch/tokensetup.php');
+// Tell moodle the context, in this case the site context (it's system wide not a course or course page.)
+$PAGE->set_context(\context_system::instance());
+// Title tells what is on tab
+$PAGE->set_title(title: 'Creating a tenant');
define('CMI5LAUNCH_REPORT_DEFAULT_PAGE_SIZE', 20);
define('CMI5LAUNCH_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
define('CMI5LAUNCH_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
@@ -54,18 +50,6 @@ function goback(){
$cmi5helper = new cmi5_connectors;
$gettoken = $cmi5helper->cmi5launch_get_retrieve_token();
-
-// Return link/button to settings page.
- $link = "
-
-
-
- OK
-
-
- ";
-
-
// Before a token can be made, there must be a tenant name and id, so verify these exist, if not throw error.
// Retrieves the string if there or false if not.
@@ -117,6 +101,14 @@ function goback(){
echo $link;
}
+
+
+//whenyou want to out put html use the moodle core output rendereer: often overridden in theme
+echo $OUTPUT->header();
+
+// we want to display a form
+$mform = new setup_token();
+echo $OUTPUT->footer();
?>