You are here

function friend_selector_process in Drupal for Facebook 5

File

./fb_form.module, line 341
This module defines facebook-specific form elements for use with Drupal's form API.

Code

function friend_selector_process($orig) {
  global $fb;
  if (!$fb) {

    // TODO: Handle this better.
    return;
  }
  static $options = NULL;
  if (!$options) {
    $query = "SELECT last_name, first_name, uid, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=" . fb_facebook_user() . ")";
    $result = $fb->api_client
      ->fql_query($query);

    // TODO: sort results by name
    $options = array();
    foreach ($result as $data) {
      $options[$data['uid']] = $data['first_name'] . ' ' . $data['last_name'];
    }
  }

  // TODO: display small picture along with name in select box.
  $element = array();
  foreach (array(
    '#title',
    '#parents',
    '#description',
    '#default_value',
    '#weight',
    '#multiple',
    '#required',
    '#name',
    '#value',
  ) as $key) {
    if (isset($orig[$key])) {
      $element[$key] = $orig[$key];
    }
  }
  $element['#type'] = 'select';
  $element['#options'] = $options;

  //drupal_set_message("fb_form processed " . dpr($orig, 1) . " into " . dpr($element, 1));
  return $element;
}