You are here

class radioactivity_live_incident_storage in Radioactivity 7

Hierarchy

Expanded class hierarchy of radioactivity_live_incident_storage

File

storage/radioactivity_live_incident_storage.php, line 3

View source
class radioactivity_live_incident_storage extends radioactivity_incident_storage {

  /**
   * Constructor
   * @param unknown_type $field_id
   */
  public function __construct($field_id) {
    parent::__construct($field_id);
  }
  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
  }

}

Members