You are here

function redhen_activity_source_entity in RedHen CRM 7

Return the source entity of an activity message.

Parameters

$message:

Return value

mixed

1 call to redhen_activity_source_entity()
redhen_activity_activity_page in modules/redhen_activity/redhen_activity.module
Page callback for a list of activities.

File

modules/redhen_activity/redhen_activity.module, line 667

Code

function redhen_activity_source_entity($message) {
  switch ($message->type) {
    case 'redhen_engagement':
    case 'redhen_contact':
      $ref_field = 'message_redhen_contact';
      $ref_entity_type = 'redhen_contact';
      break;
    case 'redhen_org':
      $ref_field = 'message_redhen_org';
      $ref_entity_type = 'redhen_org';
      break;
    case 'redhen_relation':
    case 'redhen_note':
    case 'redhen_membership':
      if (!empty($message->message_redhen_contact)) {
        $ref_field = 'message_redhen_contact';
        $ref_entity_type = 'redhen_contact';
      }
      else {
        $ref_field = 'message_redhen_org';
        $ref_entity_type = 'redhen_org';
      }
      break;
  }
  $source_entity = entity_load_single($ref_entity_type, $message->{$ref_field}[LANGUAGE_NONE][0]['target_id']);
  return $source_entity;
}