function privatemsg_list

1 privatemsg.module privatemsg_list(&$form_state, $argument = 'list', $uid = NULL)
7-1 privatemsg.pages.inc privatemsg_list($form, &$form_state, $argument, $account)
7-2 privatemsg.pages.inc privatemsg_list($form, &$form_state, $argument, $account)
6-2 privatemsg.pages.inc privatemsg_list(&$form_state, $argument, $account)
1 string reference to 'privatemsg_list'

File

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

Code

function privatemsg_list($form, &$form_state, $argument, $account) {
  // 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 themed list headers based on the available data.
  $headers = privatemsg_get_headers(TRUE);

  $form = array(
    '#list_argument' => $argument,
    '#submit' => array('privatemsg_list_submit'),
    'updated' => array(
      '#prefix' => '<div id="privatemsg-list-form">',
      '#suffix' => '</div>',
    ),
    '#attached' => array('css' => array(drupal_get_path('module', 'privatemsg') . '/styles/privatemsg-list.css')),
  );
  $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'])) {
    // Load the last reply that is not from the current user.
    $result = db_query('SELECT pmi.thread_id, MAX(pm.mid) AS last_message FROM {pm_message} pm INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid WHERE pmi.thread_id IN (:thread_ids) AND pm.author <> :current_uid GROUP BY pmi.thread_id', array(':current_uid' => $account->uid, ':thread_ids' => array_keys($form['updated']['list']['#options'])));
    foreach ($result as $row) {
      // Set replied flag if there is no newer message from another user than
      // the last replied.
      if ($row->last_message <= $form['updated']['list']['#options'][$row->thread_id]['last_reply_to_mid']) {
        $form['updated']['list']['#options'][$row->thread_id]['is_replied'] = TRUE;
      }
    }

    $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;
}