diff --git a/privatemsg.module b/privatemsg.module index 93155f7..8a85fcd 100755 --- a/privatemsg.module +++ b/privatemsg.module @@ -2545,6 +2545,29 @@ function privatemsg_recipient_get_types() { } /** + * Returns an array of defined recipient type names. + * + * @return + * Array of recipient types with type + * @see hook_privatemsg_recipient_type_info() + * @see privatemsg_recipient_get_types() + * + * @ingroup types + */ +function privatemsg_recipient_get_type_options() { + $types = privatemsg_recipient_get_types(); + $typeoptions = array(); + + foreach ($types as $typecode => $type) { + $typeoptions[$typecode] = $type['name']; + } + + uasort($typeoptions, 'strnatcasecmp'); + + return $typeoptions; +} + +/** * Return a single recipient type information. * @param $type * Name of the recipient type. diff --git a/views/privatemsg.views.inc b/views/privatemsg.views.inc index 5f29d28..cc7f6e8 100644 --- a/views/privatemsg.views.inc +++ b/views/privatemsg.views.inc @@ -180,7 +180,7 @@ function privatemsg_views_data() { 'handler' => 'views_handler_sort', ), 'argument' => array( - 'help' => t("Filter according to the recipient's uid."), + 'help' => t('Filter according to the recipient\'s uid.'), 'handler' => 'views_handler_argument_user_uid', ), 'relationship' => array( @@ -190,6 +190,33 @@ function privatemsg_views_data() { 'label' => t('Recipient'), 'help' => t('Relate to the user receiving the private message.'), ), + 'filter' => array( + 'help' => t('Filter according to the recipient\'s uid.'), + 'handler' => 'views_handler_filter_user_name', + ), + ); + // $data['pm_index']['recipient'] assumes that the recipient is a user. + // This is true in most of the cases, but in advanced scenarios it can also + // be a group or something entirely custom. + $data['pm_index']['recipientraw'] = array( + 'title' => t('Recipient ID'), + 'real field' => 'recipient', + 'field' => array( + 'help' => t('The ID of the private message recipient. Useful when the recipient is not a user.'), + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'help' => t('Filter according to the recipient\'s id.'), + 'handler' => 'views_handler_argument_numeric', + ), + 'filter' => array( + 'help' => t('Filter according to the recipient\'s id.'), + 'handler' => 'views_handler_filter_numeric', + ), ); $data['pm_index']['is_new'] = array( 'title' => t('Is new'), @@ -225,6 +252,23 @@ function privatemsg_views_data() { 'type' => 'yes-no', ), ); + $data['pm_index']['type'] = array( + 'title' => t('Recipient type'), + 'help' => t('The type of the recipient. Useful when privatemsg_groups is installed.'), + 'field' => array( + 'handler' => 'views_handler_field_machine_name', + 'options callback' => 'privatemsg_recipient_get_type_options', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'help' => t('Filter on the type of recipient.'), + 'handler' => 'views_handler_filter_in_operator', + 'options callback' => 'privatemsg_recipient_get_type_options', + ), + ); return $data; }