You are here

function message_save_message_to_realms in Message 6

API function; Save a message instance and save it to realms.

Parameters

$message_name: The message name.

$entity_type: The entity type.

$etid: The entity ID.

$arguments: Optional; Array of arguments to pass to the callback function.

$realms: Optioanl; An array of arrays keyed with the realm ID. If no realms are provided then a the message instance will be assigned by default to the user realm, with the user ID as the realm ID.

$account: Optional; The user object, if empty the logged in user will be used.

$extra_identifier: Optioanl; The string value to save as the extra identfier.

3 calls to message_save_message_to_realms()
message_example_comment in modules/message_example/message_example.module
Implementation of hook_comment().
message_example_flag in modules/message_example/message_example.module
Implementation of hook_flag().
message_example_nodeapi in modules/message_example/message_example.module
Implementation of hook_nodeapi().

File

./message.module, line 237
API functions to manipulate messages.

Code

function message_save_message_to_realms($message_name, $entity_type, $eid, $arguments = array(), $realms = array(), $account = NULL, $extra_identifier = '') {
  if (empty($account)) {
    global $user;
    $account = drupal_clone($user);
  }
  $return = array();

  // Create message instance.
  $message_instance = new stdClass();
  $message_instance->name = $message_name;
  $message_instance->uid = $account->uid;
  $message_instance->entity_type = $entity_type;
  $message_instance->eid = $eid;
  $message_instance->arguments = $arguments;
  $message_instance->extra_identifier = $extra_identifier;
  $message_instance = message_instance_save($message_instance);
  $return['message instance'] = $message_instance;
  if (empty($realms)) {

    // Set default realm.
    $realms[] = array(
      'realm' => 'user',
      'realm id' => $account->uid,
    );
  }

  // Save to the realms.
  foreach ($realms as $value) {
    $realm = new stdClass();
    $realm->iid = $message_instance->iid;
    $realm->realm = $value['realm'];
    $realm->realm_id = $value['realm id'];
    $return['message realm'][] = message_realm_save($realm);
  }
  return $return;
}