Permalink
Browse files

Moved all mod.php functions from modules into lib.php, and

updated course/mod.php to use them there.  No longer need module/mod.php
  • Loading branch information...
martin
martin committed Aug 3, 2002
1 parent 8c3c848 commit 04eba58f57ee5975543c8b0a99f135dabcbab89c
Showing with 355 additions and 384 deletions.
  1. +10 −7 course/mod.php
  2. +25 −0 mod/README
  3. +50 −0 mod/assignment/lib.php
  4. +0 −59 mod/assignment/mod.php
  5. +48 −0 mod/choice/lib.php
  6. +0 −59 mod/choice/mod.php
  7. +109 −0 mod/forum/lib.php
  8. +0 −125 mod/forum/mod.php
  9. +49 −0 mod/journal/lib.php
  10. +0 −60 mod/journal/mod.php
  11. +64 −0 mod/survey/lib.php
  12. +0 −74 mod/survey/mod.php
View
@@ -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
@@ -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)) {
View
@@ -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()
+
View
@@ -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;
+}
+
+
+?>
View
@@ -1,59 +0,0 @@
-<?PHP // $Id$
-
-/////////////////////////////////////////////////////////////
-//
-// MOD.PHP - contains functions to add, update and delete
-// an instance of this module
-//
-// Generally called from /course/mod.php
-//
-/////////////////////////////////////////////////////////////
-
-function 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 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 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;
-}
-
-
-?>
View
@@ -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;
+}
+
+
?>
View
@@ -1,59 +0,0 @@
-<?PHP // $Id$
-
-/////////////////////////////////////////////////////////////
-//
-// MOD.PHP - contains functions to add, update and delete
-// an instance of this module
-//
-// Generally called from /course/mod.php
-//
-/////////////////////////////////////////////////////////////
-
-function 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 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 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;
-}
-
-
-?>
Oops, something went wrong.

0 comments on commit 04eba58

Please sign in to comment.