You are here

function commons_radioactivity_incident_node in Drupal Commons 7.3

Helper function to create Radioactivity incidents for nodes.

Parameters

$node: The node which will have its radioactivity modified.

$value: The value by which to modify the node's radioactivity.

10 calls to commons_radioactivity_incident_node()
commons_radioactivity_comment_delete in modules/commons/commons_radioactivity/includes/incidents/commons_radioactivity.incidents_comment.inc
Implements hook_comment_delete().
commons_radioactivity_comment_insert in modules/commons/commons_radioactivity/includes/incidents/commons_radioactivity.incidents_comment.inc
Implements hook_comment_insert().
commons_radioactivity_comment_publish in modules/commons/commons_radioactivity/includes/incidents/commons_radioactivity.incidents_comment.inc
Implements hook_comment_publish().
commons_radioactivity_comment_unpublish in modules/commons/commons_radioactivity/includes/incidents/commons_radioactivity.incidents_comment.inc
Implements hook_comment_unpublish().
commons_radioactivity_flag_flag in modules/commons/commons_radioactivity/includes/incidents/commons_radioactivity.incidents_flag.inc
Implements hook_flag_flag().

... See full list

File

modules/commons/commons_radioactivity/commons_radioactivity.module, line 97
Code for the Commons Radioactivity feature.

Code

function commons_radioactivity_incident_node($node, $value) {

  // Only operate on nodes that have the radioactivity field.
  if (!empty($node->field_radioactivity)) {

    // Find the node's ID and bundle.
    list($id, , $bundle) = entity_extract_ids('node', $node);

    // Prevent groups from going negative in energy.
    if ($bundle == 'group' && $node->field_radioactivity[LANGUAGE_NONE][0]['radioactivity_energy'] + $value >= 0) {

      // Get an instance of the incident storage for the radioactivity field.
      $profile = radioactivity_get_field_profile('node', $bundle, 'field_radioactivity');

      // Trigger a radioactivity incident.
      if ($profile && $profile->storageObject) {
        $profile->storageObject
          ->addIncident(new RadioactivityIncident('node', $bundle, 'field_radioactivity', LANGUAGE_NONE, $id, $value, time(), FALSE));
      }
    }
  }
}