You are here

function radioactivity_get_energies_for_source in Radioactivity 6

Same name and namespace in other branches
  1. 5 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);

3 calls to radioactivity_get_energies_for_source()
radioactivity_debug_add_energy_form_submit in plugins/radioactivity_debug.module
radioactivity_rules_token_values in modules/radioactivity_rules/radioactivity_rules.module
_radioactivity_add_energy_internal in ./radioactivity.inc

File

./radioactivity.inc, line 101

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 (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);

    // Default energy is 0. Try first the base class and then possible subclass.
    // e.g. if full class name is node:story, try first $decay_profile['energy']['node'][<action>]
    // and then $decay_profile['energy']['node']['subclasses']['story'][<action>]
    // The last match is the defining match
    foreach ($classparts as $part) {
      if (empty($energy[$part]) || !is_array($energy[$part])) {
        break;
      }
      $energy = $energy[$part];
      if (isset($energy[$source])) {
        $value_cand = $energy[$source];
      }
      else {
        $value_cand = FALSE;
      }
      if (strlen($value_cand) > 0) {
        $value = (double) $value_cand;
      }
      if (isset($energy['subclasses'])) {
        $energy = $energy['subclasses'];
      }
      else {
        $energy = FALSE;
      }
    }
    $ret[$dpid] = $value;
  }
  return $ret;
}