You are here

function flag_user in Flag 5

Same name and namespace in other branches
  1. 6.2 flag.module \flag_user()
  2. 6 flag.module \flag_user()

Implementation of hook_user().

1 string reference to 'flag_user'
flag_flag_definitions in ./flag.inc
Implementation of hook_flag_definitions().

File

./flag.module, line 342
The Flag module.

Code

function flag_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'delete':

      // Remove flags by this user.
      $result = db_query("SELECT fc.fid, fc.content_id, c.count FROM {flag_content} fc LEFT JOIN {flag_counts} c ON fc.content_id = c.content_id AND fc.content_type = c.content_type WHERE fc.uid = %d", $account->uid);
      while ($flag_data = db_fetch_object($result)) {
        $flag_data->count--;
        db_query("UPDATE {flag_counts} SET count = %d WHERE fid = %d AND content_id = %d", $flag_data->count, $flag_data->fid, $flag_data->content_id);
      }
      db_query("DELETE FROM {flag_content} WHERE uid = %d", $account->uid);
      break;
    case 'view':
      $items = array();
      $flags = flag_get_flags('user');
      foreach ($flags as $flag) {
        if (!$flag
          ->user_access()) {

          // User has no permission to use this flag.
          continue;
        }
        if (!$flag
          ->applies_to_content_object($account)) {

          // Flag does not apply to this content.
          continue;
        }
        if (!$flag
          ->uses_hook_link(array())) {

          // Flag not set to appear on profile.
          continue;
        }
        $items[t('Actions')] = array(
          array(
            'title' => $flag
              ->get_title($account->uid),
            'value' => $flag
              ->theme($flag
              ->is_flagged($account->uid) ? 'unflag' : 'flag', $account->uid),
            'class' => 'profile-' . $flag->name,
          ),
        );
      }
      return $items;
  }
}