Skeleton version of the quiz module. It won't break an installation,

but it doesn't do anything yet.
This commit is contained in:
moodler
2002-10-04 02:59:05 +00:00
parent 518d37151d
commit 730fd187c8
8 changed files with 571 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
<?PHP // $Id$
#------------------------------------------------------------
$string['modulename'] = "Quiz";
$string['modulenameplural'] = "Quizzes";
#------------------------------------------------------------
$string['alwaysavailable'] = "Always available";
$string['attempt'] = "Attempt \$a";
$string['attemptfirst'] = "First attempt";
$string['attemptlast'] = "Last attempt";
$string['attempts'] = "Attempts";
$string['attemptsallowed'] = "Attempts allowed";
$string['attemptsunlimited'] = "Unlimited attempts";
$string['daysavailable'] = "Days available";
$string['gradeaverage'] = "Average grade";
$string['gradehighest'] = "Highest grade";
$string['grademethod'] = "Grading method";
$string['introduction'] = "Introduction";
$string['showfeedback'] = "After answering, show feedback?";
$string['showcorrectanswer'] = "After answering, show correct answers?";
+173
View File
@@ -0,0 +1,173 @@
# phpMyAdmin MySQL-Dump
# version 2.3.2-dev
# http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
# Generation Time: Oct 03, 2002 at 11:15 PM
# Server version: 3.23.49
# PHP Version: 4.2.3
# Database : `moodle`
# --------------------------------------------------------
#
# Table structure for table `quiz`
#
CREATE TABLE `quiz` (
`id` int(10) unsigned NOT NULL auto_increment,
`course` int(10) unsigned NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`intro` text NOT NULL,
`days` smallint(6) NOT NULL default '0',
`attempts` smallint(6) NOT NULL default '0',
`feedback` tinyint(4) NOT NULL default '0',
`correctanswers` tinyint(4) NOT NULL default '1',
`grademethod` tinyint(4) NOT NULL default '1',
`questions` text NOT NULL,
`sumgrades` int(10) NOT NULL default '0',
`grade` int(10) NOT NULL default '0',
`timecreated` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Main information about each quiz';
# --------------------------------------------------------
#
# Table structure for table `quiz_answers`
#
CREATE TABLE `quiz_answers` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`answer` int(10) unsigned NOT NULL default '0',
`grade` float NOT NULL default '0',
`feedback` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Answers, with a percentage grade and feedback';
# --------------------------------------------------------
#
# Table structure for table `quiz_attempts`
#
CREATE TABLE `quiz_attempts` (
`id` int(10) unsigned NOT NULL auto_increment,
`quiz` int(10) unsigned NOT NULL default '0',
`user` int(10) unsigned NOT NULL default '0',
`attempt` smallint(6) NOT NULL default '0',
`grade` float NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Stores various attempts on a quiz';
# --------------------------------------------------------
#
# Table structure for table `quiz_categories`
#
CREATE TABLE `quiz_categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`course` int(10) unsigned NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`info` text NOT NULL,
`publish` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Categories are for grouping questions';
# --------------------------------------------------------
#
# Table structure for table `quiz_grades`
#
CREATE TABLE `quiz_grades` (
`id` int(10) unsigned NOT NULL auto_increment,
`quiz` int(10) unsigned NOT NULL default '0',
`user` int(10) unsigned NOT NULL default '0',
`grade` float NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Final quiz grade (may be best of several attempts)';
# --------------------------------------------------------
#
# Table structure for table `quiz_multichoice`
#
CREATE TABLE `quiz_multichoice` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`layout` tinyint(4) NOT NULL default '0',
`answers` varchar(255) NOT NULL default '',
`single` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Options for multiple choice questions';
# --------------------------------------------------------
#
# Table structure for table `quiz_question_grades`
#
CREATE TABLE `quiz_question_grades` (
`id` int(10) unsigned NOT NULL auto_increment,
`quiz` int(10) unsigned NOT NULL default '0',
`question` int(10) unsigned NOT NULL default '0',
`grade` smallint(6) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='The grade for a question in a quiz';
# --------------------------------------------------------
#
# Table structure for table `quiz_questions`
#
CREATE TABLE `quiz_questions` (
`id` int(10) NOT NULL auto_increment,
`course` int(10) NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`question` text NOT NULL,
`type` smallint(6) NOT NULL default '0',
`options` int(10) NOT NULL default '0',
`category` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='The quiz questions themselves';
# --------------------------------------------------------
#
# Table structure for table `quiz_responses`
#
CREATE TABLE `quiz_responses` (
`id` int(10) unsigned NOT NULL auto_increment,
`attempt` int(10) unsigned NOT NULL default '0',
`question` int(10) unsigned NOT NULL default '0',
`answer` varchar(255) NOT NULL default '',
`grade` float NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Stores user responses to a quiz, and percentage grades';
# --------------------------------------------------------
#
# Table structure for table `quiz_shortanswer`
#
CREATE TABLE `quiz_shortanswer` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`answer` int(10) NOT NULL default '0',
`case` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Options for short answer questions';
# --------------------------------------------------------
#
# Table structure for table `quiz_truefalse`
#
CREATE TABLE `quiz_truefalse` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`true` int(10) unsigned NOT NULL default '0',
`false` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Options for True-False questions';
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

+73
View File
@@ -0,0 +1,73 @@
<?PHP // $Id$
// This page lists all the instances of quiz in a particular course
require("../../config.php");
require("lib.php");
require_variable($id); // course
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
require_login($course->id);
add_to_log($course->id, "quiz", "view all", "index.php?id=$course->id", "");
// Print the header
$strquizzes = get_string("modulenameplural", "quiz");
$strquiz = get_string("modulename", "quiz");
if ($course->category) {
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
}
print_header("$course->shortname: $strquizzes", "$course->fullname", "$navigation $strquizzes");
// Get all the appropriate data
if (! $quizzes = get_all_instances_in_course("quiz", $course->id, "cw.section ASC")) {
notice("There are no quizzes", "../../course/view.php?id=$course->id");
die;
}
// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string("name");
$strweek = get_string("week");
$strtopic = get_string("topic");
if ($course->format == "weeks") {
$table->head = array ($strweek, $strname);
$table->align = array ("CENTER", "LEFT");
} else if ($course->format == "topics") {
$table->head = array ($strtopic, $strname);
$table->align = array ("CENTER", "LEFT", "LEFT", "LEFT");
} else {
$table->head = array ($strname);
$table->align = array ("LEFT", "LEFT", "LEFT");
}
foreach ($quizzes as $quiz) {
$link = "<A HREF=\"view.php?id=$quiz->coursemodule\">$quiz->name</A>";
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($quiz->section, $link);
} else {
$table->data[] = array ($link);
}
}
echo "<BR>";
print_table($table);
// Finish the page
print_footer($course);
?>
+104
View File
@@ -0,0 +1,104 @@
<?PHP // $Id$
// Library of function for module quiz
$QUIZ_GRADE_METHOD = array ( "1" => get_string("gradehighest", "quiz"),
"2" => get_string("gradeaverage", "quiz"),
"3" => get_string("attemptfirst", "quiz"),
"4" => get_string("attemptlast", "quiz")
);
function quiz_add_instance($quiz) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will create a new instance and return the id number
// of the new instance.
$quiz->timemodified = time();
# May have to add extra stuff in here #
return insert_record("quiz", $quiz);
}
function quiz_update_instance($quiz) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will update an existing instance with new data.
$quiz->timemodified = time();
$quiz->id = $quiz->instance;
# May have to add extra stuff in here #
return update_record("quiz", $quiz);
}
function quiz_delete_instance($id) {
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
if (! $quiz = get_record("quiz", "id", "$id")) {
return false;
}
$result = true;
# Delete any dependent records here #
if (! delete_records("quiz", "id", "$quiz->id")) {
$result = false;
}
return $result;
}
function quiz_user_outline($course, $user, $mod, $quiz) {
// Return a small object with summary information about what a
// user has done with a given particular instance of this module
// Used for user activity reports.
// $return->time = the time they did it
// $return->info = a short text description
return $return;
}
function quiz_user_complete($course, $user, $mod, $quiz) {
// Print a detailed representation of what a user has done with
// a given particular instance of this module, for user activity reports.
return true;
}
function quiz_print_recent_activity(&$logs, $isteacher=false) {
// Given a list of logs, assumed to be those since the last login
// this function prints a short list of changes related to this module
// If isteacher is true then perhaps additional information is printed.
// This function is called from course/lib.php: print_recent_activity()
global $CFG, $COURSE_TEACHER_COLOR;
return $content; // True if anything was printed, otherwise false
}
function quiz_cron () {
// Function to be run periodically according to the moodle cron
// This function searches for things that need to be done, such
// as sending out mail, toggling flags etc ...
global $CFG;
return true;
}
//////////////////////////////////////////////////////////////////////////////////////
// Any other quiz functions go here. Each of them must have a name that
// starts with quiz_
?>
+115
View File
@@ -0,0 +1,115 @@
<!-- This page defines the form to create or edit an instance of this module -->
<!-- It is used from /course/mod.php. The whole instance is available as $form. -->
<? include_once("$CFG->dirroot/mod/quiz/lib.php") ?>
<H1 ALIGN=CENTER><FONT COLOR=RED>This module is not ready for use</FONT></H1>
<FORM name="form" method="post" action="<?=$ME ?>">
<CENTER>
<TABLE cellpadding=5>
<TR valign=top>
<TD align=right><P><B><? print_string("name") ?>:</B></P></TD>
<TD>
<INPUT type="text" name="name" size=40 value="<? p($form->name) ?>">
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("introduction", "quiz") ?>:</B></P></TD>
<TD>
<textarea name="intro" rows=4 cols=50 wrap="virtual"><? p($form->intro) ?></textarea>
<? helpbutton("text", get_string("helptext")); ?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("daysavailable", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("alwaysavailable", "quiz");
for ($i=1;$i<=13;$i++) {
$options[$i] = get_string("numdays", "", $i);
}
for ($i=2;$i<=16;$i++) {
$days = $i * 7;
$options[$days] = get_string("numweeks", "", $i);
}
$options[365] = get_string("numweeks", "", 52);
if ($form->days == "") {
$form->days == "14";
}
choose_from_menu($options, "days", "$form->days", "");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("attemptsallowed", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("attemptsunlimited", "quiz");
$options[1] = "1 ".strtolower(get_string("attempt", "quiz"));
for ($i=2;$i<=6;$i++) {
$options[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
}
choose_from_menu($options, "attempts", "$form->attempts", "");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("grademethod", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[1] = get_string("gradehighest", "quiz");
$options[2] = get_string("gradeaverage", "quiz");
$options[3] = get_string("attemptfirst", "quiz");
$options[4] = get_string("attemptlast", "quiz");
choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("showfeedback", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "feedback", "$form->feedback", "");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("showcorrectanswer", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "correctanswers", "$form->correctanswers", "");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("maximumgrade") ?>:</B></P></TD>
<TD>
<?
for ($i=100; $i>=0; $i--) {
$grades[$i] = $i;
}
choose_from_menu($grades, "grade", "$form->grade", "");
?>
</TD>
</TR>
</TABLE>
<!-- These hidden variables are always the same -->
<INPUT type="hidden" name=course value="<? p($form->course) ?>">
<INPUT type="hidden" name=coursemodule value="<? p($form->coursemodule) ?>">
<INPUT type="hidden" name=section value="<? p($form->section) ?>">
<INPUT type="hidden" name=module value="<? p($form->module) ?>">
<INPUT type="hidden" name=modulename value="<? p($form->modulename) ?>">
<INPUT type="hidden" name=instance value="<? p($form->instance) ?>">
<INPUT type="hidden" name=mode value="<? p($form->mode) ?>">
<INPUT type="submit" value="<? print_string("savechanges") ?>">
</CENTER>
</FORM>
+24
View File
@@ -0,0 +1,24 @@
<?PHP // $Id$
////////////////////////////////////////////////////////////////////////////////
// Code fragment to define the version of quiz
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2002100300; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
function quiz_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality
global $CFG;
if ($oldversion < 2002100300) {
}
return true;
}
?>
+61
View File
@@ -0,0 +1,61 @@
<?PHP // $Id$
// This page prints a particular instance of quiz
require("../../config.php");
require("lib.php");
optional_variable($id); // Course Module ID, or
optional_variable($q); // quiz ID
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $quiz = get_record("quiz", "id", $cm->instance)) {
error("Course module is incorrect");
}
} else {
if (! $quiz = get_record("quiz", "id", $a)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $quiz->course)) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
error("Course Module ID was incorrect");
}
}
require_login($course->id);
add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", "$quiz->id");
// Print the page header
if ($course->category) {
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
}
$strquizzes = get_string("modulenameplural", "quiz");
$strquiz = get_string("modulename", "quiz");
print_header("$course->shortname: $quiz->name", "$course->fullname",
"$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> -> $quiz->name",
"", "", true, update_module_icon($cm->id, $course->id));
// Print the main part of the page
echo "YOUR CODE GOES HERE";
// Finish the page
print_footer($course);
?>