Tutor Moderation & Approval

Tutor Moderation & Approval

by Steve Bilton -
Number of replies: 15
Hi All,

I've been asked to implement some sort of forum postings approval / moderation system by my company director.

I have researched the moodle bug tracker and forum discussions that revolve around this much desired feature and haven't found any solutions as yet. There is the exception of a request in the bug tracker for this feature to be added as a patch to allow the functionality here : http://tracker.moodle.org/browse/MDL-16118 initiated by Bill Mounce.

My suggestion is to provide a little more freedom than to approve or deny every post.
I suggest to only interfere when an inappropriate post is created. This is much the way moodle already operates by default with the small difference of an EMAIL DELAY PERIOD for students BUT NOT TUTORS.

I want to usilise the built in time delay for editing forum posts, but not have this delay rule apply to course tutors/admins.

I.e.

The forum posting would go out imediately to tutors and admins, but have a time delay for student roles.

This would provide adequate email notification and enought time for our staff to review the forum post upon its' creation whilst not interfering with normal moodle operation unless a post with potentially 'bad' content is observered. The post can be removed before email copies are sent out to the course students.

(Also not to show the "email now" check box for students when posting to forums. I'm sure that's the easy bit smile)


I will be looking at peforming a small hack to allow this, not entirely sure how acheivable this would be, but it does seem like the most sensible approach.

The forums are not directly moderated or interferred with on a per email basis, however this does provide much better notification to those that are course moderators and provide a 'Heads-Up' warning to any potential issues that could arise or prove to be damaging.

I am hunting in the forum module files for places to edit and not having much look getting it to behave as I want.

Are there any kind moodlers out there that could point me in the right direction?

I would be most greatful for any assistance. Of course i'll post modifications I make if they are successful.

I am currently using moodle 1.8x

Don't forget to vote for the feature on the bug tracker ;-p





Average of ratings: -
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Steve Bilton -
Hi,

So far I have edited settings.php and adjusted the delay editing period to 2, 3 ,4 and 24hours options. This is now set to 24 hours and email to all user accounts are delayed by this amount of time before being emailed out.

I have been trying to edit lib.php in mod/forum/ to force the value of blockperiod in the MySQL mdl_forum table to be IGNORED for tutors and admins - 'isadmin' or 'has capability'. But I haven't quite got there yet.

When the cron runs I want email copies of the forum posts to be sent out to TUTORS and ADMINS but to wait for the designated period in the blockperiod field (in mdl_forum table) before sending email copies of forum posts to STUDENTS.

the code I need to edit seems to be in lib.php around lines 4860 - 4890 depending on the moodle version. I am using moodle 1.8+

Does any one have some suggestions to achieve this, am I missing something?
i.e. is there another file which sends out the emails appart from process_email.php in /admin/ ??

Thanks for any help

Steve
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Steve Bilton -
Ok, so once I have amened the MAXEDITINGTIME to be 24hours, 1440 mins, that's 86400 in seconds. Do this buy editing the maxeditingtime field in the database and setting it to : 86400.

To change the available options in the site settings edit the file /admin/settings/security.php

Find the code code around line 14 & add some more options:
$temp->add(new admin_setting_configselect('maxeditingtime', get_string('maxeditingtime','admin'), get_string('configmaxeditingtime','admin'), 1800,
array(60 => get_string('numminutes', '', 1),
300 => get_string('numminutes', '', 5),
900 => get_string('numminutes', '', 15),
1800 => get_string('numminutes', '', 30),
2700 => get_string('numminutes', '', 45),
3600 => get_string('numminutes', '', 60),
7200 => get_string('numminutes', '', 120),
10800 => get_string('numminutes', '', 180),
25200 => get_string('numminutes', '', 240),
86400 => get_string('numminutes', '', 1440)))); // <-- 24 hours
//finished editing maxeditingtime options.

NEXT

Find the file lib.php in /mod/forum/

Forum Customisation to allow for passive forum monitoring. Notifies admins and tutors of new posts before emailed out to subscribed users.

Customisation Sends Site administrators and Course Tutors copies of forum posts as they are created.

This allows for posts to be intercepted by a Forum moderator before copies of the post are sent to students.

Moderators can edit, delete, ignore or otherwise actively address any points or issues raised by the forum post.

Normal forum behaviour is kept with a few difference ;-
  • Adjusted maxeditingtime to 24 hours
    System will only send subscribed users emailed copies of posts 24hours after initial creation.
  • Site Admins & Course Tutors are emailed immediately any new forum post or replies
  • Site Admins can always edit forum posts (regardless of age) using this option in config.php: $CFG->admineditalways = true;

Adjustments to allow replies :
Edit the file /mod/forum/lib.php
Find the Line : 2966
Edit the following code :
// Update discussion modified date
set_field("forum_discussions", "timemodified", $post->modified, "id", $post->discussion);
set_field("forum_discussions", "usermodified", $post->userid, "id", $post->discussion);

if (forum_tp_can_track_forums($post->forum) && forum_tp_is_tracked($post->forum)) {
forum_tp_mark_post_read($post->userid, $post, $post->forum);
}
<!!INSERT CODE GOES HERE!!>
return $post->id;
}

INSERT RED CODE BETWEEN CODE IN GREEN :
forum_tp_mark_post_read($post->userid, $post, $post->forum);
}
// Steve inserted code here EMAIL ADMIN/TUTORS WHEN FORUMS ARE REPLIED TO
//========================================================================================================
//STEVE UPDATE 2nd APRIL 2009 // EMAIL ADMIN/TUTORS WHEN FORUMS ARE REPLIED TO

$to = array();
$tostr = '';
//get teachers emails and append to address
$context = get_context_instance(CONTEXT_COURSE, $post->course);
$rusers = get_role_users(3, $context);

if (!empty($rusers))
{
foreach ($rusers as $teacher)
$to[]= trim($teacher->email);
}
//get site admin emails and append to address
$scontext = get_context_instance(CONTEXT_SYSTEM);
$susers = get_role_users(1, $scontext);

if (!empty($susers))
{
foreach ($susers as $admin)
$to[]= trim($admin->email);
}

$to2 = array_unique($to);
if (!empty($to2))
{
foreach ($to2 as $em)
{
$tostr .= $em.',';
}
}

$tostr = substr($tostr,0,-1);
//create mail subject
$postsubject = stripslashes("ALERT! New Reply: ".$post->subject);
//create mail body

// $body_str = $post->message;
//$body_str = trusttext_strip($body_str);
// $body_str = substr_replace($body_str,"<br/>","\r\n");
//$body_str = strip_tags($body_str);

$body_str = stripslashes(format_text_email(trusttext_strip($post->message),'text'));

$postbody = 'New Post ('.$post->subject.') by '.$USER->firstname.' '.$USER->lastname."\r\n\r\n";
$postbody .= '---------------------------------------------------'."\r\n";
$postbody .= $body_str."\r\n"."\r\n";
$postbody .= 'Created: '.date('d/M/y H:ia',$post->created)."\r\n";
$postbody .= "\r\n";
$postbody .= $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->parent.''."\r\n";

//create email headers
$headers = "From: ".$USER->firstname." ".$USER->lastname."<".$USER->email.">\r\n";

$mailresult = mail($tostr,$postsubject,$postbody,$headers);

if (!$mailresult)
error ("Reply Mail fail..."); //========================================================================================================
//end steve forum reply code
return $post->id;
}


Adjustments to allow for Forum Updates (if updated within the 24hour maxeditingtime period):

EDIT around line: 3062
INSERT RED CODE BETWEEN CODE IN GREEN :
if (forum_tp_can_track_forums($post->forum) && forum_tp_is_tracked($post->forum)) {
forum_tp_mark_post_read($post->userid, $post, $post->forum);
}
// Steve inserted code here EMAIL ADMIN/TUTORS WHEN FORUM POSTS ARE UPDATED WITHIN 'MAXEDITINGTIME' PERIOD
//========================================================================================================
//STEVE EDIT UPDATE 2nd APRIL 2009 // EMAIL ADMIN/TUTORS WHEN FORUM POSTS ARE UPDATED WITHIN 'MAXEDITINGTIME' PERIOD


$to = array();
$tostr = '';
//get teachers emails and append to address
$context = get_context_instance(CONTEXT_COURSE, $post->course);
$rusers = get_role_users(3, $context);

if (!empty($rusers))
{
foreach ($rusers as $teacher)
$to[]= trim($teacher->email);

}
//get site admin emails and append to address
$scontext = get_context_instance(CONTEXT_SYSTEM);
$susers = get_role_users(1, $scontext);

if (!empty($susers))
{
foreach ($susers as $admin)
$to[]= trim($admin->email);

}

$to2 = array_unique($to);
if (!empty($to2))
{
foreach ($to2 as $em)
{
$tostr .= $em.',';
}
}

$tostr = substr($tostr,0,-1);
//create mail subject
$postsubject = stripslashes("ALERT! Post Update: ".$post->subject);
//create mail body

// $body_str = $post->message;
//$body_str = trusttext_strip($body_str);
// $body_str = substr_replace($body_str,"<br/>","\r\n");
//$body_str = strip_tags($body_str);

$body_str = stripslashes(format_text_email(trusttext_strip($post->message),'text'));

$postbody = 'New Post ('.$post->subject.') by '.$USER->firstname.' '.$USER->lastname."\r\n\r\n";
$postbody .= '---------------------------------------------------'."\r\n";
$postbody .= $body_str."\r\n"."\r\n";
$postbody .= 'Created: '.date('d/M/y H:ia',$post->created)."\r\n";
$postbody .= "\r\n";
$postbody .= $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->parent.''."\r\n";

//create email headers
$headers = "From: ".$USER->firstname." ".$USER->lastname."<".$USER->email.">\r\n";

$mailresult = mail($tostr,$postsubject,$postbody,$headers);

if (!$mailresult)
error ("Update Mail fail...");

//========================================================================================================
//Steve edit - END CODE FOR FORUM POSTS ARE UPDATED WITHIN 'MAXEDITINGTIME' PERIOD
return update_record("forum_posts", $post);
}

Allow for NEW Forum Discussions:

EDIT around line: 3186
INSERT RED CODE BETWEEN CODE IN GREEN :
if (forum_tp_can_track_forums($post->forum) && forum_tp_is_tracked($post->forum)) {
forum_tp_mark_post_read($post->userid, $post, $post->forum);
}


// SEND EMAIL COPIES OF NEW FORUM DISCUSSIONS TO ADMINS & TUTORS
//========================================================================================================
//STEVE EDITED CODE UPDATE 1st APRIL 2009 // SEND EMAIL COPIES OF NEW FORUM DISCUSSIONS TO ADMINS & TUTORS


$to = array();
$tostr = '';
//get teachers emails and append to address
$context = get_context_instance(CONTEXT_COURSE, $post->course);
$rusers = get_role_users(3, $context);

if (!empty($rusers))
{
foreach ($rusers as $teacher)
$to[]= trim($teacher->email);

}
//get site admin emails and append to address
$scontext = get_context_instance(CONTEXT_SYSTEM);
$susers = get_role_users(1, $scontext);

if (!empty($susers))
{
foreach ($susers as $admin)
$to[]= trim($admin->email);

}

$to2 = array_unique($to);
if (!empty($to2))
{
foreach ($to2 as $em)
{
$tostr .= $em.',';
}
}

$tostr = substr($tostr,0,-1);
//create mail subject
$postsubject = stripslashes("ALTERT! New Post: ".$discussion->name);
//create mail body

// $body_str = $post->message;
//$body_str = trusttext_strip($body_str);
// $body_str = substr_replace($body_str,"<br/>","\r\n");
//$body_str = strip_tags($body_str);

$body_str = stripslashes(format_text_email(trusttext_strip($post->message),'text'));

$postbody = 'New Post ('.$discussion->name.') by '.$USER->firstname.' '.$USER->lastname."\r\n\r\n";
$postbody .= '---------------------------------------------------'."\r\n";
$postbody .= $body_str."\r\n"."\r\n";
$postbody .= 'Created: '.date('d/M/y H:ia',$post->created)."\r\n";
$postbody .= "\r\n";
$postbody .= $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.''."\r\n";

//create email headers
$headers = "From: ".$USER->firstname." ".$USER->lastname."<".$USER->email.">\r\n";

$mailresult = mail($tostr,$postsubject,$postbody,$headers);

if (!$mailresult)
error ("Discussion Mail fail...");

//========================================================================================================
//end code 26th March updated 1st April by Steve

return $post->discussion;
}

DONE

I hope this helps someone else out.

Otherwise wait forr moodle 2.0 as moderation is going to be built in I belive.
The above method will work or 1.8 & 1.9 moodles

Steve
www.sheilds-elearning.co.uk
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Steve - Thanks for sharing your experience and work with the community. I am not sure where got the impression that moderation was going to be built in to Moodle 2.0. I am not aware of that but I could just be in the dark on it. If you have a link that explains that let me know. The list of work being done for Moodle 2.0 can be found in the Roadmap. In any case, I think you might be interested in the Forum post approval patch that I wrote in response to popular demand for CONTRIB-1085. Let me know if you have any questions or suggestions for how that work might better suit your needs. Peace - Anthony

p.s. - Just an FYI that generally speaking we try to avoid posting large sections of code in the forum post. It would probably be much more helpful to post a patch file. Moodle Docs has information on How_to_create_a_patch if you are not already familiar with the process.
Average of ratings: Useful (1)
In reply to Anthony Borrow

Re: Tutor Moderation & Approval

by Candra Mukhi -

Hi Anthony

We are trying to install the patch in our 1.93 moodle my webmaster is asking me where and how should he  install the contribution.Could you inform us about it ,thank you in advance.

In reply to Candra Mukhi

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Candra - Have your webmaster take a look at Development:How_to_apply_a_patch and then if he/she has questions let me know by sending a Moodle message or an email (anthony [a t] moodle [d o t] org). Peace -Anthony
In reply to Anthony Borrow

Re: Tutor Moderation & Approval

by Steve Bilton -
Hi Anthony,

Thanks for the reply, and i'm very glad to contribute to the moodle community.

Personally I don't like patches, unless on a clean system, they tend to break my other hacks smile
I realise if i made everything a patch this could help me avoid overwriting my previous code or indeed messing it up all together.

I will post an instructional file next time instead of the long code in forums... or a patch if it doesn't interfere with my other Moodle Medalings.

To be honest the patch is the reason why i haven't tried your moderation patch for moodle 1.9, i just plain don't like them, its' a personal preference.

Some patches are have so many changes its' hard to see how to apply all the changes without a patch.

I know it comes accross as a bit irrational, but i find irrational fears are what hold a lot of us (and companies) back from progressing as we should. I'll try applying/creating a patch the next time I do some code mods, so hopefully I can try and change my bad habits.

Don't suppose you've had any further interest in creating your patch for a 1.8(.8) moodle version (appart from myself)?

I thought I read that moderation & approval was going to be built in based on your patch for Moodle 2.0, but i obviously got this wrong, oops, sorry.

All the best

Steve
www.sheilds-elearning.co.uk


In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Steve Bilton -
Hi Anthony,

Isn't it bad to put your unlinked email address on the public forum??

(anthony [a t] moodle [d o t] org).
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Steve - When I first got involved with Moodle, I was not a big fan of patches either. Like yourself, I was suspicious as to what it was really doing. Experience with working with the code and using them has won me over. Eventually, I began making patches for each of my hacks on the production site I was running and then I know longer had to worry about things getting messed up unless the same file was getting more than one patch. In those cases, it is prudent to give them a close look and make sure they do not interfere with one another. At one point, I had a nice list of all my modifications and the affected files. If you use a tool like Eclipse it is good because you get told about potential problems merging a diff in. In any case, I understand and want you to work in the way that seems to work best for you. If you send me a patch from your system (at least any changes to the files affected by my patch), I would be willing to help you merge them so that you can test things at least on a test server. I did not look at creating a patch for 1.8 because that version had not implemented AJAX style ratings (AFAIK); however, if you want the non-AJAX (i.e. page refresh version) I would be happy to work with you on that. If you are interested, please make a comment along those lines at CONTRIB-1085. Regarding my email, you are right that it is unadvisable to put one's email address is a post (unless they really like testing their spam filter). I've gone back and changed mine. I tend not to be paranoid enough. Peace - Anthony
In reply to Anthony Borrow

Re: Tutor Moderation & Approval

by Candra Mukhi -

Hi Anthony,

So thanks for your help,now we are waiting what our webmaster can do....if some problem arise we would put in contact with you(hope that everything would be ok).

Candra

In reply to Candra Mukhi

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Candra - That would be fine. Peace - Anthony
In reply to Anthony Borrow

Re: Tutor Moderation & Approval

by Danny Yeshurun -
Hi all,

I am not sure if this is the place for this question but I have a problem with applying the patch for CONTRIB-1085.
I am using moodle 1.9.5 and here is what I get once I apply the patch:

patching file mod/forum/db/access.php
patching file mod/forum/mod_form.php
patching file mod/forum/post.php
patching file mod/forum/rate_ajax.js
Hunk #2 FAILED at 121.
1 out of 2 hunks FAILED -- saving rejects to file mod/forum/rate_ajax.js.rej
patching file mod/forum/lib.php
Hunk #14 succeeded at 3659 (offset 7 lines).
Hunk #15 succeeded at 3695 (offset 7 lines).
Hunk #16 succeeded at 3992 (offset 7 lines).
Hunk #17 succeeded at 4057 (offset 7 lines).
Hunk #18 FAILED at 4693.
Hunk #19 succeeded at 4736 (offset 7 lines).
Hunk #20 succeeded at 5098 (offset 7 lines).
Hunk #21 succeeded at 5177 (offset 7 lines).
Hunk #22 succeeded at 5198 (offset 7 lines).
Hunk #23 succeeded at 6481 (offset 7 lines).
Hunk #24 succeeded at 7020 (offset 7 lines).
1 out of 24 hunks FAILED -- saving rejects to file mod/forum/lib.php.rej
patching file mod/forum/rate.php
patching file mod/forum/rate_ajax.php
patching file lang/en_utf8/forum.php
patching file lang/en_utf8/error.php
patching file mod/forum/patch_forum_approveposts.txt


Note that the *.rej files are not created.

Any idea?

TIA,
Danny
In reply to Danny Yeshurun

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Danny - It has been a little while since I've looked at CONTRIB-1085. I believe there are a couple of existing issues I need to work on. In any case, I am not sure what is happening but if you are having trouble applying the patch let me know the exact version of Moodle you are using and I will try to get you patched versions of the files. If you can, simply upgrade to the latest 1.9.5+ (weekly build). I am assuming that you do not have any other customizations that modify these files. We should be able to get you up and running with the patch without too much trouble. I appreciate your help in testing the patch. Please report any problems you have in the tracker and I'll respond there. Peace - Anthony
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Steve Bilton -
I was wondering if someone might help me....

referenced code is from my above post : http://moodle.org/mod/forum/discuss.php?d=118408#p534575

file affected : /mod/forum/lib.php

It's fairly simple all I want is for the course shortname or fullname to appear in the subject or body of an email notification. But i can't figure out how to call for the course name thoughtful this should be very simple....

I need something like :

$postbody .= stripslashes("ALTERT! New Post: ".$discussion->name);

where is states
$discussion->name i need the course full name, but i can't seem to figure out how to get this to be called for...

I need to call something instead , ie. like the below examples, but must obviously contain the course name and output it... :

$discussion->fullname

$discussion->shortname
$posts->shortname
$course->fullname
$course->shortname
$site->fullname
$site->shortname

But I can't find what's storing the course name ....

Steve
In reply to Steve Bilton

Re: Tutor Moderation & Approval

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Steve - Isn't the shortname already included in the subject line? In the emails I receive from Moodle.org I get the course shortname. For example, take a look around line 462 in /mod/forum/lib.php in the forum_cron function:

$postsubject = "$course->shortname: ".format_string($post->subject,true);

Peace - Anthony
In reply to Anthony Borrow

Re: Tutor Moderation & Approval

by Steve Bilton -
Hi Anthony,

Yes I tried something very similar, but a blank line is returned, nothing displayed.

$postbody .= "$course->shortname: "."\r\n"; does not work.

I also tried this :
$postbody .= $forum->course."\r\n"; - also returns blank line.

MY subject code is :

$postsubject = stripslashes("ALTERT! New Post: ".$discussion->name);

I'm guessing that i need to declare the variables somewhere, but where?

Any ideas?

Thanks for your reply

Steve