You are here

function radioactivity_live_incident_storage::add_incident in Radioactivity 7

Overrides radioactivity_incident_storage::add_incident

File

storage/radioactivity_live_incident_storage.php, line 16

Class

radioactivity_live_incident_storage

Code

function add_incident($entities, $energy = null) {
  static $time_now = NULL;
  if ($time_now == NULL) {
    $time_now = time();
  }
  if ($energy == NULL) {
    $energy = $this->incident_energy;
  }
  foreach ($entities as $entity_type => $entities_id) {
    $info = entity_get_info($entity_type);
    $id = $info['entity keys']['id'];
    $bundle = $info['bundle keys']['bundle'];
    $entities_loaded = entity_load($entity_type, $entities_id);
    foreach ($entities_loaded as $entity_id => $entity) {

      /*
      $temp = new stdClass();

      $temp->{$id} = $entity_id;
      if ($bundle) {
        $temp->{$bundle} = $entity->{$bundle};
      }
      */
      $l = $entity->language;
      if (!isset($entity->{$this->field_name})) {
        $value = 0;
        $entity->{$this->field_name} = array(
          $l => array(
            0 => array(
              RADIOACTIVITY_FIELD_ENERGY => 0,
              RADIOACTIVITY_FIELD_TIMESTAMP => 0,
            ),
          ),
        );
      }
      else {
        $value = $entity->{$this->field_name}[$l][0][RADIOACTIVITY_FIELD_ENERGY];
      }
      $value += $energy;
      $entity->{$this->field_name}[$l][0][RADIOACTIVITY_FIELD_ENERGY] = $value;
      field_attach_update($entity_type, $entity);
    }
  }

  // foreach
}