You are here

function activity_user in Activity 6.2

Same name and namespace in other branches
  1. 5.4 activity.module \activity_user()
  2. 6 activity.module \activity_user()

Implementation of hook_user().

File

./activity.module, line 409
Primarily Drupal hooks and global API functions to manipulate activity.

Code

function activity_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'delete') {

    // Remove all activity records for this user.
    $db_result = db_query("SELECT aid FROM {activity} WHERE uid = %d", $account->uid);
    $aids = array();
    while ($aid_obj = db_fetch_object($db_result)) {
      $aids[] = $aid_obj->aid;
    }
    activity_delete($aids);
  }
  if ($op == 'after_update') {
    if ($account->status == 0) {
      db_query("UPDATE {activity} SET status = 0 WHERE uid = %d", $account->uid);
    }
    else {
      $rows = db_query("SELECT a.aid, a.status as activity_status, a.eid, a.type, a.nid FROM {activity} a WHERE a.uid = %d", $account->uid);
      $publish = array();
      while ($row = db_fetch_object($rows)) {
        if ($row->activity_status == 0) {
          $new_status = 1;
          if (!empty($row->nid)) {
            $node_status = db_result(db_query("SELECT status FROM {node} WHERE nid = %d", $row->nid));
            $new_status = $node_status;
          }
          if ($row->type == 'comment') {
            $comment_status = db_result(db_query("SELECT status FROM {comments} WHERE cid = %d", $row->eid));
            $new_status = $new_status == 1 && $comment_status == COMMENT_PUBLISHED ? 1 : 0;
          }
          if ($new_status == 1) {
            $publish[] = $row->aid;
          }
        }
      }
      if (!empty($publish)) {
        db_query("UPDATE {activity} SET status = 1 WHERE aid IN (" . db_placeholders($publish) . ")", $publish);
      }
    }
  }
}