You are here

function radioactivity_get_energies_for_source in Radioactivity 5

Same name and namespace in other branches
  1. 6 radioactivity.inc \radioactivity_get_energies_for_source()

Return energies for source action.

Parameters

$oid:

$oclass Base class, e.g. 'node'. Subclass will be resolved by subclass_resolver hook if necessary:

$source Energy source, e.g. 'view':

Return value

array of dpid to energy, e.g, array(1 => 3.4, 2 => 5.6);

1 call to radioactivity_get_energies_for_source()
_radioactivity_add_energy_internal in ./radioactivity.inc

File

./radioactivity.inc, line 92

Code

function radioactivity_get_energies_for_source($oid, $oclass, $source) {
  $ret = array();
  foreach (_radioactivity_get_decay_profiles() as $dpid => $decay_profile) {
    $classname = $oclass;

    // the default class name
    // check if we need to resolve full classname
    if (isset($decay_profile['energy'][$oclass]['subclasses']) && is_array($decay_profile['energy'][$oclass]['subclasses'])) {
      foreach ($decay_profile['energy'][$oclass]['subclasses'] as $subsources) {
        if (isset($subsources[$source])) {

          // there is subclass specific energy value for the source, so
          // resolve subclass
          $classname = _radioactivity_resolve_classname($oid, $oclass);
          break;
        }
      }
    }

    // resolve energy amount
    $energy = $decay_profile['energy'];
    $value = 0;
    $classparts = explode(':', $classname);
    foreach ($classparts as $part) {
      if (!isset($energy[$part]) || !is_array($energy[$part])) {
        break;
      }
      $energy = $energy[$part];
      $value_cand = isset($energy[$source]) ? $energy[$source] : FALSE;
      if (strlen($value_cand) > 0) {
        $value = (double) $value_cand;
      }
      $energy = isset($energy['subclasses']) ? $energy['subclasses'] : FALSE;
    }
    $ret[$dpid] = $value;
  }
  return $ret;
}