You are here

function _heartbeat_array_udiff in Heartbeat 6.3

Helper function to sync default messages with messages already cached

Parameters

array $defaults:

array $cache:

Return value

array with unique default keys ready to be imported

1 call to _heartbeat_array_udiff()
heartbeat_gather_messages in ./heartbeat.module
Function that gathers all messages from all modules New ones and existing ones

File

./heartbeat.common.inc, line 194
Commonly functions used in heartbeat

Code

function _heartbeat_array_udiff($defaults, $cache) {

  // First rebuild the arrays so that the keys make sense
  $cache_array = $default_array = array();
  foreach ($cache as $cached) {
    $cache_array[$cached['message_id']] = $cached;
  }

  // Build the defaults messages array and set the unexisting keys
  foreach ($defaults as $key => $default) {
    $default_array[$default['message_id']] = $default;

    // set keys that are not defined
    if (!isset($default['perms'])) {
      $defaults[$key]['perms'] = 0;
    }
    if (!isset($default['message_type'])) {
      $defaults[$key]['message_type'] = 'normal';
    }
    if (!isset($default['message'])) {
      unset($defaults[$key]);
    }
  }
  return array_diff_assoc($default_array, $cache_array);
}