I'm trying something quite unusual and am interested to hear if anyone has done anything similar.
I have a web app that existed prior to my Moodle site and takes students through lessons and quizzes. Its functioning and look need to be conserved so it doesn't make sense to rewrite this as a Moodle module, but I want to have reporting of the results of students taking the lessons/quizzes available to the teachers on their Moodle course.
My solution for the moment has been to use a custom-made web service function with triggers at appropriate points in the web app (e.g. at the end of a quiz) that is accessed through an iframe using the
URL resource.
The internal workings of the web service function do roughly the following:
CREATE A QUIZ:
insert record to mdl_quiz (name according to a convention based on the structure of web app),
Insert record to mdl_course_modules (using module 13 and the id of quiz just created; visible=0),
update record in mdl_course_sections (sort the contents of sequence field and insert the course-module id in the appropriate place),
insert record to mdl_quiz_question_instance (uses any question to allow moodle to see that the quiz has a question)
CREATE A QUIZ ATTEMPT
insert record to mdl_quiz_attempt (using the user id of the user accessing the web app; unique id as the highest current unique id + 1),
insert record to mdl_quiz_grade (using the same grade as inserted above)
This then works to provide teachers with stats about these hidden 'modules' that correspond to each URL resource.
One less important glitch is that the quiz modules so created won't appear until an existing quiz is updated (just by clicking 'edit settings' and 'update' on any quiz without making changes) or a new one created but once this is done the teachers will be able to see the table and graph of student success, which is what was wanted.
A more important glitch is that bona fide quizzes can't now be attempted, as I get the following error:
bug info: Duplicate entry '4' for key 'mdl_quizatte_uni_uix'
INSERT INTO mdl_quiz_attempts (quiz,userid,preview,layout,attempt,sumgrades,timestart,timefinish,timemodified,uniqueid) VALUES(?,?,?,?,?,?,?,?,?,?)
[array (
0 => '49',
1 => '2',
2 => 1,
3 => '2,0,4,0,3,0',
4 => 1,
5 => 0,
6 => 1307548257,
7 => 0,
8 => 1307548257,
9 => 4,
)]
Stack trace:
- line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
- line 874 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
- line 916 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
- line 101 of /mod/quiz/startattempt.php: call to mysqli_native_moodle_database->insert_record()
I am guessing this is a problem with the unique_id field of the quiz_attempt and that this causes a conflict.
Is there a way to solve this by finding a different way to create this unique id and can I persist with this method to get what I need or should I expect other instabilities to result from this?
What would my prospects be of using the gradebook API to write a new gradebook report using a table and lib/graphlib to get this done? One motive for using quizzes was that all of the permission issues are taken care of so that teachers will only see grades of their own students. Would this be harder to implement in a gradebook report?