You are here

function _radioactivity_add_energy_internal in Radioactivity 5

Same name and namespace in other branches
  1. 6 radioactivity.inc \_radioactivity_add_energy_internal()
2 calls to _radioactivity_add_energy_internal()
radioactivity_add_energy in ./radioactivity.inc
Add energy to nodes.
radioactivity_process_memcached_entries in ./radioactivity.module

File

./radioactivity.inc, line 178

Code

function _radioactivity_add_energy_internal($oid, $oclass, $source, $multiplier = 1) {
  $db_type = $GLOBALS['db_type'];
  $timestamp = time();
  $energies = radioactivity_get_energies_for_source($oid, $oclass, $source);
  foreach ($energies as $dpid => $amount) {
    if ($amount == 0) {
      continue;
    }

    // multiply amount by multiplier
    $amount *= $multiplier;

    // remap id if necessary
    $oid = _radioactivity_possibly_remap_id($oid, $oclass);
    switch ($db_type) {
      case 'mysql':
      case 'mysqli':
        _radioactivity_add_energy_mysql($oid, $oclass, $dpid, $amount, $timestamp);
        break;
      case 'pgsql':
        _radioactivity_add_energy_std($oid, $oclass, $dpid, $amount, $timestamp);
        break;
      default:
        watchdog('radioactivity', t('Unsupported database: @db_type', array(
          '@db_type' => $db_type,
        )), WATCHDOG_ERROR);
        return FALSE;
    }
  }
  return TRUE;
}