Skip to content

Commit

Permalink
Moved all mod.php functions from modules into lib.php, and
Browse files Browse the repository at this point in the history
updated course/mod.php to use them there.  No longer need module/mod.php
  • Loading branch information
martin committed Aug 3, 2002
1 parent 8c3c848 commit 04eba58
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 384 deletions.
17 changes: 10 additions & 7 deletions course/mod.php
Expand Up @@ -14,23 +14,26 @@
error("You can't modify this course!");
}

$modcode = "../mod/$mod->modulename/mod.php";
if (file_exists($modcode)) {
include($modcode);
$modlib = "../mod/$mod->modulename/lib.php";
if (file_exists($modlib)) {
include($modlib);
} else {
error("This module is missing important code! (mod.php)");
error("This module is missing important code! ($modlib)");
}
$addinstancefunction = $mod->modulename."_add_instance";
$updateinstancefunction = $mod->modulename."_update_instance";
$deleteinstancefunction = $mod->modulename."_delete_instance";

switch ($mod->mode) {
case "update":
if (! update_instance($mod)) {
if (! $updateinstancefunction($mod)) {
error("Could not update the $mod->modulename");
}
add_to_log($mod->course, "course", "update mod", "../mod/$mod->modulename/view.php?id=$mod->coursemodule", "$mod->modulename $mod->instance");
break;

case "add":
if (! $mod->instance = add_instance($mod)) {
if (! $mod->instance = $addinstancefunction($mod)) {
error("Could not add a new instance of $mod->modulename");
}
// course_modules and course_sections each contain a reference
Expand All @@ -48,7 +51,7 @@
add_to_log($mod->course, "course", "add mod", "../mod/$mod->modulename/view.php?id=$mod->coursemodule", "$mod->modulename $mod->instance");
break;
case "delete":
if (! delete_instance($mod->instance)) {
if (! $deleteinstancefunction($mod->instance)) {
notify("Could not delete the $mod->modulename (instance)");
}
if (! delete_course_module($mod->coursemodule)) {
Expand Down
25 changes: 25 additions & 0 deletions mod/README
@@ -0,0 +1,25 @@
This directory contains all the learning modules.

Standard components expected of each module:

mod.html: a form to setup/update a module instance
version.php: defines some meta-info and provides upgrading code
icon.gif: a 16x16 icon for the module
db/mysql.sql: an SQL dump of all the required db tables and data
index.php: a page to list all instances in a course
view.php: a page to view a particular instance
lib.php: any/all functions defined by the module should be in here.
constants should be defined using MODULENAME_xxxxxx
functions should be defined using modulename_xxxxxx

There are a number of standard functions:

modulename_add_instance()
modulename_update_instance()
modulename_delete_instance()

modulename_user_complete()
modulename_user_outline()

modulename_cron()

50 changes: 50 additions & 0 deletions mod/assignment/lib.php
@@ -0,0 +1,50 @@
<?PHP // $Id$

function assignment_add_instance($assignment) {
// 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.

$assignment->timemodified = time();

return insert_record("assignment", $assignment);
}


function assignment_update_instance($assignment) {
// 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.

$assignment->timemodified = time();
$assignment->id = $assignment->instance;

return update_record("assignment", $assignment);
}


function assignment_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 (! $assignment = get_record("assignment", "id", "$id")) {
return false;
}

$result = true;

if (! delete_records("assignment_submissions", "assignment", "$assignment->id")) {
$result = false;
}

if (! delete_records("assignment", "id", "$assignment->id")) {
$result = false;
}

return $result;
}


?>
59 changes: 0 additions & 59 deletions mod/assignment/mod.php

This file was deleted.

48 changes: 48 additions & 0 deletions mod/choice/lib.php
Expand Up @@ -35,5 +35,53 @@ function choice_user_complete($course, $user, $mod, $choice) {
}
}


function choice_add_instance($choice) {
// 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.

$choice->timemodified = time();

return insert_record("choice", $choice);
}


function choice_update_instance($choice) {
// 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.

$choice->id = $choice->instance;
$choice->timemodified = time();

return update_record("choice", $choice);
}


function choice_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 (! $choice = get_record("choice", "id", "$id")) {
return false;
}

$result = true;

if (! delete_records("choice_answers", "choice", "$choice->id")) {
$result = false;
}

if (! delete_records("choice", "id", "$choice->id")) {
$result = false;
}

return $result;
}


?>

59 changes: 0 additions & 59 deletions mod/choice/mod.php

This file was deleted.

0 comments on commit 04eba58

Please sign in to comment.