You are here

function _casetracker_change_event in Case Tracker 7

Detects and fires a casetracker rules change event. One event will be fired regardless of the number of items in the casetracker that change.

Parameters

$node: Node object of the case

$old_record: case tracker data for the old record,

$new_record: casee tracker data for the new record.

4 calls to _casetracker_change_event()
casetracker_comment_insert in ./casetracker.module
Implements hook_comment_insert().
casetracker_comment_update in ./casetracker.module
Implements hook_comment_update().
casetracker_node_insert in ./casetracker.module
Implements hook_node_insert().
casetracker_node_update in ./casetracker.module
Implements hook_node_update().

File

./casetracker.module, line 284
Enables the handling of projects and their cases.

Code

function _casetracker_change_event($node, $old_record, $new_record) {
  if (is_callable('rules_invoke_event')) {
    $changes = array();
    if (!$old_record || $old_record->case_status_id != $new_record->case_status_id) {
      $changes[] = 'status';
    }
    if (!$old_record || $old_record->case_priority_id != $new_record->case_priority_id) {
      $changes[] = 'priority';
    }
    if (!$old_record || $old_record->case_type_id != $new_record->case_type_id) {
      $changes[] = 'type';
    }
    if (!$old_record || $old_record->pid != $new_record->pid) {
      $changes[] = 'project';
    }
    if ($changes) {
      $type = casetracker_case_state_load($new_record->case_type_id);
      $priority = casetracker_case_state_load($new_record->case_priority_id);
      $status = casetracker_case_state_load($new_record->case_status_id);
      $casetracker = new stdClass();
      $casetracker->status_id = $new_record->case_status_id;
      $casetracker->status = $status->name;
      $casetracker->priority_id = $new_record->case_priority_id;
      $casetracker->priority = $priority->name;
      $casetracker->type_id = $new_record->case_type_id;
      $casetracker->type = $type->name;
      $casetracker->assign_to = $new_record->assign_to;
      $casetracker->pid = $new_record->pid;
      $casetracker->changes = $changes;
      rules_invoke_event('casetracker_state_change', $node, $casetracker);
    }
  }
}