You are here

function _casetracker_actions_update_by_comment in Case Tracker 7

Same name and namespace in other branches
  1. 6 casetracker_actions/casetracker_actions.module \_casetracker_actions_update_by_comment()

Update case by programmatically inserting a comment posted by current user.

1 call to _casetracker_actions_update_by_comment()
_casetracker_actions_act in casetracker_actions/casetracker_actions.module
generalized casetracker update function All casetracker actions have the same fundamental behavior.

File

casetracker_actions/casetracker_actions.module, line 304
casetracker_actions.module

Code

function _casetracker_actions_update_by_comment($field, $value, $node) {
  global $user;
  if (user_access('post comments') && (user_access('administer comments') || node_comment_mode($nid) == COMMENT_NODE_READ_WRITE)) {
    $case_info = get_object_vars($node->casetracker);
    $case_info[$field] = $field == 'assign_to' ? casetracker_get_name($value) : $value;
    if ($field != 'assign_to') {
      $case_info['assign_to'] = casetracker_get_name($case_info['assign_to']);
    }

    // casetracker uses revision_id as a primary key for casetracker_case table.
    $edit = array(
      'nid' => $node->nid,
      'pid' => 0,
      // comment parent id
      'comment' => t('Case changed in bulk update.'),
      // comment body
      'subject' => t('Update'),
      'uid' => $user->uid,
      'revision_id' => $node->vid,
      'casetracker' => $case_info,
    );
    return comment_save($edit);
  }
  drupal_set_message(t('You may not post an update to case #%nid. Either you do not have the necessary permissions or the case has been locked.', array(
    '%nid' => $nid,
  )));
  return 0;
}