You are here

public static function drupalchatController::_drupalchat_get_buddylist in DrupalChat 8

1 call to drupalchatController::_drupalchat_get_buddylist()
drupalchatController::_drupalchat_get_user_details in src/Controller/drupalchatController.php

File

src/Controller/drupalchatController.php, line 335
Contains Drupal\drupalchat\Controller\drupalchatController

Class

drupalchatController

Namespace

Drupal\drupalchat\Controller

Code

public static function _drupalchat_get_buddylist($uid, $drupalchat_ur_name = NULL) {
  $final_list = array();
  $drupalchat_rel = \Drupal::config('drupalchat.settings')
    ->get('drupalchat_rel') ?: DRUPALCHAT_REL_AUTH;
  if ($drupalchat_ur_name == NULL) {
    $drupalchat_ur_name = \Drupal::config('drupalchat.settings')
      ->get('drupalchat_ur_name') ?: 'friend';
  }
  if ($drupalchat_rel == DRUPALCHAT_REL_UR && function_exists('user_relationships_type_load') && function_exists('user_relationships_load')) {
    $r_names = Tags::explode($drupalchat_ur_name);
    foreach ($r_names as $r_name) {
      $comp_r_name = user_relationships_type_load(array(
        'name' => $r_name,
      ), TRUE);
      $final_list[$comp_r_name->rtid]['name'] = $comp_r_name->name;
      $final_list[$comp_r_name->rtid]['plural'] = $comp_r_name->plural_name;
      $relationships = user_relationships_load(array(
        'rtid' => $comp_r_name->rtid,
        'user' => $uid,
        'approved' => 1,
      ), array(), TRUE);
      foreach ($relationships as $rid => $relationship) {
        $uid == $relationship->requester_id ? $final_list[$comp_r_name->rtid]['valid_uids'][] = $relationship->requestee_id : ($final_list[$comp_r_name->rtid]['valid_uids'][] = $relationship->requester_id);
      }
    }
  }
  else {
    if ($drupalchat_rel == DRUPALCHAT_REL_FF) {
      $fid = '1';
      $final_list[$fid]['name'] = 'friend';
      $final_list[$fid]['plural'] = 'friends';
      $result = db_query("SELECT * FROM {flag_friend} WHERE uid = :uid OR friend_uid = :uid", array(
        ':uid' => $uid,
        ':friend_uid' => $uid,
      ));
      foreach ($result as $friend) {
        $uid == $friend->uid ? $final_list[$fid]['valid_uids'][] = $friend->friend_uid : ($final_list[$fid]['valid_uids'][] = $friend->uid);
      }
    }
  }
  return $final_list;
}