Index: user_relationships_theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_relationships/user_relationships_theme.inc,v
retrieving revision 1.6
diff -u -r1.6 user_relationships_theme.inc
--- user_relationships_theme.inc	17 Sep 2007 18:44:40 -0000	1.6
+++ user_relationships_theme.inc	18 Sep 2007 22:59:23 -0000
@@ -76,55 +76,80 @@
  */
 function theme_user_relationships_pending_requests_page($uid = NULL) {
   global $user;
-  if (empty($uid)) {
-    $uid = $user->uid;
-  }
 
-  // Check that the uid is valid, not the anonymous user, and the user exists
-  if (!(is_numeric($uid) && ($uid > 0) && $account = user_load(array('uid' => $uid)))) {
-    drupal_not_found();
-    exit();
-  }
-
-  if (sizeof($account->relationships)) {
-    $sorted = array();
-    foreach($account->relationships as $relationship) {
-      if (!$relationship->approved) {
-        $sort = $relationship->requester_id == $uid ? t('Sent Requests') : t('Received Requests');
-        $sorted[$sort][] = user_relationships_relationship_load($relationship->rid);
-      }
-    }
-    foreach ($sorted as $name => $relationships) {
-      $rows[] = array(array('data' => $name, 'header' => true, 'colspan' => 2));
-      foreach ($relationships as $relationship) {        
-        $relate_to = ($relationship->requester_id == $uid ? $relationship->requestee : $relationship->requester);
-
-        if ($account->uid == $user->uid && $relationship->requester_id == $uid) {
-          $links = theme('user_relationships_pending_request_cancel_link', $uid, $relationship->rid);
-        }
-        else {
-          $links =
-            theme('user_relationships_pending_request_approve_link', $uid, $relationship->rid) . ' | ' .
-            theme('user_relationships_pending_request_disapprove_link', $uid, $relationship->rid);
-        }
-        
-        $rows[] = array(
-          theme('username', $relate_to) . ' is a ' . $relationship->name,
-          $links
-        );
-      }
-    }
-  }
+  drupal_set_title(t("%username's pending relationships", array('%username' => $account->name)));
 
-  if (sizeof($rows)) {
-    $output .= theme('table', NULL, $rows);
+  if (NULL == $uid) {
+    $uid     =  $user->uid;
+    $account =& $user;
   }
   else {
-    $output .= t('No pending relationships found');
+    // Check that the uid is valid, not the anonymous user, and the user exists
+    if (!(is_numeric($uid) && ($uid > 0) && $account = user_load(array('uid' => $uid)))) {
+      drupal_not_found();
+      exit();
+    }
   }
 
+  // determine number of requests to display per page
+  $relationships_per_page = variable_get('user_relationships_relationships_per_page', 16);
 
-  drupal_set_title(t("%username's pending relationships", array('%username' => $account->name)));
+  // set up query-related stuff
+  $pending_sent_query  = 
+    'SELECT r.*, rt.name FROM {user_relationships} r, {user_relationship_types} rt ' .
+    'WHERE  r.requester_id=%d AND r.approved=0 AND rt.rtid = r.rtid';
+  $pending_recd_query  = 
+    'SELECT r.*, rt.name FROM {user_relationships} r, {user_relationship_types} rt ' .
+    'WHERE  r.requestee_id=%d AND r.approved=0 AND rt.rtid = r.rtid';
+  $args = array($uid);
+  $pager_sent = 0; // arbitrary integer to distinguish between 2 pagers on one page
+  $pager_recd = 1; // arbitrary integer to distinguish between 2 pagers on one page
+
+  // process pending sent requests
+  $pending_sent_requests = $relationships_per_page
+    ? pager_query($pending_sent_query, $relationships_per_page, $pager_sent, NULL, $args)
+    : db_query($pending_sent_query, $args);
+  if (db_num_rows($pending_sent_requests)) {
+    $rows[] = array(array('data' => t('Sent Requests'), 'header' => true, 'colspan' => 2));
+
+    while ($relationship = db_fetch_object($pending_sent_requests)) {
+      $relate_to = user_load(array('uid' => $relationship->requestee_id));
+      $links     = theme('user_relationships_pending_request_cancel_link', $uid, $relationship->rid);
+      $rows[]    = array(theme('username', $relate_to) . ' is a ' . $relationship->name, $links);
+    } // while ($relation = db_fetch_object($pending_sent_requests))
+
+    $output .= theme('table', array(), $rows);
+
+    if ($relationships_per_page) $output .= theme('pager', NULL, $relationships_per_page, $pager_sent);
+
+    unset($rows);
+  } // if (db_num_rows($pending_sent_requests))
+
+  // process pending received requests
+  $pending_recd_requests = $relationships_per_page
+    ? pager_query($pending_recd_query, $relationships_per_page, $pager_recd, NULL, $args)
+    : db_query($pending_recd_query, $args);
+  if (db_num_rows($pending_recd_requests)) {
+    $rows[] = array(array('data' => t('Received Requests'), 'header' => true, 'colspan' => 2));
+
+    while ($relationship = db_fetch_object($pending_recd_requests)) {
+      $relate_to = user_load(array('uid' => $relationship->requester_id));
+      $links =
+	theme('user_relationships_pending_request_approve_link',    $uid, $relationship->rid) . ' | ' .
+	theme('user_relationships_pending_request_disapprove_link', $uid, $relationship->rid);
+      $rows[] = array(theme('username', $relate_to) . ' is a ' . $relationship->name, $links);
+    } // while ($relation = db_fetch_object($pending_recd_requests))
+
+    $output .= theme('table', array(), $rows);
+
+    if ($relationships_per_page) $output .= theme('pager', NULL, $relationships_per_page, $pager_recd);
+
+    unset($rows);
+  } // if (db_num_rows($pending_recd_requests))
+
+  if (!isset($output)) {
+    $output .= t('No pending relationships found');
+  }
