mirror of
https://github.com/moodle/moodle.git
synced 2025-01-22 08:11:26 +01:00
155 lines
5.8 KiB
PHP
155 lines
5.8 KiB
PHP
<?PHP // $Id$
|
|
|
|
$RATING = array ("3" => "Outstanding",
|
|
"2" => "Satisfactory",
|
|
"1" => "Not satisfactory");
|
|
|
|
|
|
function journal_user_summary($course, $user, $mod, $journal) {
|
|
global $CFG;
|
|
}
|
|
|
|
|
|
function journal_user_outline($course, $user, $mod, $journal) {
|
|
if ($entry = get_record_sql("SELECT * FROM journal_entries
|
|
WHERE user='$user->id' AND journal='$journal->id'")) {
|
|
|
|
$numwords = count(preg_split("/\w\b/", $entry->text)) - 1;
|
|
|
|
$result->info = "$numwords words";
|
|
$result->time = $entry->modified;
|
|
return $result;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
|
|
function journal_user_complete($course, $user, $mod, $journal) {
|
|
global $CFG, $THEME;
|
|
|
|
if ($entry = get_record_sql("SELECT * FROM journal_entries
|
|
WHERE user='$user->id' AND journal='$journal->id'")) {
|
|
|
|
print_simple_box_start();
|
|
if ($entry->modified) {
|
|
echo "<P><FONT SIZE=1>Last edited: ".userdate($entry->modified)."</FONT></P>";
|
|
}
|
|
if ($entry->text) {
|
|
echo text_to_html($entry->text);
|
|
}
|
|
if ($entry->teacher) {
|
|
$teacher = get_record("user", "id", $entry->teacher);
|
|
|
|
echo "\n<BR CLEAR=ALL>";
|
|
echo "<TABLE><TR>";
|
|
echo "<TD WIDTH=35 VALIGN=TOP>";
|
|
print_user_picture($entry->teacher, $course->id, $teacher->picture);
|
|
echo "<TD BGCOLOR=\"$THEME->cellheading\">".$RATING[$entry->rating];
|
|
if ($entry->timemarked) {
|
|
echo " <FONT SIZE=1>".userdate($entry->timemarked)."</FONT>";
|
|
}
|
|
echo "<P ALIGN=RIGHT><FONT SIZE=-1><I>";
|
|
if ($RATING[$entry->rating]) {
|
|
echo "Overall rating: ";
|
|
echo $RATING[$entry->rating];
|
|
} else {
|
|
echo "No rating given";
|
|
}
|
|
echo "</I></FONT></P>";
|
|
|
|
echo "<BR><FONT COLOR=#000055>";
|
|
echo text_to_html($entry->comment);
|
|
echo "</FONT><BR>";
|
|
echo "</TD></TR></TABLE>";
|
|
}
|
|
print_simple_box_end();
|
|
|
|
} else {
|
|
echo "No entry";
|
|
}
|
|
}
|
|
|
|
|
|
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 (! $course = get_record("course", "id", "$entry->course")) {
|
|
echo "Could not find course $entry->course\n";
|
|
continue;
|
|
}
|
|
|
|
if (! isstudent($course->id, $user->id) and !isteacher($course->id, $user->id)) {
|
|
continue; // Not an active participant
|
|
}
|
|
|
|
if (! $teacher = get_record("user", "id", "$entry->teacher")) {
|
|
echo "Could not find teacher $entry->teacher\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 = "<P><FONT FACE=sans-serif>".
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
|
|
"<A HREF=\"$CFG->wwwroot/mod/journal/index.php?id=$course->id\">Journals</A> ->".
|
|
"<A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$mod->id\">$entry->name</A></FONT></P>";
|
|
$posthtml .= "<HR><FONT FACE=sans-serif>";
|
|
$posthtml .= "<P>$teacher->firstname $teacher->lastname has posted some feedback on your";
|
|
$posthtml .= " journal entry for '<B>$entry->name</B>'</P>";
|
|
$posthtml .= "<P>You can see it <A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$mod->id\">";
|
|
$posthtml .= "appended to your journal entry</A>.</P></FONT><HR>";
|
|
} 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;
|
|
}
|
|
|
|
|
|
?>
|