Skip to content

Commit fad220c

Browse files
committed
Queries including kprime and mtf question types.
1 parent 089f326 commit fad220c

File tree

2 files changed

+265
-0
lines changed

2 files changed

+265
-0
lines changed
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* 2024 Luca Bösch [email protected]
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
5+
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
6+
* option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
9+
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
* See the GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with this program. If not, see
13+
* https://www.gnu.org/licenses/.
14+
*/
15+
16+
SELECT
17+
'https://www.example.org/moodle' AS "sourcesystem", -- the source system.
18+
'1,2,3,45,678,9012' AS "authorizedusers", -- the authorized users
19+
qn.id AS "questionid", -- the question id.
20+
qn.parent AS "questionparent", -- the parent question id, given it has one.
21+
qn.name AS "questionname", -- the question name.
22+
qn.questiontext, -- the question text.
23+
qn.questiontextformat, qn.generalfeedback, qn.generalfeedbackformat,
24+
qn.defaultmark,
25+
qn.penalty, qn.qtype, qn.length, qn.stamp AS "questionstamp", qn.timecreated AS "qntimecreated", -- when this question was created.
26+
lpad(EXTRACT(DAY FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
27+
to_timestamp(qn.timecreated+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qn.timecreated+3600))::text, 2,
28+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') "qntimecreatedstring", -- when this question was created.
29+
qn.timemodified AS "qntimemodified", -- when this question was modified.
30+
lpad(EXTRACT(DAY FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
31+
to_timestamp(qn.timemodified+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qn.timemodified+3600))::text, 2,
32+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') "qntimemodifiedstring", -- when this question was modified.
33+
qn.createdby AS "qncreatedby", -- by whom this question was created.
34+
qn.modifiedby AS "qnmodifiedby", -- by whom this question was modified.
35+
qna.id AS "questionanswersid", qna.answer, qna.answerformat,
36+
qtkprimer.optiontext "kprime option text",
37+
qtkprimer.number "kprime option row number",
38+
qtkprimec.responsetext "kprime option responsetext",
39+
qtkprimew.weight "kprime option weight",
40+
qna.fraction, qna.feedback, qna.feedbackformat,
41+
qnv.id AS "questionversionid", qnv.questionbankentryid, qnv.version, qnv.questionid, qnv.status,
42+
qbe.questioncategoryid, qbe.idnumber as "questionbankentryidnumber", qbe.ownerid AS "ownerid",
43+
qnr.id AS "questionreferencesid", qnr.usingcontextid, qnr.component, qnr.questionarea, qnr.itemid, qnr.version as "questionreferencesversion",
44+
qc.id AS "questioncategoriesid", qc.name AS "questioncategoryname", qc.contextid AS "questioncategorycontextid", qc.info, qc.infoformat, qc.stamp AS "questioncategorystamp", qc.parent AS
45+
"questioncategoryparent", qc.sortorder, qc.idnumber as "questioncategoryidnumber",
46+
qs.slot,
47+
qs.effectiveweight,
48+
qs.discriminationindex,
49+
qs.discriminativeefficiency,
50+
qs.sd,
51+
qs.facility,
52+
qs.randomguessscore, -- An estimate of the score a student would get by guessing randomly.
53+
-- u.id AS "userid",
54+
MD5(u.username) "qbeusername",
55+
ctx.id AS "contextid", ctx.path,
56+
qnat.id AS "questionattemptsid", qnat.timemodified AS "qatimemodified",
57+
lpad(EXTRACT(DAY FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
58+
to_timestamp(qnat.timemodified+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM
59+
to_timestamp(qnat.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') "qatimemodifiedstring",
60+
qas.id AS "qastepid",
61+
qas.timecreated AS "qastepcreated",
62+
lpad(EXTRACT(DAY FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
63+
to_timestamp(qas.timecreated+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qas.timecreated+3600))::text, 2,
64+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') "qastepcreatedstring",
65+
qasd.name AS "questionattemptstepdataname",
66+
qasd.value AS "questionattemptstepdatavalue",
67+
qzat.id AS "quizattemptsid",
68+
qzat.uniqueid AS "quizattemptsuniqueid",
69+
qz.id AS "quizid", -- the quiz id.
70+
qz.name AS "quizname", -- the quiz name.
71+
qz.grade AS "quizgrade", -- the quiz maximum grade.
72+
qzfb.feedbacktext, -- the quiz feedback.
73+
qzfb.feedbacktextformat, -- the quiz feedback text format.
74+
qzfb.mingrade AS "feedbackmingrade", -- the quiz feedback min grade.
75+
qzfb.maxgrade AS "feedbackmaxgrade", -- the quiz feedback max grade.
76+
c.id AS "courseid",
77+
cm.id AS "coursemodulesid",
78+
m.name AS "modulename",
79+
(SELECT MD5(username) FROM {user} WHERE id = qzat.userid) AS "qzatuserid",
80+
uid.data AS "userinfodata"
81+
82+
FROM {question} qn
83+
LEFT JOIN {question_answers} qna
84+
ON qn.id = qna.question
85+
LEFT JOIN {qtype_kprime_weights} qtkprimew
86+
ON qn.id=qtkprimew.questionid
87+
LEFT JOIN {qtype_kprime_rows} qtkprimer
88+
ON qn.id=qtkprimer.questionid AND qtkprimer.number=qtkprimew.rownumber
89+
LEFT JOIN {qtype_kprime_columns} qtkprimec
90+
ON qn.id=qtkprimec.questionid AND qtkprimec.number=qtkprimew.columnnumber
91+
LEFT JOIN {question_versions} qnv
92+
ON qn.id = qnv.questionid
93+
LEFT JOIN {question_bank_entries} qbe
94+
ON qbe.id = qnv.questionbankentryid
95+
LEFT JOIN {question_references} qnr
96+
ON qbe.id = qnr.questionbankentryid AND qnr.version = qnv.version
97+
LEFT JOIN {question_categories} qc
98+
ON qbe.questioncategoryid = qc.id
99+
LEFT JOIN {question_statistics} qs
100+
ON qn.id = qs.questionid
101+
LEFT JOIN {user} u
102+
ON qbe.ownerid = u.id
103+
LEFT JOIN {context} ctx
104+
ON qnr.usingcontextid = ctx.id
105+
LEFT JOIN {question_attempts} qnat
106+
ON (qn.id = qnat.questionid OR qn.parent = qnat.questionid)
107+
LEFT JOIN {question_attempt_steps} qas
108+
ON qnat.id = qas.questionattemptid
109+
LEFT JOIN {question_attempt_step_data} qasd
110+
ON qas.id = qasd.attemptstepid
111+
LEFT JOIN {quiz_attempts} qzat
112+
ON qzat.uniqueid = qnat.questionusageid
113+
LEFT JOIN {quiz} qz
114+
ON qz.id = qzat.quiz
115+
LEFT JOIN {quiz_feedback} qzfb
116+
ON qz.id = qzfb.quizid
117+
LEFT JOIN {course} c
118+
ON c.id = qz.course
119+
LEFT JOIN {course_modules} cm
120+
ON cm.course = c.id AND cm.instance = qz.id
121+
LEFT JOIN {modules} m
122+
ON cm.module = m.id AND m.name = 'quiz'
123+
LEFT JOIN {user_info_data} uid
124+
ON u.id = uid.userid
125+
LEFT JOIN {user_info_field} uif
126+
ON uif.id = uid.fieldid AND uif.shortname = 'analytics'
127+
128+
WHERE cm.course=%%COURSEID%% AND cm.id = %%CMID%% AND((uid.data IS NULL) OR (uid.data !='1'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* 2024 Luca Bösch [email protected]
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
5+
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
6+
* option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
9+
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
* See the GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with this program. If not, see
13+
* https://www.gnu.org/licenses/.
14+
*/
15+
16+
SELECT
17+
'https://www.example.org/moodle' AS "sourcesystem", -- the source system.
18+
'1,2,3,45,678,9012' AS "authorizedusers", -- the authorized users
19+
qn.id AS "questionid", -- the question id.
20+
qn.parent AS "questionparent", -- the parent question id, given it has one.
21+
qn.name AS "questionname", -- the question name.
22+
qn.questiontext, -- the question text.
23+
qn.questiontextformat, qn.generalfeedback, qn.generalfeedbackformat,
24+
qn.defaultmark,
25+
qn.penalty, qn.qtype, qn.length, qn.stamp AS "questionstamp", qn.timecreated AS "qntimecreated", -- when this question was created.
26+
lpad(EXTRACT(DAY FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
27+
to_timestamp(qn.timecreated+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qn.timecreated+3600))::text, 2,
28+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qn.timecreated+3600))::text, 2, '0') "qntimecreatedstring", -- when this question was created.
29+
qn.timemodified AS "qntimemodified", -- when this question was modified.
30+
lpad(EXTRACT(DAY FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
31+
to_timestamp(qn.timemodified+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qn.timemodified+3600))::text, 2,
32+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qn.timemodified+3600))::text, 2, '0') "qntimemodifiedstring", -- when this question was modified.
33+
qn.createdby AS "qncreatedby", -- by whom this question was created.
34+
qn.modifiedby AS "qnmodifiedby", -- by whom this question was modified.
35+
qna.id AS "questionanswersid", qna.answer, qna.answerformat,
36+
qtkprimer.optiontext "kprime option text",
37+
qtkprimer.number "kprime option row number",
38+
qtkprimec.responsetext "kprime option responsetext",
39+
qtkprimew.weight "kprime option weight",
40+
qmr.optiontext "mtf option text",
41+
qmc.responsetext "mtf option responsetext",
42+
qmw.weight "mtf option weight",
43+
qna.fraction, qna.feedback, qna.feedbackformat,
44+
qnv.id AS "questionversionid", qnv.questionbankentryid, qnv.version, qnv.questionid, qnv.status,
45+
qbe.questioncategoryid, qbe.idnumber as "questionbankentryidnumber", qbe.ownerid AS "ownerid",
46+
qnr.id AS "questionreferencesid", qnr.usingcontextid, qnr.component, qnr.questionarea, qnr.itemid, qnr.version as "questionreferencesversion",
47+
qc.id AS "questioncategoriesid", qc.name AS "questioncategoryname", qc.contextid AS "questioncategorycontextid", qc.info, qc.infoformat, qc.stamp AS "questioncategorystamp", qc.parent AS
48+
"questioncategoryparent", qc.sortorder, qc.idnumber as "questioncategoryidnumber",
49+
qs.slot,
50+
qs.effectiveweight,
51+
qs.discriminationindex,
52+
qs.discriminativeefficiency,
53+
qs.sd,
54+
qs.facility,
55+
qs.randomguessscore, -- An estimate of the score a student would get by guessing randomly.
56+
-- u.id AS "userid",
57+
MD5(u.username) "qbeusername",
58+
ctx.id AS "contextid", ctx.path,
59+
qnat.id AS "questionattemptsid", qnat.timemodified AS "qatimemodified",
60+
lpad(EXTRACT(DAY FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
61+
to_timestamp(qnat.timemodified+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM
62+
to_timestamp(qnat.timemodified+3600))::text, 2, '0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qnat.timemodified+3600))::text, 2, '0') "qatimemodifiedstring",
63+
qas.id AS "qastepid",
64+
qas.timecreated AS "qastepcreated",
65+
lpad(EXTRACT(DAY FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || '.' || lpad(EXTRACT(MONTH FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || '.' || EXTRACT(YEAR FROM
66+
to_timestamp(qas.timecreated+3600)) || ' ' || lpad(EXTRACT(HOUR FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') || ':' || lpad(EXTRACT(MINUTE FROM to_timestamp(qas.timecreated+3600))::text, 2,
67+
'0') || ':' || lpad(EXTRACT(SECOND FROM to_timestamp(qas.timecreated+3600))::text, 2, '0') "qastepcreatedstring",
68+
qasd.name AS "questionattemptstepdataname",
69+
qasd.value AS "questionattemptstepdatavalue",
70+
qzat.id AS "quizattemptsid",
71+
qzat.uniqueid AS "quizattemptsuniqueid",
72+
qz.id AS "quizid", -- the quiz id.
73+
qz.name AS "quizname", -- the quiz name.
74+
qz.grade AS "quizgrade", -- the quiz maximum grade.
75+
qzfb.feedbacktext, -- the quiz feedback.
76+
qzfb.feedbacktextformat, -- the quiz feedback text format.
77+
qzfb.mingrade AS "feedbackmingrade", -- the quiz feedback min grade.
78+
qzfb.maxgrade AS "feedbackmaxgrade", -- the quiz feedback max grade.
79+
c.id AS "courseid",
80+
cm.id AS "coursemodulesid",
81+
m.name AS "modulename",
82+
(SELECT MD5(username) FROM mdl_user WHERE id = qzat.userid) AS "qzatuserid",
83+
uid.data AS "userinfodata"
84+
85+
FROM mdl_question qn
86+
LEFT JOIN mdl_question_answers qna
87+
ON qn.id = qna.question
88+
LEFT JOIN mdl_qtype_kprime_weights qtkprimew
89+
ON qn.id=qtkprimew.questionid
90+
LEFT JOIN mdl_qtype_kprime_rows qtkprimer
91+
ON qn.id=qtkprimer.questionid AND qtkprimer.number=qtkprimew.rownumber
92+
LEFT JOIN mdl_qtype_kprime_columns qtkprimec
93+
ON qn.id=qtkprimec.questionid AND qtkprimec.number=qtkprimew.columnnumber
94+
LEFT JOIN mdl_qtype_mtf_weights qmw
95+
ON qn.id=qmw.questionid
96+
LEFT JOIN mdl_qtype_mtf_rows qmr
97+
ON qn.id=qmr.questionid AND qmr.number=qmw.rownumber
98+
LEFT JOIN mdl_qtype_mtf_columns qmc
99+
ON qn.id=qmc.questionid AND qmc.number=qmw.columnnumber
100+
LEFT JOIN mdl_question_versions qnv
101+
ON qn.id = qnv.questionid
102+
LEFT JOIN mdl_question_bank_entries qbe
103+
ON qbe.id = qnv.questionbankentryid
104+
LEFT JOIN mdl_question_references qnr
105+
ON qbe.id = qnr.questionbankentryid AND qnr.version = qnv.version
106+
LEFT JOIN mdl_question_categories qc
107+
ON qbe.questioncategoryid = qc.id
108+
LEFT JOIN mdl_question_statistics qs
109+
ON qn.id = qs.questionid
110+
LEFT JOIN mdl_user u
111+
ON qbe.ownerid = u.id
112+
LEFT JOIN mdl_context ctx
113+
ON qnr.usingcontextid = ctx.id
114+
LEFT JOIN mdl_question_attempts qnat
115+
ON (qn.id = qnat.questionid OR qn.parent = qnat.questionid)
116+
LEFT JOIN mdl_question_attempt_steps qas
117+
ON qnat.id = qas.questionattemptid
118+
LEFT JOIN mdl_question_attempt_step_data qasd
119+
ON qas.id = qasd.attemptstepid
120+
LEFT JOIN mdl_quiz_attempts qzat
121+
ON qzat.uniqueid = qnat.questionusageid
122+
LEFT JOIN mdl_quiz qz
123+
ON qz.id = qzat.quiz
124+
LEFT JOIN mdl_quiz_feedback qzfb
125+
ON qz.id = qzfb.quizid
126+
LEFT JOIN mdl_course c
127+
ON c.id = qz.course
128+
LEFT JOIN mdl_course_modules cm
129+
ON cm.course = c.id AND cm.instance = qz.id
130+
LEFT JOIN mdl_modules m
131+
ON cm.module = m.id AND m.name = 'quiz'
132+
LEFT JOIN mdl_user_info_data uid
133+
ON u.id = uid.userid
134+
LEFT JOIN mdl_user_info_field uif
135+
ON uif.id = uid.fieldid AND uif.shortname = 'analytics'
136+
137+
WHERE cm.course=%%COURSEID%% AND cm.id = %%CMID%% AND((uid.data IS NULL) OR (uid.data !='1'))

0 commit comments

Comments
 (0)