ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Subscriber.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
11{
13 protected $db;
15 protected $user;
16
23 {
24 $this->db = $db;
25 $this->user = $user;
26 }
27
32 public function getInitialUserProfileData() : array
33 {
34 $conversationIds = [];
35
36 $res = $this->db->queryF(
37 'SELECT DISTINCT(conversation_id) FROM osc_activity WHERE user_id = %s',
38 ['integer'],
39 [$this->user->getId()]
40 );
41 while ($row = $this->db->fetchAssoc($res)) {
42 $conversationIds[$row['conversation_id']] = $row['conversation_id'];
43 }
44
45 $res = $this->db->queryF(
46 'SELECT DISTINCT(conversation_id) FROM osc_messages WHERE user_id = %s',
47 ['integer'],
48 [$this->user->getId()]
49 );
50 while ($row = $this->db->fetchAssoc($res)) {
51 $conversationIds[$row['conversation_id']] = $row['conversation_id'];
52 }
53
54 if (0 === count($conversationIds)) {
55 return [];
56 }
57
58 $usrIds = [];
59
60 $in = $this->db->in('id', $conversationIds, false, 'text');
61 $res = $this->db->query('SELECT DISTINCT(participants) FROM osc_conversation WHERE ' . $in);
62 while ($row = $this->db->fetchAssoc($res)) {
63 $participants = json_decode($row['participants'], true);
64
65 if (is_array($participants)) {
66 $usrIds = array_unique(array_merge($usrIds, array_map(function ($user) {
67 return $user['id'];
68 }, $participants)));
69 }
70 }
71
72 return $this->getDataByUserIds($usrIds);
73 }
74
80 public function getDataByUserIds(array $usrIds) : array
81 {
82 $usrIds = array_filter(array_map('intval', array_map('trim', $usrIds)));
83
86
87 $publicData = \ilUserUtil::getNamePresentation($usrIds, true, false, '', false, true, false, true);
88
89 $data = [];
90
91 foreach ($usrIds as $usr_id) {
92 $publicImage = isset($publicData[$usr_id]) && isset($publicData[$usr_id]['img']) ? $publicData[$usr_id]['img'] : '';
93
94 $publicName = '';
95 if (isset($publicData[$usr_id])) {
96 $login = '';
97 if (isset($publicData[$usr_id]['login'])) {
98 $publicName = $login = (string) $publicData[$usr_id]['login'];
99 }
100
101 if (isset($publicData[$usr_id]['public_profile']) && $publicData[$usr_id]['public_profile']) {
102 $publicName = implode(' ', array_filter(array_map('trim', [
103 (string) $publicData[$usr_id]['firstname'],
104 (string) $publicData[$usr_id]['lastname'],
105 ])));
106
107 if ($publicName === '') {
108 $publicName = $login;
109 }
110 }
111 }
112
113 $data[$usr_id] = array(
114 'public_name' => $publicName,
115 'profile_image' => $publicImage
116 );
117 }
118
120
121 return $data;
122 }
123}
user()
Definition: user.php:4
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
An exception for terminatinating execution or to throw for unit testing.
__construct(\ilDBInterface $db, \ilObjUser $user)
Subscriber constructor.
Definition: Subscriber.php:22
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:
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static getTokenMaxLifetimeInSeconds()
$login
Definition: cron.php:13
Interface ilDBInterface.
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23