You are here

function privatemsg_groups_privatemsg_name_lookup in Privatemsg 7.2

Implements hook_privatemsg_name_lookup().

File

privatemsg_groups/privatemsg_groups.module, line 209
Allows to send messages to all members of an organic group

Code

function privatemsg_groups_privatemsg_name_lookup($string) {

  // Remove optional group specifier.
  $string = trim(str_replace(t('[group]'), '', $string));
  foreach (og_get_all_group_bundle() as $group_type => $bundles) {
    $type = _privatemsg_groups_get_group_recipient_type($group_type);
    $type_info = privatemsg_recipient_get_type($type);
    if ($type_info) {
      $gids = og_get_all_group($group_type);
      $groups = entity_load($group_type, $gids);
      foreach ($groups as $gid => $group) {
        $name = entity_label($group_type, $group);
        if ($string == $name) {
          $recipient = clone $group;
          $recipient->type = $type;
          $recipient->recipient = $gid;
          return array(
            privatemsg_recipient_key($recipient) => $recipient,
          );
        }
      }
    }
  }
}