From 8a85e908251ae7120bba5a226ac94138f59c37cf Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 27 Jul 2002 06:58:39 +0000 Subject: [PATCH] Implemented journal feedback notification (mailouts) --- mod/journal/db/mysql.sql | 1 + mod/journal/lib.php | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/mod/journal/db/mysql.sql b/mod/journal/db/mysql.sql index 58763ba357..c480ce41be 100755 --- a/mod/journal/db/mysql.sql +++ b/mod/journal/db/mysql.sql @@ -40,6 +40,7 @@ CREATE TABLE journal_entries ( comment text, teacher int(10) unsigned NOT NULL default '0', timemarked int(10) unsigned NOT NULL default '0', + mailed int(1) unsigned NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM COMMENT='All the journal entries of all people'; diff --git a/mod/journal/lib.php b/mod/journal/lib.php index 09a7c087a3..3cc7b8c1f1 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -69,4 +69,81 @@ function journal_user_complete($course, $user, $mod, $journal) { } } + +function journal_cron () { +// Function to be run periodically according to the moodle cron +// Finds all journal notifications that have yet to be mailed out, and mails them + + global $CFG; + + echo "Processing journals...\n"; + + $cutofftime = time() - $CFG->maxeditingtime; + + if ($entries = get_records_sql("SELECT e.*, j.course, j.name + FROM journal_entries e, journal j + WHERE e.mailed = '0' AND + e.timemarked < '$cutofftime' AND e.timemarked > 0 + AND e.journal = j.id")) { + $timenow = time(); + + foreach ($entries as $entry) { + + echo "Processing journal entry $entry->id\n"; + + if (! $user = get_record("user", "id", "$entry->user")) { + echo "Could not find user $post->user\n"; + continue; + } + + if (! $teacher = get_record("user", "id", "$entry->teacher")) { + echo "Could not find teacher $entry->teacher\n"; + continue; + } + + if (! $course = get_record("course", "id", "$entry->course")) { + echo "Could not find course $entry->course\n"; + continue; + } + + if (! $mod = get_coursemodule_from_instance("journal", $entry->journal, $course->id)) { + echo "Could not find course module for journal id $entry->journal\n"; + continue; + } + + $postsubject = "$course->shortname: Journal feedback: $entry->name"; + $posttext = "$course->shortname -> Journals -> $entry->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= "$teacher->firstname $teacher->lastname has posted some feedback on your\n"; + $posttext .= "journal entry for '$entry->name'\n\n"; + $posttext .= "You can see it appended to your journal entry:\n"; + $posttext .= " $CFG->wwwroot/mod/journal/view.php?id=$mod->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($user->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/journal/index.php?id=$course->id\">Journals ->". + "wwwroot/mod/journal/view.php?id=$mod->id\">$entry->name

"; + $posthtml .= "
"; + $posthtml .= "

$teacher->firstname $teacher->lastname has posted some feedback on your"; + $posthtml .= " journal entry for '$entry->name'

"; + $posthtml .= "

You can see it wwwroot/mod/journal/view.php?id=$mod->id\">"; + $posthtml .= "appended to your journal entry.


"; + } else { + $posthtml = ""; + } + + if (! email_to_user($user, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: Journal cron: Could not send out mail for id $entry->id to user $user->id ($user->email)\n"; + } + if (! set_field("journal_entries", "mailed", "1", "id", "$entry->id")) { + echo "Could not update the mailed field for id $entry->id\n"; + } + } + } + + return true; +} + + ?> -- 2.39.5