Index: views/privatemsg.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/views/privatemsg.views.inc,v retrieving revision 1.2 diff -u -p -r1.2 privatemsg.views.inc --- views/privatemsg.views.inc 30 Nov 2009 17:37:16 -0000 1.2 +++ views/privatemsg.views.inc 10 Dec 2009 02:14:29 -0000 @@ -5,7 +5,245 @@ * Provide views data and handlers for privatemsg.module */ +/** + * Implementation of hook_views_data(). + */ function privatemsg_views_data() { + // ---------------------------------------------------------------- + // privatemsg table -- basic table information. + + // Define the base group of this table. Fields that don't + // have a group defined will go into this field by default. + $data['pm_message']['table']['group'] = t('Private message'); + + // Advertise this table as a possible base table + $data['pm_message']['table']['base'] = array( + 'field' => 'mid', + 'title' => t('Private message'), + 'help' => t("Private messages sent between users."), + 'weight' => 10, + ); + + // For other base tables, explain how we join + // Join with the user table + $data['pm_message']['table']['join'] = array( + 'user' => array( + 'left_field' => 'uid', + 'field' => 'author', + ), + ); + + // ---------------------------------------------------------------- + // pm_message table -- fields + + // mid + $data['pm_message']['mid'] = array( + 'title' => t('Mesage Id'), + 'help' => t('The ID of the private message.'), + // Information for displaying the nid + 'field' => array( + 'handler' => 'views_handler_field_privatemsg', + 'click sortable' => TRUE, + ), + // Information for accepting a mid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'name field' => 'subject', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'numeric', + ), + // Information for accepting a mid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a mid. + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + ); + + // title + // This definition has more items in it than it needs to as an example. + $data['pm_message']['subject'] = array( + 'title' => t('Subject'), // The item it appears as on the UI, + 'help' => t('The subject of the message.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_privatemsg_subject', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // Body field + $data['pm_message']['body'] = array( + 'title' => t('Body'), // The item it appears as on the UI, + 'help' => t('The body of the message.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_markup', + 'format' => variable_get('filter_default_format', 1), // The name of the format field or an integer + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // author field + $data['pm_message']['author'] = array( + 'title' => t('Author'), + 'help' => t('Author of the message.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'users', + 'field' => 'uid', // join pm_message.author = user.uid + 'label' => t('Author'), + ), + 'filter' => array( + 'handler' => 'views_handler_filter_user_name', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + ); + + // created field + $data['pm_message']['timestamp'] = array( + 'title' => t('Sent date'), + 'help' => t('The date and time when the message was sent.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // ---------------------------------------------------------------------- + // privatemsg message instance table + + // Define the base group of this table. Fields that don't + // have a group defined will go into this field by default. + $data['pm_index']['table']['group'] = t('Private message'); + + // For other base tables, explain how we join + $data['pm_index']['table']['join'] = array( + // Directly links to privatemsg table. + 'pm_message' => array( + 'left_field' => 'mid', + 'field' => 'mid', + 'type' => 'INNER', + ), + // Join with the user table + 'user' => array( + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + + // mid + $data['pm_index']['thread_id'] = array( + 'title' => t('Message thread'), + 'help' => t('Messages thread ID.'), + // Information for displaying the nid + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + // Information for accepting a mid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'name field' => 'subject', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'numeric', + ), + // Information for accepting a mid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a mid. + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + ); + + // uid field + $data['pm_index']['uid'] = array( + 'title' => t('Recipient'), + 'help' => t('Relate a message to the user who received it.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'users', + 'field' => 'uid', + 'label' => t('Recipient'), + ), + 'field' => array( + 'title' => t('Participants'), + 'help' => t('Display user participants.'), + 'handler' => 'views_handler_field_privatemsg_participants', + 'skip base' => 'pm_index', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_user_name', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + ); + + $data['pm_index']['is_new'] = array( + 'title' => t('New?'), + 'help' => t('Whether the user has read this message.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + 'click sortable' => TRUE, + ), + ); + + $data['pm_index']['deleted'] = array( + 'title' => t('Deleted?'), + 'help' => t('Whether the user has deleted this message.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Deleted?'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['users']['privatemsg_link'] = array( 'group' => t('Privatemsg'), 'title' => t('Send message'), @@ -18,7 +256,6 @@ function privatemsg_views_data() { return $data; } - /** * Implementation of hook_views_handlers(). */ @@ -29,12 +266,17 @@ function privatemsg_views_handlers() { ), 'handlers' => array( // field handlers - 'views_handler_field_privatemsg_link' => array( + 'views_handler_field_privatemsg_link' => array( 'parent' => 'views_handler_field', ), + 'views_handler_field_privatemsg_subject' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_privatemsg_participants' => array( + 'parent' => 'views_handler_field_prerender_list', + ), ), ); } - Index: views/views_handler_field_privatemsg_participants.inc =================================================================== RCS file: views/views_handler_field_privatemsg_participants.inc diff -N views/views_handler_field_privatemsg_participants.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views/views_handler_field_privatemsg_participants.inc 10 Dec 2009 02:14:29 -0000 @@ -0,0 +1,5 @@ +additional_fields['mid'] = 'mid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_msg'] = array('default' => FALSE); + return $options; + } + + /** + * Provide link to node option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_msg'] = array( + '#title' => t('Link this field to its message'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_msg']), + ); + // @TODO: Add an option like Node:Title upadted mark + } + + /** + * Render whatever the data is as a link to the node. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_msg']) && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "messages/view/" . $values->{$this->aliases['mid']}; + } + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +}