ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOnScreenChatUserDataProvider.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
12  protected $db;
13 
17  protected $user;
18 
25  {
26  $this->db = $db;
27  $this->user = $user;
28  }
29 
34  public function getInitialUserProfileData()
35  {
36  $conversationIds = [];
37 
38  $res = $this->db->queryF(
39  'SELECT DISTINCT(conversation_id) FROM osc_activity WHERE user_id = %s',
40  ['integer'],
41  [$this->user->getId()]
42  );
43  while ($row = $this->db->fetchAssoc($res)) {
44  $conversationIds[$row['conversation_id']] = $row['conversation_id'];
45  }
46 
47  $res = $this->db->queryF(
48  'SELECT DISTINCT(conversation_id) FROM osc_messages WHERE user_id = %s',
49  ['integer'],
50  [$this->user->getId()]
51  );
52  while ($row = $this->db->fetchAssoc($res)) {
53  $conversationIds[$row['conversation_id']] = $row['conversation_id'];
54  }
55 
56  if (0 === count($conversationIds)) {
57  return [];
58  }
59 
60  $usrIds = [];
61 
62  $in = $this->db->in('id', $conversationIds, false, 'text');
63  $res = $this->db->query('SELECT DISTINCT(participants) FROM osc_conversation WHERE ' . $in);
64  while ($row = $this->db->fetchAssoc($res)) {
65  $participants = json_decode($row['participants'], true);
66 
67  if (is_array($participants)) {
68  $usrIds = array_unique(array_merge($usrIds, array_map(function ($user) {
69  return $user['id'];
70  }, $participants)));
71  }
72  }
73 
74  return $this->getDataByUserIds($usrIds);
75  }
76 
82  public function getDataByUserIds(array $usrIds)
83  {
84  $usrIds = array_filter(array_map('intval', array_map('trim', $usrIds)));
85 
88 
89  $publicData = \ilUserUtil::getNamePresentation($usrIds, true, false, '', false, true, false, true);
90 
91  $data = [];
92 
93  foreach ($usrIds as $usr_id) {
94  $publicImage = isset($publicData[$usr_id]) && isset($publicData[$usr_id]['img']) ? $publicData[$usr_id]['img'] : '';
95 
96  $publicName = '';
97  if (isset($publicData[$usr_id])) {
98  $login = '';
99  if (isset($publicData[$usr_id]['login'])) {
100  $publicName = $login = $publicData[$usr_id]['login'];
101  }
102 
103  if (isset($publicData[$usr_id]['public_profile']) && $publicData[$usr_id]['public_profile']) {
104  $publicName = implode(', ', [
105  $publicData[$usr_id]['lastname'],
106  $publicData[$usr_id]['firstname'],
107  ]);
108 
109  if ($publicName !== '') {
110  $publicName .= ' [' . $login . ']';
111  } else {
112  $publicName = $login;
113  }
114  }
115  }
116 
117  $data[$usr_id] = array(
118  'public_name' => $publicName,
119  'profile_image' => $publicImage
120  );
121  }
122 
124 
125  return $data;
126  }
127 }
user()
Definition: user.php:4
Interface ilDBInterface.
foreach($_POST as $key=> $value) $res
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
Create styles array
The data for the language used.
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
__construct(\ilDBInterface $db, \ilObjUser $user)
ilOnScreenChatUserDataProvider constructor.
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static getTokenMaxLifetimeInSeconds()
Class ilOnScreenChatUserDataProvider.