public static function drupalchatController::_drupalchat_get_user_details in DrupalChat 8
2 calls to drupalchatController::_drupalchat_get_user_details()
File
- src/
Controller/ drupalchatController.php, line 819 - Contains Drupal\drupalchat\Controller\drupalchatController
Class
Namespace
Drupal\drupalchat\ControllerCode
public static function _drupalchat_get_user_details() {
$user = \Drupal::currentUser();
$user_id = $user
->id();
$account = \Drupal\user\Entity\User::load(\Drupal::currentUser()
->id());
if (\Drupal::currentUser()
->hasPermission('administer drupalchat')) {
$chat_role = "admin";
}
else {
if (\Drupal::currentUser()
->hasPermission('moderate drupalchat')) {
$chat_role = "moderator";
}
else {
$chat_role = "participant";
}
}
$hook_user_name = '';
$hook_user_avatar_url = '';
$hook_user_profile_url = '';
$hook_user_roles = array();
\Drupal::moduleHandler()
->alter('drupalchat_get_username', $hook_user_name, $user_id);
\Drupal::moduleHandler()
->alter('drupalchat_get_user_avatar_url', $hook_user_avatar_url, $user_id);
\Drupal::moduleHandler()
->alter('drupalchat_get_user_profile_url', $hook_user_profile_url, $user_id);
\Drupal::moduleHandler()
->alter('drupalchat_get_user_roles', $hook_user_roles, $user_id);
$userSiteRoles = user_role_names();
// if(\Drupal::currentUser()->hasPermission('administer drupalchat')) {
// $role = "admin";
// }
// else {
// $role = array();
// $userRole = \Drupal::currentUser()->getRoles();
// //print_r(gettype($roles));
// for($index = 0; $index < sizeof($userRole); $index++){
// $role[(string)$userRole[$index]] = $userSiteRoles[$userRole[$index]];
// }
// // print_r($role);
// }
if (!empty($hook_user_roles)) {
$role = $hook_user_roles;
}
else {
// $role = $user->roles;
if (\Drupal::currentUser()
->hasPermission('administer drupalchat')) {
$role = "admin";
}
else {
$role = array();
$userRole = \Drupal::currentUser()
->getRoles();
//print_r(gettype($roles));
for ($index = 0; $index < sizeof($userRole); $index++) {
$role[(string) $userRole[$index]] = $userSiteRoles[$userRole[$index]];
}
// print_r($role);
}
}
if (!empty($hook_user_name)) {
$user_name = $hook_user_name;
}
else {
$user_name = Html::escape(user_format_name($account));
}
$data = array(
'user_name' => $user_name,
'user_id' => $user_id,
'user_roles' => $role,
'chat_role' => $chat_role,
'user_status' => '1',
'user_list_filter' => 'all',
);
if ($chat_role == 'admin' || $chat_role == 'moderator') {
$data['user_site_roles'] = $userSiteRoles;
}
if (!empty($hook_user_avatar_url)) {
$data['user_avatar_url'] = $hook_user_avatar_url;
}
else {
$data['user_avatar_url'] = drupalchatController::drupalchat_return_pic_url();
}
if (!empty($hook_user_profile_url)) {
$data['user_profile_url'] = $hook_user_profile_url;
}
else {
$data['user_profile_url'] = drupalchatController::drupalchat_return_profile_url();
}
$hook_user_friends = array();
$hook_user_groups = array();
\Drupal::moduleHandler()
->alter('drupalchat_get_groups', $hook_user_groups, $user_id);
\Drupal::moduleHandler()
->alter('drupalchat_get_friends', $hook_user_friends, $user_id);
$drupalchat_rel = \Drupal::config('drupalchat.settings')
->get('drupalchat_rel') ?: DRUPALCHAT_REL_AUTH;
if ($drupalchat_rel == DRUPALCHAT_REL_OG) {
$user_groups = drupalchatController::_drupalchat_get_groups($user->uid);
if (!empty($user_groups)) {
$data['user_list_filter'] = 'group';
$data['user_groups'] = $user_groups;
}
}
else {
if ($drupalchat_rel > DRUPALCHAT_REL_AUTH) {
$data['user_list_filter'] = 'friend';
$new_valid_uids = drupalchatController::_drupalchat_get_buddylist($user->uid);
if (!isset($_SESSION['drupalchat_user_roster_list']) || $_SESSION['drupalchat_user_roster_list'] != $new_valid_uids) {
$data['user_relationships'] = $new_valid_uids;
$_SESSION['drupalchat_user_roster_list'] = $new_valid_uids;
}
else {
$data['user_relationships'] = $new_valid_uids;
}
}
else {
if (!empty($hook_user_friends)) {
$data['user_list_filter'] = 'friend';
$final_list = array();
$final_list['1']['name'] = 'friend';
$final_list['1']['plural'] = 'friends';
$final_list['1']['valid_uids'] = $hook_user_friends;
$data['user_relationships'] = $final_list;
}
else {
if (!empty($hook_user_groups)) {
$data['user_list_filter'] = 'group';
$data['user_groups'] = $hook_user_groups;
}
}
}
}
return $data;
}