By Alcaparra on
Hi! I try that my admins can remove flags of others users. I don't want to reset all the flags for a node ("Flag abuse module"), but I want to remove a user's flag on a particular content (no global flag). I want use this module with "Views". I try this, but it doesn't work in new module (flag_remove.module):
<?php
// $Id: flag_remove.module,v 0.1 2010/08/23 11:13:19 based in Flag Abuse by sirkitree Exp $
function flag_remove_perm() {
return array('remove flag');
}
//Here I don't know that write in event/action.
function flag_remove_preprocess_flag(&$vars) {
global $user;
// permmission check instead of a role
if (user_access('remove flag', $user)) {
// is this one of our votos flags
if (in_array($vars['flag']->name, array('servers_favorito'))) {
$vars['action'] = 'what should I write?';
$vars['link_text'] = t('Remove Flag');
$vars['link_title'] = t('Remove Flag for this user');
}
}
}
function flag_remove_flag($event, $flag, $content_id, $account) {
$myfid = 5;
$mycid = $data->nid;
$myuid = $data->users_flag_content_uid;
$mysid = 0;
// permmission check instead of a role
if (user_access('remove flag', $account)) {
// is this one of our remove flags
if (in_array($flag->name, array('remove_flag'))) {
// remove flag
$fcid = db_result(db_query("SELECT fcid FROM {flag_content} WHERE fid = $myfid AND content_id = $mycid AND uid = $myuid AND sid = $mysid", $this->fid, $content_id, $uid, $sid));
if ($fcid) {
db_query("DELETE FROM {flag_content} WHERE fcid = $fcid", $fcid);
$this->my_update_count($content_id);
}
return $fcid;
}
}
}
function my_update_count($content_id) {
$myfid = 5;
$mycid = $data->nid;
$myuid = $data->users_flag_content_uid;
$mysid = 0;
$count = db_result(db_query("SELECT COUNT(*) FROM {flag_content} WHERE fid = $myfid AND content_id = $mycid", $this->fid, $content_id));
if ($count == 0) {
db_query("DELETE FROM {flag_counts} WHERE fid = $myfid AND content_id = $myfid", $this->fid, $content_id);
}
else {
db_query("UPDATE {flag_counts} SET count = $count WHERE fid = $myfid AND content_id = $mycid", $count, $this->fid, $content_id);
if (!db_affected_rows()) {
db_query("INSERT INTO {flag_counts} (fid, content_type, content_id, count) VALUES ($myfid, 'node', $mycid, $count)", $this->fid, $this->content_type, $content_id, $count);
}
}
}