Leevi,
I am trying to modify your code for a project I’m working on. Basically our client wants to allow users to flag posts that contain inappropriate content, and after 3 flags, or 5 flags close the post and bring it to an administrator’s attention. I was able to modify your code to work on a weblog post easily enough by changing instances of comment_id, etc. to entry_id, but I don’t know how to use the $DB global to say, for instance:
//Check to if/how many times the post has been flagged
$check2 = $DB->query("SELECT status FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($entry_id)."'");
// if the post has not been flagged
if ($check2->$row['status'] == 'open')
{
//change 'open' to 'one' as a mark of first flag
$DB->query($DB->update_string('exp_weblog_titles', array('status' => 'one'), array('entry_id' => $entry_id)));
//otherwise check how many times the post has been flagged and add another flag
}
if elseif ($check->row['s'] == 'one')
{
$DB->query($DB->update_string('exp_weblog_titles', array('status' => 'two'), array('entry_id' => $entry_id)));
}
if elseif ($check->row['s'] == 'two')
{
$DB->query($DB->update_string('exp_weblog_titles', array('status' => 'three'), array('entry_id' => $entry_id)));
}
if elseif ($check->row['s'] == 'three')
{
// Three strikes and you're out - mark the post as inappropriate
$DB->query($DB->update_string('exp_weblog_titles', array('status' => 'closed'), array('entry_id' => $entry_id)));
Now when I attempt to “flag” a post, nothing happens, so I know I’m not writing the $DB query correctly. Any help you could give, even if you could give me a link to a tutorial for writing $DB queries would be appreciated.
Thanks,
James at bhg Graphic Design