General developer forum

 
 
Picture of Alan Hess
Save Javascript Array to DB - Patch or new Module?
Group Particularly helpful Moodlers

Hi

I need a little friendly advice. I'm doing some linguistic research which uses an interactive Webpage (HTML/Javascript) which can be called in a Moodle course as an uploaded HTML file with associated js and css files. The associated javascript stores data in an array 'text[n]' which records the alterations learners make to an existing framework text in an assisted creative writing session.

See http://manxman.ch/moodle2/file.php/5/Newgames/demogame-en-expand/Story.html for a basic demo. It works fine!

I have very little PHP knowledge but OK in Javascript. From what I can see the strings $USER and $COURSE could be stored and retrieved in MYSQL along with a dump of the text array?  I don't need much more functionality than that as learners progress to creating texts from scratch in a Wiki later. They only need to recall the state of their own mods at the next login. At the moment we copy and paste into a stored file.

Would a source code patch be the easiest method or would I have to develop a whole new Module or Question Type? Any pointers?

Best regards

Alan

Switzerland

 

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Save Javascript Array to DB - Patch or new Module?
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

One way to do this would be to turn your HTML + JS + CSS into a 'SCORM package'. If you do that, then your JavaScript can communicate with Moodle (or any other SCORM-compliant LMS) and store things like that array you want to store.

If you Google "SCORM tutorial" then that seems to find some things.

 
Average of ratings:Useful (1)
Picture of Alan Hess
Re: Save Javascript Array to DB - Patch or new Module?
Group Particularly helpful Moodlers

Aha! - Thanks Tim. It looks promising and will start experimenting.

Alan

 
Average of ratings: -
Picture of Alan Hess
Re: Save Javascript Array to DB - Patch or new Module?
Group Particularly helpful Moodlers

Already got content loaded via a SCORM driver package in Moodle 2.4.1 displaying and working fully!!  Just need to figure out how to pass the variable now.

Driver from here : http://www.adlnet.gov/capabilities/scorm#tab-learn

Thanks again

 
Average of ratings: -
Picture of Ray Morris
Re: Save Javascript Array to DB - Patch or new Module?
Group DevelopersGroup Particularly helpful Moodlers

The adlnet page you linked to has some samples.  Using their API javascript,  you could set and get suspend data like this:

doSetValue("cmi.suspend_data", yourdata);
yourdata = doGetValue("cmi.suspend_data");

Before getting and setting values, you have to do some setup work to initilaize the API connection.  See their samples for code you can copy-paste, then hopefully once you have it working you can look at it an understand a little bit about what it's doing.

 

 
Average of ratings:Useful (1)
Picture of Alan Hess
Re: Save Javascript Array to DB - Patch or new Module?
Group Particularly helpful Moodlers

Thanks Ray much appreciated. I ended up using pipwerks.com which needs much less config.

Cheers

 
Average of ratings: -
Picture of Alan Hess
Re: Save Javascript Array to DB - Patch or new Module?
Group Particularly helpful Moodlers

Hi Tim - Thanks a million! Just to close the story, all has gone very well. I never thought of using SCORM to just store Javascript variables in this way.

I ended up downloading the SCORM 2004 driver from pipwerks.com which is easy to figure out. The SCORM variable 'cmi.suspend_data' is a string 64K long and sufficient to store my text array. Just used javascript '.split' function to reinstate it.

Needless to say SCORM can store other infos too such as edit count etc..  Although this is not a test activity as such it works well.

demo - http://manxman.ch/moodle2/mod/scorm/view.php?id=473

Best regards

Alan

 

 
Average of ratings: -