TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 447
  • Total: 447

TP Quiz Script (PHP Article)

Started by jacortina, October 30, 2007, 01:04:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Xarcell

Ok, I tried a different site and DB. It created tables with any trouble.

Now I'm off to play it with.

Mind if I write a Doc on it?

Xarcell

#11
When I click "XML Format Info"

I get:

Parse error: syntax error, unexpected T_FUNCTION in /home/.abigaildryer/xarcell/inspireromance.com/smf/Sources/JQuizXML.php on line 3

What is: "Qualifiers"

And there is a line in the php txt file. Is it missing something, or can the uncommented line supposed to be removed?

line 22:
Quote
                                //      Can be overridden with per-quiz parameters.

jacortina

First of all - here's the complete JQuizXML.php file (I did have an extra space on that first line between '?' and 'php', but it worked fine on my host):

<?php

function print_XML_quiz_format() {
print ( 
'<pre>' )  ;
echo 
'
&lt;?xml version="1.0"?&gt;
&lt;QUIZ&gt;

&lt;QUESTION&gt;
&lt;TEXT&gt;Who was the fifth president of the United States?&lt;/TEXT&gt;
&lt;CHOICES&gt;James Monroe| James Madison| John Quincy Adams&lt;/CHOICES&gt;
&lt;ANSWER&gt;James Monroe&lt;/ANSWER&gt;
&lt;/QUESTION&gt;

&lt;QUESTION&gt;
&lt;TEXT&gt;What city is the capital of Maine?&lt;/TEXT&gt;
&lt;POINTS&gt;2&lt;/POINTS&gt;
&lt;CHOICES&gt;Augusta&lt;/CHOICES&gt;
&lt;ANSWER&gt;Augusta&lt;/ANSWER&gt;
&lt;/QUESTION&gt;

&lt;QUESTION&gt;
&lt;TEXT&gt;When was the US Constitution signed?&lt;/TEXT&gt;
&lt;CHOICES&gt;1789| 1776| 1787&lt;/CHOICES&gt;
&lt;ANSWER&gt;1789&lt;/ANSWER&gt;
&lt;/QUESTION&gt;

&lt;TITLE&gt;&lt;/TITLE&gt;
&lt;NOSCORE&gt;&lt;/NOSCORE&gt;
&lt;PASS_THRESHOLD&gt;&lt;/PASS_THRESHOLD&gt;
&lt;PREREQS&gt;&lt;/PREREQS&gt;
&lt;PM_ON_PASS&gt;&lt;/PM_ON_PASS&gt;
&lt;GROUP_ON_PASS&gt;&lt;/GROUP_ON_PASS&gt;
&lt;GROUPS_MODE&gt;&lt;/GROUPS_MODE&gt;
&lt;RETAKE_PASSED&gt;true&lt;/RETAKE_PASSED&gt;
&lt;DEBUG&gt;&lt;/DEBUG&gt;

&lt;/QUIZ&gt;

================================================================================

&lt;QUESTION&gt;
&lt;TEXT&gt;--- Text to appear to \'ask\' the question ---&lt;/TEXT&gt;
&lt;POINTS&gt;--- Optional - Number of points earned for answering question; ---&lt;/POINTS&gt;
                  if not given, question will be scored as one (1) point.
&lt;CHOICES&gt;--- Choices for multiple choice, pipe (\'|\') delimited; ---&lt;/CHOICES&gt;
                   supply only one entry to prompt for typed text answer. 
&lt;ANSWER&gt;--- Corrrect answer for question; if question is of the ---&lt;/ANSWER&gt;
                  typed text kind, text matching is NOT case sensitive
&lt;/QUESTION&gt;

An arbitrary number of question \'sets\' can be included, but the
&lt;ANSWER&gt;&lt;/ANSWER&gt; MUST come last in each set (just
before the &lt;/QUESTION&gt; tag).


All of the following Quiz Paramters are optional, with default behavior programmed into
the script:

&lt;TITLE&gt;&lt;/TITLE&gt;
The title to be used in display (and PM\'s) for the quiz.

&lt;NOSCORE&gt;&lt;/NOSCORE&gt;
Insert the word \'true\' to suppress the recording of scores for this quiz. Default is
to record scores. Note that if membergroup change in other than AUTO mode is selected
via parameters below, they will never occur as the scoring record is used to hold the
membergroup change information.

&lt;PASS_THRESHOLD&gt;&lt;/PASS_THRESHOLD&gt;
Number of points necessary to \'pass\' the quiz. Note that this is the total of points
for questions answered correctly rather than just number of questions answered correctly.
Default is to set the passing mark to be equal to total number of points (perfect score
needed to pass).

&lt;PREREQS&gt;&lt;/PREREQS&gt;
Specifications to determine qualifiers (if any) to take the quiz (or even see it in the
quiz list). See below for details*.

&lt;PM_ON_PASS&gt;&lt;/PM_ON_PASS&gt;
Pipe (\'|\') delimited list of User Numbers of those to receive a PM when a quiz-taker
passes this quiz. Default is none.

&lt;GROUP_ON_PASS&gt;&lt;/GROUP_ON_PASS&gt;
Membergroup number(s) of groups to join and/or leave upon receiving a passing score on
the quiz. Pipe (\'|\') delimited. Default is none. Group to join given as number only,
group to leave given as negative. If more then one of either type is given, only the
LAST will be considered.
(Ex. 1: &lt;GROUP_ON_PASS&gt;12&lt;/GROUP_ON_PASS&gt; - join group 12.)
(Ex. 2: &lt;GROUP_ON_PASS&gt;12|-11&lt;/GROUP_ON_PASS&gt; - join group 12 and leave group 11).
{NOTE: ONLY additional membergoups will be effected. Will NOT drop or add a member\'s
primary membergroup. Will NOT consider groups 1-3 nor any post-count based group numbers.)

&lt;GROUPS_MODE&gt;&lt;/GROUPS_MODE&gt;
If any entries given in \'GROUPS_ON_PASS\' entry above, specify whether such group change(s)
require approval or should be automatic. Default is to require approval. Insert the text
\'AUTO\' to make such change(s) automatic.

&lt;RETAKE_PASSED&gt;true&lt;/RETAKE_PASSED&gt;
In-script configuration value $quiz_retake_pass can be overridden by inserting value of
\'true\' or \'false\' here to specify whether or not a quiz can be retaken by a user after
having passed it. Will default to the scripts configuration value (and if that\'s missing,
will default to false - no retaking passed quizzes.

&lt;DEBUG&gt;&lt;/DEBUG&gt;
If present at all (no value necessary), will prevent users from taking the quiz. Useful
for Admins to check and review the paramters (especially the qualifiers / pre-requisites).
Clicking a quiz in the Admin Menu will show how the quiz parameters \'look\' to the script.


* Specifying Pre-Requisites / Qualifications:

\'Sets\' of conditions can be enered, pipe (\'|\') delimited. These sets are all \'OR\'ed
(a user matching any of the individual sets will be able to see and take the quiz).

Each set consists of one or more \'conditions\', plus-sign (\'+\') delimited. These
conditions are all \'AND\'ed (user must match ALL of the conditions in a given set to
match the set).

Condition specifications can be given for group membership or non-membership, whether a user
has previously passed another quiz, post count, and absolute user ID number. Parentheses can
be used, if desired, but will not affect the processing.

Group Membership/Non-membership:
 G10 - User MUST be member of membergroup 10.
-G11 - User MUST NOT be member of membergroup 11.

Previous quiz record:
 Qtest1 - User MUST have passed quiz [test1].
-Qtest2 - User MUST NOT have passed quiz [test2].

Post Count:
 P20  - User MUST have made 20 posts or more.
-P100 - User MUST have made LASS THAN 100 posts.

User Specification:
 U199 - User is User # 199.
-U221 - User is NOT User # 221.

Example Sets:
(G12)+(-Qtest3) - Matched by members of membergroup 12 who have NOT passed quiz [test3].
(Qtest4)+(P250) - Matched by users who\'ve passed quiz [test4] AND have made at least 250 posts.

Example Full Pre-Requisites:
(G13)|(G12)+(Qtest1)|(U123)+(P500)
                  Any member of group 13 -OR- members of group 12 who have
                  already passed quiz [test1] -OR- user # 123 after they
                  have made their 500th post.

'
;

print ( 
'</pre>' )  ;
}

?>


And the point of that os to display this:
-------------------------------------------------

<?xml version="1.0"?>
<QUIZ>

<QUESTION>
<TEXT>Who was the fifth president of the United States?</TEXT>
<CHOICES>James Monroe| James Madison| John Quincy Adams</CHOICES>
<ANSWER>James Monroe</ANSWER>
</QUESTION>

<QUESTION>
<TEXT>What city is the capital of Maine?</TEXT>
<POINTS>2</POINTS>
<CHOICES>Augusta</CHOICES>
<ANSWER>Augusta</ANSWER>
</QUESTION>

<QUESTION>
<TEXT>When was the US Constitution signed?</TEXT>
<CHOICES>1789| 1776| 1787</CHOICES>
<ANSWER>1789</ANSWER>
</QUESTION>

<TITLE></TITLE>
<NOSCORE></NOSCORE>
<PASS_THRESHOLD></PASS_THRESHOLD>
<PREREQS></PREREQS>
<PM_ON_PASS></PM_ON_PASS>
<GROUP_ON_PASS></GROUP_ON_PASS>
<GROUPS_MODE></GROUPS_MODE>
<RETAKE_PASSED></RETAKE_PASSED>
<DEBUG></DEBUG>

</QUIZ>

================================================================================

<QUESTION>
<TEXT>--- Text to appear to 'ask' the question ---</TEXT>
<POINTS>--- Optional - Number of points earned for answering question; ---</POINTS>
                  if not given, question will be scored as one (1) point.
<CHOICES>--- Choices for multiple choice, pipe ('|') delimited; ---</CHOICES>
                   supply only one entry to prompt for typed text answer.
<ANSWER>--- Corrrect answer for question; if question is of the ---</ANSWER>
                  typed text kind, text matching is NOT case sensitive
</QUESTION>

An arbitrary number of question 'sets' can be included, but the
<ANSWER></ANSWER> MUST come last in each set (just
before the </QUESTION> tag).


All of the following Quiz Paramters are optional, with default behavior programmed into
the script:

<TITLE></TITLE>
The title to be used in display (and PM's) for the quiz.

<NOSCORE></NOSCORE>
Insert the word 'true' to suppress the recording of scores for this quiz. Default is
to record scores. Note that if membergroup change in other than AUTO mode is selected
via parameters below, they will never occur as the scoring record is used to hold the
membergroup change information.

<PASS_THRESHOLD></PASS_THRESHOLD>
Number of points necessary to 'pass' the quiz. Note that this is the total of points
for questions answered correctly rather than just number of questions answered correctly.
Default is to set the passing mark to be equal to total number of points (perfect score
needed to pass).

<PREREQS></PREREQS>
Specifications to determine qualifiers (if any) to take the quiz (or even see it in the
quiz list). See below for details*.

<PM_ON_PASS></PM_ON_PASS>
Pipe ('|') delimited list of User Numbers of those to receive a PM when a quiz-taker
passes this quiz. Default is none.

<GROUP_ON_PASS></GROUP_ON_PASS>
Membergroup number(s) of groups to join and/or leave upon receiving a passing score on
the quiz. Pipe ('|') delimited. Default is none. Group to join given as number only,
group to leave given as negative. If more then one of either type is given, only the
LAST will be considered.
(Ex. 1: <GROUP_ON_PASS>12</GROUP_ON_PASS> - join group 12.)
(Ex. 2: <GROUP_ON_PASS>12|-11</GROUP_ON_PASS> - join group 12 and leave group 11).
{NOTE: ONLY additional membergoups will be effected. Will NOT drop or add a member's
primary membergroup. Will NOT consider groups 1-3 nor any post-count based group numbers.)

<GROUPS_MODE></GROUPS_MODE>
If any entries given in 'GROUPS_ON_PASS' entry above, specify whether such group change(s)
require approval or should be automatic. Default is to require approval. Insert the text
'AUTO' to make such change(s) automatic.

<RETAKE_PASSED></RETAKE_PASSED>
In-script configuration value $quiz_retake_pass can be overridden by inserting value of
'true' or 'false' here to specify whether or not a quiz can be retaken by a user after
having passed it. Will default to the scripts configuration value (and if that's missing,
will default to false - no retaking passed quizzes.

<DEBUG></DEBUG>
If present at all (no value necessary), will prevent users from taking the quiz. Useful
for Admins to check and review the paramters (especially the qualifiers / pre-requisites).
Clicking a quiz in the Admin Menu will show how the quiz parameters 'look' to the script.


* Specifying Pre-Requisites / Qualifications:

'Sets' of conditions can be enered, pipe ('|') delimited. These sets are all 'OR'ed
(a user matching any of the individual sets will be able to see and take the quiz).

Each set consists of one or more 'conditions', plus-sign ('+') delimited. These
conditions are all 'AND'ed (user must match ALL of the conditions in a given set to
match the set).

Condition specifications can be given for group membership or non-membership, whether a user
has previously passed another quiz, post count, and absolute user ID number. Parentheses can
be used, if desired, but will not affect the processing.

Group Membership/Non-membership:
G10 - User MUST be member of membergroup 10.
-G11 - User MUST NOT be member of membergroup 11.

Previous quiz record:
Qtest1 - User MUST have passed quiz [test1].
-Qtest2 - User MUST NOT have passed quiz [test2].

Post Count:
P20  - User MUST have made 20 posts or more.
-P100 - User MUST have made LASS THAN 100 posts.

User Specification:
U199 - User is User # 199.
-U221 - User is NOT User # 221.

Example Sets:
(G12)+(-Qtest3) - Matched by members of membergroup 12 who have NOT passed quiz [test3].
(Qtest4)+(P250) - Matched by users who've passed quiz [test4] AND have made at least 250 posts.

Example Full Pre-Requisites:
(G13)|(G12)+(Qtest1)|(U123)+(P500)
                  Any member of group 13 -OR- members of group 12 who have
                  already passed quiz [test1] -OR- user # 123 after they
                  have made their 500th post.

jacortina

That file should handle a lot of the Docs as far as creating a Quiz file goes.

As to your question about Qualifiers... That's restrictions or pre-requisites.

Because this script/article will have to be available to all (you don't want to make multiple copies with different permissions), the script allows the Quizzes themselves to hold information about who can or cannot take them (or even see them on their lists).

Including the line:
<PREREQS>G10</PREREQS>
means the quiz is only open to member of membergroup 10.

<PREREQS>-G10</PREREQS>
means the quiz is open to those NOT in membergroup 10.

It CAN get more invloved than that, but it's really just a matter of whether or not the quiz should be restricted and to/from whom.


jacortina

Quote from: Xarcell on October 30, 2007, 09:07:54 PM
And there is a line in the php txt file. Is it missing something, or can the uncommented line supposed to be removed?

line 22:
Quote
                                //      Can be overridden with per-quiz parameters.

Looks like a commented line to me. And it's a follow-on to the comment text above it:
$q_retake_pass = 'true';                // Can users re-take quizzes that they've passed?
        //      Can be overridden with per-quiz parameters.

Xarcell

Wow, you really put alot of work into it, it's very flexible. It was ALOT more than I was hoping for. Well done...

I have a few more questions though.

Do you think this would qualify as a module? Or better to perhaps turn it into one?

Maybe write some block snippets (or if module, blocks themselves) to show recent tests, or latest passed, or a user's latest tests and scores, etc. Which ever is needed?

The only other thing I wish I would have asked for, is an optional time limit on a quiz. <TIME>in seconds</TIME> or something. I really appreciate everything you've done so far. If you don't want or have time to add it, I understand. I'm grateful with what you've given us so far...

Also, we should come up with a way to share quizzes that we have created. I plan to write quite a few, and I don't mind sharing them with anyone else that wishes to use them. I guess for the time being we can attach them to our post in this topic.

Again nice work, and a BIG THANK YOU...

jacortina

Well, as work progressed, things just jumped out. Things like being able to have more options than one question - one point. Or having the option to NOT track a score.

And, given a more flexible system of modules as 'plug-ins' rather than built in bundles, I'd say it could work that way. There's a much more limited set of configuration paramters in this than, say, the Calendar block I've worked on. And simple 'auxiliary' blocks which pull query information from the table wouldn't be hard at all.

A sharing mechanism (other than simply swapping around files to FTP into place) sounds like an interesting thing to look into.

And I'll give some thought to the TIME parameter. But because they can simply stop before the end of the quiz and start it over later (and sooner or later that'll become common knowledge), I don't know if that will be all that useful.

I WAS considering a parameter to prevent re-taking a test until a given period of time had passed (in days), so if they bombed it, they can't just jump back in but would have to wait a day, a week, whatever.

Xarcell

#17
Quote from: J.A.Cortina on October 31, 2007, 12:31:05 AM
I WAS considering a parameter to prevent re-taking a test until a given period of time had passed (in days), so if they bombed it, they can't just jump back in but would have to wait a day, a week, whatever.

That would be nice to have.

Also I was wondering if it would be possible to add a subject to the quiz, that offer information on what the test is about at the top?

Maybe also add a <hint></hint> tag that offer some info/hint somewhere to help explain or solve each question? Perhaps displayed above or below the save button?

EDIT: I also forgot about requesting a "credit" tag. For those of use who write the quizzes, then share them. We might want to put our credits in there somewhere.

IchBin

I should write a TP support quiz for the top 20 questions continually asked each day. ;)

jacortina

Adding SUBJECT would be pretty easy. Have it display with the first question when taking a quiz. 'Info' link when a Subject is present on the user's quiz list.

A 'hint', eh? Again, adding it in is no problem. Have to think about best (easiest) way to have it display. Of course, somebody's going to ask for a 'hint cost' penalty, then. ;)

Haven't really come up with a way to enforce a time limit (on taking a specific quiz).

Quote from: IchBin™ on November 06, 2007, 11:59:05 PM
I should write a TP support quiz for the top 20 questions continually asked each day. ;)
But the answer will always be: C) Use the Search.   ;D

If it isn't B) That's an SMF question.

This website is proudly hosted on Crocweb Cloud Website Hosting.