You are here

function activity_comment in Activity 6.2

Implementation of hook_comment().

File

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

Code

function activity_comment(&$comment, $op) {
  if ($op == 'delete') {
    $db_result = db_query("SELECT aid FROM {activity} WHERE type = 'comment' AND eid = %d", $comment->cid);
    $aids = array();
    while ($aid_obj = db_fetch_object($db_result)) {
      $aids[] = $aid_obj->aid;
    }
    activity_delete($aids);
  }
  if ($op == 'publish') {
    $rows = db_query("SELECT a.aid, a.status as activity_status, u.status as user_status, n.status as node_status FROM {activity} a INNER JOIN {users} u ON a.uid = u.uid INNER JOIN {node} n ON a.nid = n.nid WHERE a.uid <> 0 AND a.type = 'comment' AND a.eid = %d", $comment['cid']);
    $update_statuses = array();
    while ($row = db_fetch_object($rows)) {
      $new_status = $row->user_status == 1 && $row->node_status == 1 ? 1 : 0;
      if ($new_status != $row->activity_status) {
        $update_statuses[$new_status][] = $row->aid;
      }
    }
    foreach ($update_statuses as $status => $aids) {
      $arguments = $aids;
      array_unshift($arguments, $status);
      db_query("UPDATE {activity} SET status = %d WHERE aid IN (" . db_placeholders($aids) . ")", $arguments);
    }
  }
  if ($op == 'unpublish') {
    db_query("UPDATE {activity} SET status = 0 WHERE type = 'comment' AND eid = %d", $comment->cid);
  }
}