You are here

function privatemsg_list in Privatemsg 7

Same name and namespace in other branches
  1. 5.3 privatemsg.module \privatemsg_list()
  2. 5 privatemsg.module \privatemsg_list()
  3. 6.2 privatemsg.pages.inc \privatemsg_list()
  4. 6 privatemsg.module \privatemsg_list()
  5. 7.2 privatemsg.pages.inc \privatemsg_list()
1 string reference to 'privatemsg_list'
privatemsg_list_page in ./privatemsg.pages.inc
List messages.

File

./privatemsg.pages.inc, line 157
User menu callbacks for Privatemsg.

Code

function privatemsg_list($form, &$form_state, $argument, $account) {
  drupal_add_css(drupal_get_path('module', 'privatemsg') . '/styles/privatemsg-list.css');

  // If this is an AJAX request, update $_GET['q'] so that table sorting and
  // similar links are using the correct base path.
  if ($_GET['q'] == 'system/ajax') {
    $q = 'messages';
    if (!empty($argument)) {
      $q .= '/' . $argument;
    }
    $_GET['q'] = $q;
  }

  // Load the table columns.
  $columns = array_merge(array(
    'subject',
    'last_updated',
  ), array_filter(variable_get('privatemsg_display_fields', array(
    'participants',
  ))));

  // Load the themed list headers based on the available data.
  $headers = _privatemsg_list_headers($columns);
  $form = array(
    '#list_argument' => $argument,
    '#submit' => array(
      'privatemsg_list_submit',
    ),
    'updated' => array(
      '#prefix' => '<div id="privatemsg-list-form">',
      '#suffix' => '</div>',
    ),
  );
  $form['updated']['list'] = array(
    '#type' => 'tableselect',
    '#header' => $headers,
    '#options' => array(),
    '#attributes' => array(
      'class' => array(
        'privatemsg-list',
      ),
    ),
    '#empty' => t('No messages available.'),
    '#weight' => 5,
    '#pre_render' => array(
      '_privatemsg_list_thread',
    ),
  );
  $query = _privatemsg_assemble_query('list', $account, $argument);
  $i = 0;
  foreach ($query
    ->execute() as $row) {

    // Store the raw row data.
    $form['updated']['list']['#options'][$row->thread_id] = (array) $row;

    // Tableselect sorts the options, set a weight so that the order doesn't get
    // changed.
    $form['updated']['list']['#options'][$row->thread_id]['#weight'] = $i++;
  }
  if (!empty($form['updated']['list']['#options'])) {
    $form['updated']['actions'] = _privatemsg_action_form($argument);
  }

  // Save the currently active account, used for actions.
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );

  // Define checkboxes, pager and theme
  $form['updated']['pager'] = array(
    '#markup' => theme('pager'),
    '#weight' => 20,
  );
  return $form;
}