ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilObjUser.php
Go to the documentation of this file.
1<?php
2
22use ILIAS\User\Profile\DataRepository as ProfileDataRepository;
23use ILIAS\User\Profile\Fields\ConfigurationRepository as ProfileConfigurationRepository;
29use ILIAS\User\Settings\DataRepository as SettingsDataRepository;
35use ILIAS\Data\Factory as DataFactory;
37use ILIAS\Export\ExportHandler\Factory as ExportFactory;
40
47class ilObjUser extends ilObject
48{
49 public const PASSWD_PLAIN = 'plain';
50 public const PASSWD_CRYPTED = 'crypted';
51
52 public const DATABASE_DATE_FORMAT = 'Y-m-d H:i:s';
53
54 private string $ext_account = '';
55 private string $fullname;
56 private bool $time_limit_unlimited = false;
57 private ?int $time_limit_until = null;
58 private ?int $time_limit_from = null;
59 private int $time_limit_owner = 7;
60 private string $last_login = '';
61 private string $passwd = '';
62 private string $passwd_type = '';
63 private ?string $password_encoding_type = null;
64 private ?string $password_salt = null;
65 private ?string $approve_date = null;
66 private ?string $agree_date = null;
67 private int $active = 0;
68 private string $client_ip = ''; // client ip to check before login
69 private ?string $auth_mode = null; // authentication mode
70 private int $last_password_change_ts = 0;
71 private bool $passwd_policy_reset = false;
72 private int $login_attempts = 0;
74 private array $user_settings = [];
75 private static array $personal_image_cache = [];
76 private ?string $inactivation_date = null;
77 private bool $is_self_registered = false; // flag for self registered users
78 private string $last_profile_prompt = ''; // timestamp
79 private string $first_login = ''; // timestamp
80 private bool $profile_incomplete = false;
81 private array $last_visited = [];
82
84 private ProfileDataRepository $profile_data_repository;
85 private ProfileConfigurationRepository $profile_configuration_repository;
86 private SettingsDataRepository $settings_data_repository;
87
89 private DataFactory $data_factory;
91 private Services $irss;
94 private ilCtrl $ctrl;
95
96 public function __construct(
97 int $a_user_id = 0,
98 bool $a_call_by_reference = false
99 ) {
100 global $DIC;
101 $this->irss = $DIC['resource_storage'];
102 $this->ilias_settings = $DIC['ilSetting'];
103 $this->auth_session = $DIC['ilAuthSession'];
104 $this->ctrl = $DIC['ilCtrl'];
105 $this->app_event_handler = $DIC['ilAppEventHandler'];
106 $this->delivery = $DIC['file_delivery']->delivery();
107
108 if (defined('USER_FOLDER_ID')) {
109 $this->time_limit_owner = USER_FOLDER_ID;
110 }
111
112 $local_dic = LocalDIC::dic();
113 $this->profile_data_repository = $local_dic[ProfileDataRepository::class];
114 $this->profile_data = $this->profile_data_repository->getDefault();
115 $this->profile_configuration_repository = $local_dic[ProfileConfigurationRepository::class];
116 $this->settings_data_repository = $local_dic[SettingsDataRepository::class];
117
118 $this->data_factory = (new DataFactory());
119
120 $this->type = 'usr';
121 parent::__construct($a_user_id, $a_call_by_reference);
122
123 $this->cron_delete_user_reminder_mail = new ilCronDeleteInactiveUserReminderMail($this->db);
124
125 $this->auth_mode = 'default';
126 $this->passwd_type = self::PASSWD_PLAIN;
127 if ($a_user_id > 0) {
128 $this->setId($a_user_id);
129 $this->read();
130 return;
131 }
132
133 $this->user_settings = [];
134 $this->user_settings['language'] = $this->ilias->ini->readVariable('language', 'default');
135 $this->user_settings['skin'] = $this->ilias->ini->readVariable('layout', 'skin');
136 $this->user_settings['style'] = $this->ilias->ini->readVariable('layout', 'style');
137 }
138
144 public function read(): void
145 {
146 $this->profile_data = $this->profile_data_repository->getSingle($this->id);
147 $this->setFullname();
148 $this->assignSystemInformationFromDB($this->profile_data->getSystemInformation());
149
150 $this->readSettings();
151
152 parent::read();
153 }
154
155 public function saveAsNew(): void
156 {
157 $this->inactivation_date = null;
158 if ($this->active === 0) {
159 $this->inactivation_date = date('Y-m-d H:i:s');
160 }
161
162 $system_information = $this->buildSystemInformationArrayForDB();
163 $system_information['create_date'] = $this->data_factory->clock()->utc()->now()
164 ->format(self::DATABASE_DATE_FORMAT);
165
166 $this->profile_data = $this->profile_data->withId($this->id);
167 $this->profile_data_repository->store(
168 $this->profile_data->withSystemInformation($this->buildSystemInformationArrayForDB())
169 );
170
171 // CREATE ENTRIES FOR MAIL BOX
172 $mbox = new ilMailbox($this->id);
173 $mbox->createDefaultFolder();
174
175 $mail_options = new ilMailOptions($this->id);
176 $mail_options->createMailOptionsEntry();
177
178 $this->app_event_handler->raise(
179 'components/ILIAS/User',
180 'afterCreate',
181 ['user_obj' => $this]
182 );
183 }
184
185 public function update(): bool
186 {
187 $this->profile_data_repository->store(
188 $this->profile_data->withSystemInformation($this->buildSystemInformationArrayForDB())
189 );
190
191 $this->writePrefs();
192
193 parent::update();
194 $this->updateOwner();
195
196 $this->read();
197
198 $this->app_event_handler->raise(
199 'components/ILIAS/User',
200 'afterUpdate',
201 ['user_obj' => $this]
202 );
203
204 return true;
205 }
206
207 private function assignSystemInformationFromDB(array $data): void
208 {
209 if (!empty($data['passwd'])) {
210 $this->setPasswd($data['passwd'], self::PASSWD_CRYPTED);
211 }
212
213 $this->password_salt = $data['passwd_salt'];
214 $this->password_encoding_type = $data['passwd_enc_type'];
215 $this->last_password_change_ts = $data['last_password_change'];
216 $this->login_attempts = $data['login_attempts'];
217 $this->passwd_policy_reset = $data['passwd_policy_reset'];
218 $this->client_ip = $data['client_ip'];
219 $this->last_login = $data['last_login'];
220 $this->first_login = $data['first_login'];
221 $this->last_profile_prompt = $data['last_profile_prompt'];
222 $this->last_update = $data['last_update'];
223 $this->create_date = $data['create_date'];
224 $this->approve_date = $data['approve_date'];
225 $this->active = $data['active'];
226 $this->agree_date = $data['agree_date'];
227 $this->inactivation_date = $data['inactivation_date'];
228
229 $this->time_limit_owner = $data['time_limit_owner'];
230 $this->time_limit_unlimited = $data['time_limit_unlimited'];
231 $this->time_limit_from = $data['time_limit_from'];
232 $this->time_limit_until = $data['time_limit_until'];
233
234 $this->profile_incomplete = $data['profile_incomplete'];
235
236 $this->auth_mode = $data['auth_mode'];
237 $this->ext_account = $data['ext_account'] ?? '';
238 $this->is_self_registered = $data['is_self_registered'];
239 $this->last_visited = $data['last_visited'];
240 }
241
242 private function buildSystemInformationArrayForDB(): array
243 {
244 return [
245 'last_password_change' => $this->last_password_change_ts,
246 'login_attempts' => $this->login_attempts,
247 'passwd' => $this->prepareAndRetrievePasswordForStorage(),
248 'passwd_salt' => $this->password_salt,
249 'passwd_enc_type' => $this->password_encoding_type,
250 'passwd_policy_reset' => $this->passwd_policy_reset,
251 'client_ip' => $this->client_ip,
252 'last_login' => $this->last_login,
253 'first_login' => $this->first_login,
254 'last_profile_prompt' => $this->last_profile_prompt,
255 'active' => $this->active,
256 'approve_date' => $this->approve_date,
257 'agree_date' => $this->retrieveAgreeDateForStorage(),
258 'inactivation_date' => $this->inactivation_date,
259 'time_limit_owner' => $this->time_limit_owner,
260 'time_limit_unlimited' => $this->time_limit_unlimited,
261 'time_limit_from' => $this->time_limit_from,
262 'time_limit_until' => $this->time_limit_until,
263 'profile_incomplete' => $this->profile_incomplete,
264 'auth_mode' => $this->auth_mode,
265 'ext_account' => $this->ext_account ?? '',
266 'is_self_registered' => $this->is_self_registered,
267 'last_update' => $this->last_update,
268 'create_date' => $this->create_date,
269 'last_visited' => $this->last_visited
270 ];
271 }
272
273 private function prepareAndRetrievePasswordForStorage(): string
274 {
275 if ($this->passwd_type === self::PASSWD_PLAIN
276 && $this->passwd !== '') {
277 LocalUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
278 }
279
280 return $this->passwd;
281 }
282
283 private function retrieveAgreeDateForStorage(): ?string
284 {
285 if (is_string($this->agree_date && strtotime($this->agree_date) === false)) {
286 return null;
287 }
288 return $this->agree_date;
289 }
290
291 public function resetPassword(string $new_raw_password): bool
292 {
293 LocalUserPasswordManager::getInstance()->encodePassword($this, $new_raw_password);
294 $this->profile_data_repository->storePasswordFor(
295 $this->id,
296 $this->passwd,
297 $this->password_encoding_type,
298 $this->password_salt
299 );
300 return true;
301 }
302
303 public function getLastHistoryData(): ?array
304 {
305 $this->db->setLimit(1, 0);
306 $res = $this->db->queryF(
307 '
308 SELECT login, history_date FROM loginname_history
309 WHERE usr_id = %s ORDER BY history_date DESC',
310 ['integer'],
311 [$this->id]
312 );
313 $row = $this->db->fetchAssoc($res);
314 if ($row === null) {
315 return null;
316 }
317
318 return [
319 $row['login'],
320 $row['history_date']
321 ];
322 }
323
324 public function updateLogin(string $login, Context $context): bool
325 {
326 if ($login === '' || $login === $this->profile_data->getAlias()) {
327 return false;
328 }
329
330 $last_history_entry = $this->getLastHistoryData();
331
332 if (!$context->isFieldChangeable(
333 $this->profile_configuration_repository->getByClass(Alias::class),
334 $this
335 )) {
336 throw new ilUserException($this->lng->txt('permission_denied'));
337 }
338
339 // throw exception if the desired loginame is already in history and it is not allowed to reuse it
340 if ($this->ilias_settings->get('reuse_of_loginnames') === '0'
341 && self::_doesLoginnameExistInHistory($login)) {
342 throw new ilUserException($this->lng->txt('loginname_already_exists'));
343 }
344
345 if ((int) $this->ilias_settings->get('loginname_change_blocking_time') > 0
346 && is_array($last_history_entry)
347 && $last_history_entry[1] + (int) $this->ilias_settings->get('loginname_change_blocking_time') > time()) {
348 throw new ilUserException(
349 sprintf(
350 $this->lng->txt('changing_loginname_not_possible_info'),
352 new ilDateTime($last_history_entry[1], IL_CAL_UNIX)
353 ),
355 new ilDateTime(($last_history_entry[1] + (int) $this->ilias_settings->get('loginname_change_blocking_time')), IL_CAL_UNIX)
356 )
357 )
358 );
359 }
360
361 if ($this->ilias_settings->get('create_history_loginname') === '1') {
362 $this->writeHistory($this->profile_data->getAlias());
363 }
364
365 $this->profile_data = $this->profile_data->withAlias($login);
366 $this->profile_data_repository->storeLoginFor($this->id, $this->profile_data->getAlias());
367
368 return true;
369 }
370
371 private function writeHistory(string $login): void
372 {
373 $res = $this->db->queryF(
374 'SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
375 ['integer', 'text', 'integer'],
376 [$this->id, $login, time()]
377 );
378
379 if ($this->db->numRows($res) == 0) {
380 $this->db->manipulateF(
381 '
382 INSERT INTO loginname_history
383 (usr_id, login, history_date)
384 VALUES (%s, %s, %s)',
385 ['integer', 'text', 'integer'],
386 [$this->id, $login, time()]
387 );
388 }
389 }
390
391 public function writePref(
392 string $key,
393 string $value
394 ): void {
395 $this->settings_data_repository->storeSingleFor($this->id, $key, $value);
396 $this->setPref($key, $value);
397 }
398
399 public function deletePref(string $key): void
400 {
401 $this->settings_data_repository->deleteSingleFor($this->id, $key);
402 unset($this->user_settings[$key]);
403 }
404
405 public function writePrefs(): void
406 {
407 $this->settings_data_repository->deleteFor($this->id);
408 $this->settings_data_repository->storeFor($this->id, $this->user_settings);
409 }
410
411 public function getTimeZone(): string
412 {
413 $tz = $this->getPref('user_tz');
414 if ($tz !== null) {
415 return $tz;
416 }
417 return ilCalendarSettings::_getInstance()->getDefaultTimeZone();
418 }
419
420 public function getTimeFormat(): string
421 {
422 $format = $this->getPref('time_format');
423 if ($format !== null) {
424 return $format;
425 }
426 return ilCalendarSettings::_getInstance()->getDefaultTimeFormat();
427 }
428
429 public function getDateFormat(): DateFormat
430 {
431 $format = $this->getPref('date_format');
432 if ($format === null) {
433 $format = ilCalendarSettings::_getInstance()->getDefaultDateFormat();
434 }
435
436 return match ((int) $format) {
437 ilCalendarSettings::DATE_FORMAT_DMY => $this->data_factory->dateFormat()->germanShort(),
438 ilCalendarSettings::DATE_FORMAT_MDY => $this->data_factory->dateFormat()->americanShort(),
439 ilCalendarSettings::DATE_FORMAT_YMD => $this->data_factory->dateFormat()->standard(),
440 default => $this->data_factory->dateFormat()->standard()
441 };
442 }
443
444 public function getDateTimeFormat(): DateFormat
445 {
446 if ($this->getTimeFormat() === (string) \ilCalendarSettings::TIME_FORMAT_24) {
447 return $this->data_factory->dateFormat()->withTime24($this->getDateFormat());
448 }
449 return $this->data_factory->dateFormat()->withTime12($this->getDateFormat());
450 }
451
452 public function setPref(string $a_keyword, ?string $a_value): void
453 {
454 if ($a_keyword !== '') {
455 $this->user_settings[$a_keyword] = $a_value;
456 }
457 }
458
459 public function getPref(string $keyword): ?string
460 {
461 return $this->user_settings[$keyword] ?? null;
462 }
463
467 public function getPrefs(): array
468 {
469 return $this->user_settings;
470 }
471
472 private function readSettings(): void
473 {
474 $this->user_settings = $this->settings_data_repository->getFor($this->id);
475 if (!isset($this->user_settings['style'])
476 || $this->user_settings['style'] === ''
477 || !ilStyleDefinition::styleExists($this->user_settings['style'])
478 || !ilStyleDefinition::skinExists($this->user_settings['skin'])
479 && ilStyleDefinition::styleExistsForSkinId($this->user_settings['skin'], $this->user_settings['style'])) {
480 $this->user_settings['skin'] = $this->ilias->ini->readVariable('layout', 'skin');
481 $this->user_settings['style'] = $this->ilias->ini->readVariable('layout', 'style');
482 }
483 }
484
485 public function delete(): bool
486 {
487 $this->app_event_handler->raise(
488 'Services/User',
489 'deleteUser',
490 ['usr_id' => $this->getId()]
491 );
492
494 ilLDAPRoleGroupMapping::_getInstance()->deleteUser($this->getId());
495
502 global $DIC;
503 $DIC['rbacadmin']->removeUser($this->getId());
504 (ilOrgUnitUserAssignmentQueries::getInstance())->deleteAllAssignmentsOfUser($this->getId());
505
506 $mailbox = new ilMailbox($this->getId());
507 $mailbox->delete();
508 $mailbox->updateMailsOfDeletedUser($this->getLogin());
509
518 (new ilWorkspaceTree($this->id))->cascadingDelete();
519 $this->cron_delete_user_reminder_mail->removeSingleUserFromTable($this->getId());
521 $this->clipboardDeleteAll();
522
523 $this->settings_data_repository->deleteFor($this->id);
524 $this->removeUserPicture();
525 $this->profile_data_repository->deleteForUser($this->getId());
526
527 $this->resetOwner();
528 parent::delete();
529
530 return true;
531 }
532
533 public function withProfileData(Data $profile_data): self
534 {
535 $clone = clone $this;
536 $clone->profile_data = $profile_data;
537 return $clone;
538 }
539
540 public function getProfileData(): Data
541 {
542 return $this->profile_data;
543 }
544
545 public function setLogin(string $login): void
546 {
547 $this->profile_data = $this->profile_data->withAlias($login);
548 }
549
550 public function getLogin(): string
551 {
552 return $this->profile_data->getAlias();
553 }
554
555 public function setGender(string $gender_string): void
556 {
557 $this->profile_data = $this->profile_data->withGender(Genders::tryFrom($gender_string));
558 }
559
560 public function getGender(): string
561 {
562 return $this->profile_data->getGender()?->value ?? '';
563 }
564
568 public function setUTitle(string $user_title): void
569 {
570 $this->setFullname();
571 $this->profile_data = $this->profile_data->withTitle($user_title);
572 }
573
574 public function getUTitle(): string
575 {
576 return $this->profile_data->getTitle();
577 }
578
579 public function setFirstname(string $firstname): void
580 {
581 $this->profile_data = $this->profile_data->withFirstname($firstname);
582 $this->setFullname();
583 }
584
585 public function getFirstname(): string
586 {
587 return $this->profile_data->getFirstname();
588 }
589
590 public function setLastname(string $lastname): void
591 {
592 $this->profile_data = $this->profile_data->withLastname($lastname);
593 $this->setFullname();
594 }
595
596 public function getLastname(): string
597 {
598 return $this->profile_data->getLastname();
599 }
600
601 public function setBirthday(?string $birthday): void
602 {
603 if ($birthday === null || $birthday === '') {
604 $this->profile_data = $this->profile_data->withBirthday(null);
605 return;
606 }
607
608 $this->profile_data = $this->profile_data->withBirthday(
609 new \DateTimeImmutable($birthday, new DateTimeZone('UTC'))
610 );
611 }
612
613 public function getBirthday(): ?string
614 {
615 return $this->profile_data->getBirthday()?->format('Y-m-d');
616 }
617
618 public function setInstitution(string $instituion): void
619 {
620 $this->profile_data = $this->profile_data->withInstitution($instituion);
621 }
622
623 public function getInstitution(): string
624 {
625 return $this->profile_data->getInstitution();
626 }
627
628 public function setDepartment(string $department): void
629 {
630 $this->profile_data = $this->profile_data->withDepartment($department);
631 }
632
633 public function getDepartment(): string
634 {
635 return $this->profile_data->getDepartment();
636 }
637
638 public function setStreet(string $street): void
639 {
640 $this->profile_data = $this->profile_data->withStreet($street);
641 }
642
643 public function getStreet(): string
644 {
645 return $this->profile_data->getStreet();
646 }
647
648 public function setCity(string $city): void
649 {
650 $this->profile_data = $this->profile_data->withCity($city);
651 }
652
653 public function getCity(): string
654 {
655 return $this->profile_data->getCity();
656 }
657
658 public function setZipcode(string $zipcode): void
659 {
660 $this->profile_data = $this->profile_data->withZipcode($zipcode);
661 }
662
663 public function getZipcode(): string
664 {
665 return $this->profile_data->getZipcode();
666 }
667
668 public function setCountry(string $country): void
669 {
670 $this->profile_data = $this->profile_data->withCountry($country);
671 }
672
673 public function getCountry(): string
674 {
675 return $this->profile_data->getCountry();
676 }
677
678 public function setPhoneOffice(string $phone): void
679 {
680 $this->profile_data = $this->profile_data->withPhoneOffice($phone);
681 }
682
683 public function getPhoneOffice(): string
684 {
685 return $this->profile_data->getPhoneOffice();
686 }
687
688 public function setPhoneHome(string $phone): void
689 {
690 $this->profile_data = $this->profile_data->withPhoneHome($phone);
691 }
692
693 public function getPhoneHome(): string
694 {
695 return $this->profile_data->getPhoneHome();
696 }
697
698 public function setPhoneMobile(string $phone): void
699 {
700 $this->profile_data = $this->profile_data->withPhoneMobile($phone);
701 }
702
703 public function getPhoneMobile(): string
704 {
705 return $this->profile_data->getPhoneMobile();
706 }
707
708 public function setFax(string $fax): void
709 {
710 $this->profile_data = $this->profile_data->withFax($fax);
711 }
712
713 public function getFax(): string
714 {
715 return $this->profile_data->getFax();
716 }
717
718 public function setMatriculation(string $matriculation): void
719 {
720 $this->profile_data = $this->profile_data->withMatriculation($matriculation);
721 }
722
723 public function getMatriculation(): string
724 {
725 return $this->profile_data->getMatriculation();
726 }
727
728 public function setEmail(string $email): void
729 {
730 $this->profile_data = $this->profile_data->withEmail($email);
731 }
732
733 public function getEmail(): string
734 {
735 return $this->profile_data->getEmail();
736 }
737
738 public function setSecondEmail(?string $email): void
739 {
740 $this->profile_data = $this->profile_data->withSecondEmail($email);
741 }
742
743 public function getSecondEmail(): ?string
744 {
745 return $this->profile_data->getSecondEmail();
746 }
747
748 public function setHobby(string $hobby): void
749 {
750 $this->profile_data = $this->profile_data->withHobby($hobby);
751 }
752
753 public function getHobby(): string
754 {
755 return $this->profile_data->getHobby();
756 }
757
758 public function setComment(string $referral_comment): void
759 {
760 $this->profile_data = $this->profile_data->withReferralComment($referral_comment);
761 }
762
763 public function getComment(): string
764 {
765 return $this->profile_data->getReferralComment();
766 }
767
768 public function setLatitude(?string $latitude): void
769 {
770 $coordinates = $this->profile_data->getGeoCoordinates();
771 $coordinates['latitude'] = $latitude;
772 $this->profile_data = $this->profile_data->withGeoCoordinates($coordinates);
773 }
774
775 public function getLatitude(): ?string
776 {
777 return $this->profile_data->getGeoCoordinates()['latitude'] ?? null;
778 }
779
780 public function setLongitude(?string $longitude): void
781 {
782 $coordinates = $this->profile_data->getGeoCoordinates();
783 $coordinates['longitude'] = $longitude;
784 $this->profile_data = $this->profile_data->withGeoCoordinates($coordinates);
785 }
786
787 public function getLongitude(): ?string
788 {
789 return $this->profile_data->getGeoCoordinates()['longitude'] ?? null;
790 }
791
792 public function setLocationZoom(?int $zoom): void
793 {
794 $coordinates = $this->profile_data->getGeoCoordinates();
795 $coordinates['zoom'] = $zoom;
796 $this->profile_data = $this->profile_data->withGeoCoordinates($coordinates);
797 }
798
799 public function getLocationZoom(): ?int
800 {
801 return $this->profile_data->getGeoCoordinates()['zoom'] ?? null;
802 }
803
805 {
806 return $this->profile_data->getAvatarRid();
807 }
808
809 public function setAvatarRid(?ResourceIdentification $avatar_rid): void
810 {
811 $this->profile_data = $this->profile_data->withAvatarRid($avatar_rid);
812 }
813
814 public function setClientIP(string $a_str): void
815 {
816 $this->client_ip = $a_str;
817 }
818
819 public function getClientIP(): string
820 {
821 return $this->client_ip;
822 }
823
824 public function setLanguage(string $language): void
825 {
826 $this->setPref('language', $language);
827 ilSession::clear('lang');
828 }
829
830 public function getLanguage(): string
831 {
832 return $this->user_settings['language'] ?? '';
833 }
834
835 public function getPasswordEncodingType(): ?string
836 {
837 return $this->password_encoding_type;
838 }
839
840 public function setPasswordEncodingType(?string $password_encryption_type): void
841 {
842 $this->password_encoding_type = $password_encryption_type;
843 }
844
845 public function getPasswordSalt(): ?string
846 {
847 return $this->password_salt;
848 }
849
850 public function setPasswordSalt(?string $password_salt): void
851 {
852 $this->password_salt = $password_salt;
853 }
854
855 public function setFullname(): void
856 {
857 $title = $this->profile_data->getTitle() !== '' ? "{$this->profile_data->getTitle()} " : '';
858 $this->fullname = "{$title}{$this->profile_data->getFirstname()} {$this->profile_data->getLastname()}";
859 }
860
873 public function getFullname(int $max_strlen = 0): string
874 {
875 if ($max_strlen === 0) {
876 return ilUtil::stripSlashes($this->fullname);
877 }
878
879 if (mb_strlen($this->fullname) <= $max_strlen) {
880 return ilUtil::stripSlashes($this->fullname);
881 }
882
883 $length_lastname = mb_strlen($this->lastname);
884 if (mb_strlen($this->utitle) + $length_lastname + 4 <= $max_strlen) {
885 return ilUtil::stripSlashes($this->utitle . ' ' . substr($this->firstname, 0, 1) . '. ' . $this->lastname);
886 }
887
888 if (mb_strlen($this->firstname) + $length_lastname + 1 <= $max_strlen) {
889 return ilUtil::stripSlashes($this->firstname . ' ' . $this->lastname);
890 }
891
892 if ($length_lastname + 3 <= $max_strlen) {
893 return ilUtil::stripSlashes(substr($this->firstname, 0, 1) . '. ' . $this->lastname);
894 }
895
896 return ilUtil::stripSlashes(substr($this->lastname, 0, $max_strlen));
897 }
898
899 public function setPasswd(
900 string $a_str,
901 string $a_type = ilObjUser::PASSWD_PLAIN
902 ): void {
903 $this->passwd = $a_str;
904 $this->passwd_type = $a_type;
905 }
906
910 public function getPasswd(): string
911 {
912 return $this->passwd;
913 }
914
918 public function getPasswdType(): string
919 {
920 return $this->passwd_type;
921 }
922
923 public function setLastPasswordChangeTS(int $a_last_password_change_ts): void
924 {
925 $this->last_password_change_ts = $a_last_password_change_ts;
926 }
927
928 public function getLastPasswordChangeTS(): int
929 {
930 return $this->last_password_change_ts;
931 }
932
933 public function getPasswordPolicyResetStatus(): bool
934 {
935 return $this->passwd_policy_reset;
936 }
937
938 public function setPasswordPolicyResetStatus(bool $status): void
939 {
940 $this->passwd_policy_reset = $status;
941 }
942
946 public function getCurrentLanguage(): string
947 {
948 return ilSession::get('lang') ?? '';
949 }
950
954 public function setCurrentLanguage(string $language): void
955 {
956 ilSession::set('lang', $language);
957 }
958
959 public function setLastLogin(string $a_str): void
960 {
961 $this->last_login = $a_str;
962 }
963
964 public function getLastLogin(): string
965 {
966 return $this->last_login;
967 }
968
969 public function refreshLogin(): void
970 {
971 $this->last_login = $this->db->now();
972
973 $old_first_login = $this->first_login;
974 if ($old_first_login === '') {
975 $this->first_login = $this->db->now();
976 $this->app_event_handler->raise(
977 'components/ILIAS/User',
978 'firstLogin',
979 ['user_obj' => $this]
980 );
981 }
982 }
983
984 public function setFirstLogin(string $date): void
985 {
986 $this->first_login = $date;
987 }
988
989 public function getFirstLogin(): string
990 {
991 return $this->first_login;
992 }
993
994 public function setLastProfilePrompt(string $date): void
995 {
996 $this->last_profile_prompt = $date;
997 }
998
999 public function getLastProfilePrompt(): string
1000 {
1001 return $this->last_profile_prompt;
1002 }
1003
1004 public function setLastUpdate(string $date): void
1005 {
1006 $this->last_update = $date;
1007 }
1008
1009 public function getLastUpdate(): string
1010 {
1011 return $this->last_update;
1012 }
1013
1014 public function getLastVisited(): array
1015 {
1016 return $this->last_visited;
1017 }
1018
1019 public function updateLastVisited(array $last_visited): void
1020 {
1021 $this->last_visited = $last_visited;
1022 $this->profile_data_repository->storeLastVisitedFor($this->id, $last_visited);
1023 }
1024
1029 public function setApproveDate(?string $a_str): void
1030 {
1031 $this->approve_date = $a_str;
1032 }
1033
1034 public function getApproveDate(): ?string
1035 {
1036 return $this->approve_date;
1037 }
1038
1039 public function getAgreeDate(): ?string
1040 {
1041 return $this->agree_date;
1042 }
1043 public function setAgreeDate(?string $date): void
1044 {
1045 $this->agree_date = $date;
1046 }
1047
1052 public function setActive(
1053 bool $active,
1054 int $owner = 0
1055 ): void {
1056 $this->setOwner($owner);
1057
1058 $current_active = $this->active;
1059 if ($active) {
1060 $this->active = 1;
1061 $this->setApproveDate(date('Y-m-d H:i:s'));
1062 $this->setInactivationDate(null);
1063 $this->setOwner($owner);
1064 return;
1065 }
1066
1067 $this->active = 0;
1068 $this->setApproveDate(null);
1069
1070 if ($this->getId() > 0 && $current_active !== $active) {
1071 $this->setInactivationDate(ilUtil::now());
1072 }
1073 }
1074
1075 public function getActive(): bool
1076 {
1077 return $this->active === 1;
1078 }
1079
1080 public function getSkin(): string
1081 {
1082 return $this->user_settings['skin'];
1083 }
1084
1085 public function setTimeLimitOwner(int $a_owner): void
1086 {
1087 $this->time_limit_owner = $a_owner;
1088 }
1089
1090 public function getTimeLimitOwner(): int
1091 {
1092 return $this->time_limit_owner;
1093 }
1094
1095 public function setTimeLimitFrom(?int $a_from): void
1096 {
1097 $this->time_limit_from = $a_from;
1098 }
1099
1100 public function getTimeLimitFrom(): ?int
1101 {
1102 return $this->time_limit_from;
1103 }
1104
1105 public function setTimeLimitUntil(?int $a_until): void
1106 {
1107 $this->time_limit_until = $a_until;
1108 }
1109
1110 public function getTimeLimitUntil(): ?int
1111 {
1112 return $this->time_limit_until;
1113 }
1114
1115 public function setTimeLimitUnlimited(bool $unlimited): void
1116 {
1117 $this->time_limit_unlimited = $unlimited;
1118 }
1119
1120 public function getTimeLimitUnlimited(): bool
1121 {
1122 return $this->time_limit_unlimited;
1123 }
1124
1125 public function setLoginAttempts(int $a_login_attempts): void
1126 {
1127 $this->login_attempts = $a_login_attempts;
1128 }
1129
1130 public function getLoginAttempts(): int
1131 {
1132 return $this->login_attempts;
1133 }
1134
1135 public function checkTimeLimit(): bool
1136 {
1137 if ($this->getTimeLimitUnlimited()) {
1138 return true;
1139 }
1140 if ($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time()) {
1141 return true;
1142 }
1143 return false;
1144 }
1145
1146 public function setProfileIncomplete(bool $a_prof_inc): void
1147 {
1148 $this->profile_incomplete = $a_prof_inc;
1149 }
1150
1151 public function getProfileIncomplete(): bool
1152 {
1153 if ($this->id == ANONYMOUS_USER_ID) {
1154 return false;
1155 }
1156 return $this->profile_incomplete;
1157 }
1158
1159 public function isPasswordChangeDemanded(): bool
1160 {
1161 if ($this->id === ANONYMOUS_USER_ID) {
1162 return false;
1163 }
1164
1165 if ($this->id === SYSTEM_USER_ID) {
1166 if (LocalUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI='))
1167 && !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))
1168 ) {
1169 return true;
1170 }
1171 return false;
1172 }
1173
1174 return !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))
1175 && ($this->getPasswordPolicyResetStatus()
1176 || ilSecuritySettings::_getInstance()->isPasswordChangeOnFirstLoginEnabled()
1177 && $this->getLastPasswordChangeTS() === 0
1178 && $this->is_self_registered === false);
1179 }
1180
1181 public function isPasswordExpired(): bool
1182 {
1183 if ($this->id === ANONYMOUS_USER_ID
1184 || $this->getLastPasswordChangeTS() === 0) {
1185 return false;
1186 }
1187
1188 $max_pass_age_in_seconds = ilSecuritySettings::_getInstance()->getPasswordMaxAge() * 86400;
1189 if ($max_pass_age_in_seconds === 0) {
1190 return false;
1191 }
1192
1193 if (time() - $this->getLastPasswordChangeTS() > $max_pass_age_in_seconds
1194 && !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))) {
1195 return true;
1196 }
1197
1198 return false;
1199 }
1200
1201 public function getPasswordAgeInDays(): int
1202 {
1203 return (int) floor((time() - $this->getLastPasswordChangeTS()) / 86400);
1204 }
1205
1206 public function setLastPasswordChangeToNow(): void
1207 {
1208 $this->last_password_change_ts = time();
1209 }
1210
1211 public function resetLastPasswordChange(): void
1212 {
1213 $this->last_password_change_ts = 0;
1214 }
1215
1216 public function setAuthMode(?string $a_str): void
1217 {
1218 $this->auth_mode = $a_str;
1219 }
1220
1221 public function getAuthMode(bool $a_auth_key = false): ?string
1222 {
1223 if (!$a_auth_key) {
1224 return $this->auth_mode;
1225 }
1226 return ilAuthUtils::_getAuthMode($this->auth_mode);
1227 }
1228
1229 public function setExternalAccount(string $a_str): void
1230 {
1231 $this->ext_account = $a_str;
1232 }
1233
1234 public function getExternalAccount(): string
1235 {
1236 return $this->ext_account;
1237 }
1238
1245 public function addObjectToClipboard(
1246 int $a_item_id,
1247 string $a_type,
1248 string $a_title,
1249 int $a_parent = 0,
1250 string $a_time = '',
1251 int $a_order_nr = 0
1252 ): void {
1253 global $DIC;
1254
1255 $ilDB = $DIC['ilDB'];
1256
1257 if ($a_time === '') {
1258 $a_time = date('Y-m-d H:i:s');
1259 }
1260
1261 $item_set = $ilDB->queryF(
1262 'SELECT * FROM personal_clipboard WHERE ' .
1263 'parent = %s AND item_id = %s AND type = %s AND user_id = %s',
1264 ['integer', 'integer', 'text', 'integer'],
1265 [0, $a_item_id, $a_type, $this->getId()]
1266 );
1267
1268 // only insert if item is not already in clipboard
1269 if (!$item_set->fetchRow()) {
1270 $ilDB->manipulateF(
1271 'INSERT INTO personal_clipboard ' .
1272 '(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ' .
1273 ' (%s,%s,%s,%s,%s,%s,%s)',
1274 ['integer', 'text', 'integer', 'text', 'integer', 'timestamp', 'integer'],
1275 [$a_item_id, $a_type, $this->getId(), $a_title, $a_parent, $a_time, $a_order_nr]
1276 );
1277 } else {
1278 $ilDB->manipulateF(
1279 'UPDATE personal_clipboard SET insert_time = %s ' .
1280 'WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0',
1281 ['timestamp', 'integer', 'integer', 'text'],
1282 [$a_time, $this->getId(), $a_item_id, $a_type]
1283 );
1284 }
1285 }
1286
1291 public function addToPCClipboard(
1292 string $a_content,
1293 string $a_time,
1294 int $a_nr
1295 ): void {
1296 $ilDB = $this->db;
1297 if ($a_time == 0) {
1298 $a_time = date('Y-m-d H:i:s');
1299 }
1300 ilSession::set('user_pc_clip', true);
1301 $ilDB->insert('personal_pc_clipboard', [
1302 'user_id' => ['integer', $this->getId()],
1303 'content' => ['clob', $a_content],
1304 'insert_time' => ['timestamp', $a_time],
1305 'order_nr' => ['integer', $a_nr]
1306 ]);
1307 }
1308
1313 public function getPCClipboardContent(): array // Missing array type.
1314 {
1315 $ilDB = $this->db;
1316
1317 if (!ilSession::get('user_pc_clip')) {
1318 return [];
1319 }
1320
1321 $set = $ilDB->queryF('SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ' .
1322 ' WHERE user_id = %s', ['integer'], [$this->getId()]);
1323 $row = $ilDB->fetchAssoc($set);
1324
1325 $set = $ilDB->queryF(
1326 'SELECT * FROM personal_pc_clipboard ' .
1327 ' WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC',
1328 ['integer', 'timestamp'],
1329 [$this->getId(), $row['mtime']]
1330 );
1331 $content = [];
1332 while ($row = $ilDB->fetchAssoc($set)) {
1333 $content[] = $row['content'];
1334 }
1335
1336 return $content;
1337 }
1338
1342 public function clipboardHasObjectsOfType(string $a_type): bool
1343 {
1344 global $DIC;
1345
1346 $ilDB = $DIC['ilDB'];
1347
1348 $set = $ilDB->queryF(
1349 'SELECT * FROM personal_clipboard WHERE ' .
1350 'parent = %s AND type = %s AND user_id = %s',
1351 ['integer', 'text', 'integer'],
1352 [0, $a_type, $this->getId()]
1353 );
1354 if ($ilDB->fetchAssoc($set)) {
1355 return true;
1356 }
1357
1358 return false;
1359 }
1360
1361 public function clipboardDeleteObjectsOfType(string $a_type): void
1362 {
1363 $ilDB = $this->db;
1364
1365 $ilDB->manipulateF(
1366 'DELETE FROM personal_clipboard WHERE ' .
1367 'type = %s AND user_id = %s',
1368 ['text', 'integer'],
1369 [$a_type, $this->getId()]
1370 );
1371 }
1372
1373 public function clipboardDeleteAll(): void
1374 {
1375 global $DIC;
1376
1377 $ilDB = $DIC['ilDB'];
1378
1379 $ilDB->manipulateF('DELETE FROM personal_clipboard WHERE ' .
1380 'user_id = %s', ['integer'], [$this->getId()]);
1381 }
1382
1386 public function getClipboardObjects(
1387 string $a_type = '',
1388 bool $a_top_nodes_only = false
1389 ): array {
1390 global $DIC;
1391
1392 $ilDB = $DIC['ilDB'];
1393
1394 $par = '';
1395 if ($a_top_nodes_only) {
1396 $par = ' AND parent = ' . $ilDB->quote(0, 'integer') . ' ';
1397 }
1398
1399 $type_str = ($a_type != '')
1400 ? ' AND type = ' . $ilDB->quote($a_type, 'text') . ' '
1401 : '';
1402 $q = 'SELECT * FROM personal_clipboard WHERE ' .
1403 'user_id = ' . $ilDB->quote($this->getId(), 'integer') . ' ' .
1404 $type_str . $par .
1405 ' ORDER BY order_nr';
1406 $objs = $ilDB->query($q);
1407 $objects = [];
1408 while ($obj = $ilDB->fetchAssoc($objs)) {
1409 if ($obj['type'] == 'mob') {
1410 $obj['title'] = ilObject::_lookupTitle($obj['item_id']);
1411 if (ilObject::_lookupType((int) $obj['item_id']) !== 'mob') {
1412 continue;
1413 }
1414 }
1415 if ($obj['type'] == 'incl') {
1416 $obj['title'] = ilMediaPoolPage::lookupTitle($obj['item_id']);
1417 if (!ilPageObject::_exists('mep', (int) $obj['item_id'], '-')) {
1418 continue;
1419 }
1420 }
1421 $objects[] = ['id' => $obj['item_id'],
1422 'type' => $obj['type'], 'title' => $obj['title'],
1423 'insert_time' => $obj['insert_time']];
1424 }
1425 return $objects;
1426 }
1427
1431 public function getClipboardChilds(
1432 int $a_parent,
1433 string $a_insert_time
1434 ): array {
1435 global $DIC;
1436
1437 $ilDB = $DIC['ilDB'];
1438 $ilUser = $DIC['ilUser'];
1439
1440 $objs = $ilDB->queryF(
1441 'SELECT * FROM personal_clipboard WHERE ' .
1442 'user_id = %s AND parent = %s AND insert_time = %s ' .
1443 ' ORDER BY order_nr',
1444 ['integer', 'integer', 'timestamp'],
1445 [$ilUser->getId(), $a_parent, $a_insert_time]
1446 );
1447 $objects = [];
1448 while ($obj = $ilDB->fetchAssoc($objs)) {
1449 if ($obj['type'] == 'mob') {
1450 $obj['title'] = ilObject::_lookupTitle($obj['item_id']);
1451 }
1452 $objects[] = ['id' => $obj['item_id'],
1453 'type' => $obj['type'], 'title' => $obj['title'], 'insert_time' => $obj['insert_time']];
1454 }
1455 return $objects;
1456 }
1457
1459 int $a_item_id,
1460 string $a_type
1461 ): void {
1462 $ilDB = $this->db;
1463
1464 $q = 'DELETE FROM personal_clipboard WHERE ' .
1465 'item_id = ' . $ilDB->quote($a_item_id, 'integer') .
1466 ' AND type = ' . $ilDB->quote($a_type, 'text') . ' ' .
1467 ' AND user_id = ' . $ilDB->quote($this->getId(), 'integer');
1468 $ilDB->manipulate($q);
1469 }
1470
1471 public function getOrgUnitsRepresentation(): string
1472 {
1473 return self::lookupOrgUnitsRepresentation($this->getId());
1474 }
1475
1480 public function getPersonalPicturePath(
1481 string $a_size = 'small',
1482 bool $a_force_pic = false
1483 ): string {
1484 if (isset(self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic])) {
1485 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
1486 }
1487
1488 self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic] = self::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
1489
1490 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
1491 }
1492
1493 public function hasProfilePicture(): bool
1494 {
1495 return (new ilUserAvatarResolver($this->getId()))->hasProfilePicture();
1496 }
1497
1498 public function getAvatar(): Avatar
1499 {
1500 return self::_getAvatar($this->getId());
1501 }
1502
1503 public function removeUserPicture(): void
1504 {
1505 if ($this->getAvatarRid() !== null) {
1506 $this->irss->manage()->remove($this->getAvatarRid(), new ilUserProfilePictureStakeholder());
1507 }
1508
1509 $this->profile_data = $this->profile_data->withAvatarRid(null);
1510 $this->update();
1511 }
1512
1517 public function getProfileAsString(Language $language): string
1518 {
1519 global $DIC;
1520 $rbacreview = $DIC['rbacreview'];
1521 $profile = $DIC['user']->getProfile();
1522
1523 $language->loadLanguageModule('registration');
1524 $language->loadLanguageModule('crs');
1525
1526 $body = "{$language->txt('login')}: {$this->getLogin()}\n";
1527
1528 if ($this->profile_data->getTitle() !== '') {
1529 $body .= "{$language->txt('title')}: {$this->profile_data->getTitle()}\n";
1530 }
1531 if ($this->getGender() !== '') {
1532 $body .= ($language->txt('gender') . ': ' . $language->txt('gender_' . strtolower($this->getGender())) . "\n");
1533 }
1534 if ($this->getFirstname() !== '') {
1535 $body .= ($language->txt('firstname') . ': ' . $this->getFirstname() . "\n");
1536 }
1537 if ($this->getLastname() !== '') {
1538 $body .= ($language->txt('lastname') . ': ' . $this->getLastname() . "\n");
1539 }
1540 if ($this->getInstitution() !== '') {
1541 $body .= ($language->txt('institution') . ': ' . $this->getInstitution() . "\n");
1542 }
1543 if ($this->getDepartment() !== '') {
1544 $body .= ($language->txt('department') . ': ' . $this->getDepartment() . "\n");
1545 }
1546 if ($this->getStreet() !== '') {
1547 $body .= ($language->txt('street') . ': ' . $this->getStreet() . "\n");
1548 }
1549 if ($this->getCity() !== '') {
1550 $body .= ($language->txt('city') . ': ' . $this->getCity() . "\n");
1551 }
1552 if ($this->getZipcode() !== '') {
1553 $body .= ($language->txt('zipcode') . ': ' . $this->getZipcode() . "\n");
1554 }
1555 if ($this->getCountry() !== '') {
1556 $body .= ($language->txt('country') . ': ' . $this->getCountry() . "\n");
1557 }
1558 if ($this->getPhoneOffice() !== '') {
1559 $body .= ($language->txt('phone_office') . ': ' . $this->getPhoneOffice() . "\n");
1560 }
1561 if ($this->getPhoneHome() !== '') {
1562 $body .= ($language->txt('phone_home') . ': ' . $this->getPhoneHome() . "\n");
1563 }
1564 if ($this->getPhoneMobile() !== '') {
1565 $body .= ($language->txt('phone_mobile') . ': ' . $this->getPhoneMobile() . "\n");
1566 }
1567 if ($this->getFax() !== '') {
1568 $body .= ($language->txt('fax') . ': ' . $this->getFax() . "\n");
1569 }
1570 if ($this->getEmail() !== '') {
1571 $body .= ($language->txt('email') . ': ' . $this->getEmail() . "\n");
1572 }
1573 if ($this->getSecondEmail() !== null
1574 && $this->getSecondEmail() !== '') {
1575 $body .= ($language->txt('second_email') . ': ' . $this->getSecondEmail() . "\n");
1576 }
1577 if ($this->getHobby() !== '') {
1578 $body .= ($language->txt('hobby') . ': ' . $this->getHobby() . "\n");
1579 }
1580 if ($this->getComment() !== '') {
1581 $body .= ($language->txt('referral_comment') . ': ' . $this->getComment() . "\n");
1582 }
1583 if ($this->getMatriculation() !== '') {
1584 $body .= ($language->txt('matriculation') . ': ' . $this->getMatriculation() . "\n");
1585 }
1586 if ($this->getCreateDate() !== '') {
1589 $date = ilDatePresentation::formatDate(new ilDateTime($this->getCreateDate(), IL_CAL_DATETIME));
1591
1592 $body .= ($language->txt('create_date') . ': ' . $date . "\n");
1593 }
1594
1595 $gr = [];
1596 foreach ($rbacreview->getGlobalRoles() as $role) {
1597 if ($rbacreview->isAssigned($this->getId(), $role)) {
1598 $gr[] = ilObjRole::_lookupTitle($role);
1599 }
1600 }
1601 if (count($gr)) {
1602 $body .= ($language->txt('reg_role_info') . ': ' . implode(',', $gr) . "\n");
1603 }
1604
1605 // Time limit
1606 if ($this->getTimeLimitUnlimited()) {
1607 $body .= ($language->txt('time_limit') . ': ' . $language->txt('crs_unlimited') . "\n");
1608 } else {
1612 new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX),
1613 new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX)
1614 );
1616
1617 $start = new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX);
1618 $end = new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX);
1619
1620 $body .= $language->txt('time_limit') . ': ' .
1621 $language->txt('from') . ' ' .
1622 $start->get(IL_CAL_DATETIME) . ' ';
1623 $body .= $language->txt('to') . ' ' . $end->get(IL_CAL_DATETIME) . "\n";
1624 }
1625
1626 foreach ($profile->getAllUserDefinedFields() as $field) {
1627 $data = $field->retrieveValueFromUser($this);
1628 if ($data !== '') {
1629 $body .= "{$field->getLabel($this->lng)}: {$data}\n";
1630 }
1631 }
1632
1633 return $body;
1634 }
1635
1636 public function setFeedPass(
1637 string $a_password
1638 ): void {
1639 $this->writePref(
1640 'priv_feed_pass',
1641 ($a_password == '') ? '' : md5($a_password)
1642 );
1643 }
1644
1645 public function hasPublicProfile(): bool
1646 {
1647 return in_array($this->getPref('public_profile'), ['y', 'g']);
1648 }
1649
1650 public function getPublicName(): string
1651 {
1652 if ($this->hasPublicProfile()) {
1653 return $this->getFirstname() . ' ' . $this->getLastname() . ' (' . $this->getLogin() . ')';
1654 }
1655
1656 return $this->getLogin();
1657 }
1658
1659 public function resetOwner(): void
1660 {
1661 $ilDB = $this->db;
1662
1663 $query = 'UPDATE object_data SET owner = 0 ' .
1664 'WHERE owner = ' . $ilDB->quote($this->getId(), 'integer');
1665 $ilDB->query($query);
1666 }
1667
1668
1669 public function exportPersonalData(): void
1670 {
1671 if (!isset($this->user)) {
1672 global $DIC;
1673 $this->user = $DIC->user();
1674 }
1675 $export_consumer = (new ExportFactory())->consumer()->handler();
1676 $configs = $export_consumer->exportConfig()->allExportConfigs();
1678 $config = $configs->getElementByClassName('ilUserExportConfig');
1679 $config->setExportType('personal_data');
1680 $export = $export_consumer->createStandardExportByObject(
1681 $this->user->getId(),
1682 $this,
1683 $configs
1684 );
1685 $stream = Streams::ofString($export->getIRSSInfo()->getStream()->getContents());
1686 $file_name = $export->getIRSSInfo()->getFileName();
1687 $export->getIRSS()->delete($export_consumer->exportStakeholderHandler());
1688 $this->delivery->deliver($stream, $file_name);
1689 }
1690
1691 public function getPersonalDataExportFile(): string
1692 {
1693 $dir = ilExport::_getExportDirectory($this->getId(), 'xml', 'usr', 'personal_data');
1694 if (!is_dir($dir)) {
1695 return '';
1696 }
1697 foreach (ilFileUtils::getDir($dir) as $entry) {
1698 if (is_int(strpos($entry['entry'], '.zip'))) {
1699 return $entry['entry'];
1700 }
1701 }
1702
1703 return '';
1704 }
1705
1706 public function sendPersonalDataFile(): void
1707 {
1708 $file = ilExport::_getExportDirectory($this->getId(), 'xml', 'usr', 'personal_data') .
1709 '/' . $this->getPersonalDataExportFile();
1710 if (is_file($file)) {
1711 ilFileDelivery::deliverFileLegacy($file, $this->getPersonalDataExportFile());
1712 }
1713 }
1714
1715 public function importPersonalData(
1716 array $a_file,
1717 bool $a_profile_data,
1718 bool $a_settings,
1719 bool $a_notes,
1720 bool $a_calendar
1721 ): void {
1722 $imp = new ilImport();
1723 // bookmarks need to be skipped, importer does not exist anymore
1724 $imp->addSkipImporter('components/ILIAS/Bookmarks');
1725 if (!$a_profile_data) {
1726 $imp->addSkipEntity('components/ILIAS/User', 'usr_profile');
1727 }
1728 if (!$a_settings) {
1729 $imp->addSkipEntity('components/ILIAS/User', 'usr_setting');
1730 }
1731 if (!$a_notes) {
1732 $imp->addSkipEntity('components/ILIAS/Notes', 'user_notes');
1733 }
1734 if (!$a_calendar) {
1735 $imp->addSkipEntity('components/ILIAS/Calendar', 'calendar');
1736 }
1737 $imp->importEntity(
1738 $a_file['tmp_name'],
1739 $a_file['name'],
1740 'usr',
1741 'components/ILIAS/User'
1742 );
1743 }
1744
1745 public function setInactivationDate(?string $inactivation_date): void
1746 {
1747 $this->inactivation_date = $inactivation_date;
1748 }
1749
1750 public function getInactivationDate(): ?string
1751 {
1752 return $this->inactivation_date;
1753 }
1754
1755 public function isAnonymous(): bool
1756 {
1757 return self::_isAnonymous($this->getId());
1758 }
1759
1760 public static function _isAnonymous(int $usr_id): bool
1761 {
1762 return $usr_id == ANONYMOUS_USER_ID;
1763 }
1764
1765 public function activateDeletionFlag(): void
1766 {
1767 $this->writePref('delete_flag', true);
1768 }
1769
1770 public function removeDeletionFlag(): void
1771 {
1772 $this->writePref('delete_flag', false);
1773 }
1774
1775 public function hasDeletionFlag(): bool
1776 {
1777 return (bool) $this->getPref('delete_flag');
1778 }
1779
1780 public function setIsSelfRegistered(bool $status): void
1781 {
1782 $this->is_self_registered = $status;
1783 }
1784
1785 public function isSelfRegistered(): bool
1786 {
1787 return $this->is_self_registered;
1788 }
1789
1793 public function setGeneralInterests(?array $value = null): void
1794 {
1795 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1796 $this->profile_configuration_repository->getByClass(Interests::class)->getIdentifier(),
1797 $value ?? []
1798 );
1799 }
1800
1804 public function getGeneralInterests(): array
1805 {
1806 return $this->profile_data->getAdditionalFieldByIdentifier(
1807 $this->profile_configuration_repository->getByClass(Interests::class)->getIdentifier()
1808 ) ?? [];
1809 }
1810
1814 public function getGeneralInterestsAsText(): string
1815 {
1816 return $this->buildTextFromArray($this->getGeneralInterests());
1817 }
1818
1822 public function setOfferingHelp(?array $value = null): void
1823 {
1824 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1825 $this->profile_configuration_repository->getByClass(HelpOffered::class)->getIdentifier(),
1826 $value ?? []
1827 );
1828 }
1829
1833 public function getOfferingHelp(): array
1834 {
1835 return $this->profile_data->getAdditionalFieldByIdentifier(
1836 $this->profile_configuration_repository->getByClass(HelpOffered::class)->getIdentifier()
1837 ) ?? [];
1838 }
1839
1843 public function getOfferingHelpAsText(): string
1844 {
1845 return $this->buildTextFromArray($this->getOfferingHelp());
1846 }
1847
1848 public function setLookingForHelp(?array $value = null): void
1849 {
1850 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1851 $this->profile_configuration_repository->getByClass(HelpLookedFor::class)->getIdentifier(),
1852 $value ?? []
1853 );
1854 }
1855
1856 public function getLookingForHelp(): array
1857 {
1858 return $this->profile_data->getAdditionalFieldByIdentifier(
1859 $this->profile_configuration_repository->getByClass(HelpLookedFor::class)->getIdentifier()
1860 ) ?? [];
1861 }
1862
1863 public function getLookingForHelpAsText(): string
1864 {
1865 return $this->buildTextFromArray($this->getLookingForHelp());
1866 }
1867
1868
1869 public function uploadPersonalPicture(
1870 string $tmp_file
1871 ): bool {
1872 $stakeholder = new ilUserProfilePictureStakeholder();
1873 $stakeholder->setOwner($this->getId());
1874 $stream = Streams::ofResource(fopen($tmp_file, 'rb'));
1875
1876 if ($this->getAvatarRid() !== null && $this->getAvatarRid() !== ilObjUser::NO_AVATAR_RID) {
1877 $rid = $this->irss->manage()->find($this->getAvatarRid());
1878 // append profile picture
1879 $this->irss->manage()->replaceWithStream(
1880 $rid,
1881 $stream,
1882 $stakeholder
1883 );
1884 } else {
1885 // new profile picture
1886 $rid = $this->irss->manage()->stream(
1887 $stream,
1888 $stakeholder
1889 );
1890 }
1891
1892 $this->setAvatarRid($rid);
1893 $this->update();
1894 return true;
1895 }
1896
1897 private function buildTextFromArray(array $a_attr): string
1898 {
1899 if (count($a_attr) > 0) {
1900 return implode(', ', $a_attr);
1901 }
1902 return '';
1903 }
1904
1905 /*
1906 * 2025-07-16, sw: Hic sunt dracones. Static methods that need to be gone!
1907 */
1908
1909 public static function _loginExists(
1910 string $a_login,
1911 int $a_user_id = 0
1912 ): ?int {
1913 global $DIC;
1914 $ilDB = $DIC['ilDB'];
1915
1916 $q = 'SELECT DISTINCT login, usr_id FROM usr_data ' .
1917 'WHERE login = %s';
1918 $types[] = 'text';
1919 $values[] = $a_login;
1920
1921 if ($a_user_id != 0) {
1922 $q .= ' AND usr_id != %s ';
1923 $types[] = 'integer';
1924 $values[] = $a_user_id;
1925 }
1926
1927 $r = $ilDB->queryF($q, $types, $values);
1928
1929 if (($row = $ilDB->fetchAssoc($r))) {
1930 return (int) $row['usr_id'];
1931 }
1932 return null;
1933 }
1934
1935 public static function _externalAccountExists(
1936 string $a_external_account,
1937 string $a_auth_mode
1938 ): bool {
1939 global $DIC;
1940 $ilDB = $DIC['ilDB'];
1941
1942 $res = $ilDB->queryF(
1943 'SELECT * FROM usr_data ' .
1944 'WHERE ext_account = %s AND auth_mode = %s',
1945 ['text', 'text'],
1946 [$a_external_account, $a_auth_mode]
1947 );
1948 return (bool) $ilDB->fetchAssoc($res);
1949 }
1950
1951 public static function _getUsersForRole(
1952 int $role_id,
1953 int $active = -1
1954 ): array {
1955 global $DIC;
1956 $ilDB = $DIC['ilDB'];
1957 $rbacreview = $DIC['rbacreview'];
1958
1959 $ids = $rbacreview->assignedUsers($role_id);
1960
1961 if (count($ids) == 0) {
1962 $ids = [-1];
1963 }
1964
1965 $query = 'SELECT usr_data.*, usr_pref.value AS language
1966 FROM usr_data
1967 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
1968 WHERE ' . $ilDB->in('usr_data.usr_id', $ids, false, 'integer');
1969 $values[] = 'language';
1970 $types[] = 'text';
1971
1972
1973 if (is_numeric($active) && $active > -1) {
1974 $query .= ' AND usr_data.active = %s';
1975 $values[] = $active;
1976 $types[] = 'integer';
1977 }
1978
1979 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
1980
1981 $r = $ilDB->queryF($query, $types, $values);
1982 $data = [];
1983 while ($row = $ilDB->fetchAssoc($r)) {
1984 $data[] = $row;
1985 }
1986 return $data;
1987 }
1988
1989 public static function _getUsersForFolder(
1990 int $ref_id,
1991 int $active
1992 ): array {
1993 global $DIC;
1994 $ilDB = $DIC['ilDB'];
1995
1996 $query = 'SELECT usr_data.*, usr_pref.value AS language FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id and usr_pref.keyword = %s WHERE 1=1';
1997 $types[] = 'text';
1998 $values[] = 'language';
1999
2000 if (is_numeric($active) && $active > -1) {
2001 $query .= ' AND usr_data.active = %s';
2002 $values[] = $active;
2003 $types[] = 'integer';
2004 }
2005
2006 if ($ref_id != USER_FOLDER_ID) {
2007 $query .= ' AND usr_data.time_limit_owner = %s';
2008 $values[] = $ref_id;
2009 $types[] = 'integer';
2010 }
2011
2012 $query .= ' AND usr_data.usr_id != %s ';
2013 $values[] = ANONYMOUS_USER_ID;
2014 $types[] = 'integer';
2015
2016 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2017
2018 $result = $ilDB->queryF($query, $types, $values);
2019 $data = [];
2020 while ($row = $ilDB->fetchAssoc($result)) {
2021 $data[] = $row;
2022 }
2023
2024 return $data;
2025 }
2026
2027 public static function _getUsersForGroup(
2028 array $a_mem_ids,
2029 int $active = -1
2030 ): array {
2031 return self::_getUsersForIds($a_mem_ids, $active);
2032 }
2033
2034 public static function _getUsersForIds(
2035 array $a_mem_ids,
2036 int $active = -1,
2037 int $timelimitowner = -1
2038 ): array {
2039 global $DIC;
2040 $ilDB = $DIC['ilDB'];
2041
2042 $query = 'SELECT usr_data.*, usr_pref.value AS language
2043 FROM usr_data
2044 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
2045 WHERE ' . $ilDB->in('usr_data.usr_id', $a_mem_ids, false, 'integer') . '
2046 AND usr_data.usr_id != %s';
2047 $values[] = 'language';
2048 $types[] = 'text';
2049 $values[] = ANONYMOUS_USER_ID;
2050 $types[] = 'integer';
2051
2052 if (is_numeric($active) && $active > -1) {
2053 $query .= ' AND active = %s';
2054 $values[] = $active;
2055 $types[] = 'integer';
2056 }
2057
2058 if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1) {
2059 $query .= ' AND usr_data.time_limit_owner = %s';
2060 $values[] = $timelimitowner;
2061 $types[] = 'integer';
2062 }
2063
2064 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2065
2066 $result = $ilDB->queryF($query, $types, $values);
2067 $mem_arr = [];
2068 while ($row = $ilDB->fetchAssoc($result)) {
2069 $mem_arr[] = $row;
2070 }
2071
2072 return $mem_arr;
2073 }
2074
2075 public static function _getUserData(array $a_internalids): array
2076 {
2077 global $DIC;
2078 $ilDB = $DIC['ilDB'];
2079
2080 $ids = [];
2081 if (is_array($a_internalids)) {
2082 foreach ($a_internalids as $internalid) {
2083 if (is_numeric($internalid)) {
2084 $ids[] = $internalid;
2085 } else {
2086 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
2087 if (is_numeric($parsedid) && $parsedid > 0) {
2088 $ids[] = $parsedid;
2089 }
2090 }
2091 }
2092 }
2093 if (count($ids) == 0) {
2094 $ids [] = -1;
2095 }
2096
2097 $query = 'SELECT usr_data.*, usr_pref.value AS language
2098 FROM usr_data
2099 LEFT JOIN usr_pref
2100 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
2101 WHERE ' . $ilDB->in('usr_data.usr_id', $ids, false, 'integer');
2102 $values[] = 'language';
2103 $types[] = 'text';
2104
2105 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2106
2107 $data = [];
2108 $result = $ilDB->queryF($query, $types, $values);
2109 while ($row = $ilDB->fetchAssoc($result)) {
2110 $data[] = $row;
2111 }
2112 return $data;
2113 }
2114
2115 public static function getUserSubsetByPreferenceValue(
2116 array $a_user_ids,
2117 string $a_keyword,
2118 string $a_val
2119 ): array {
2120 global $DIC;
2121 $ilDB = $DIC['ilDB'];
2122
2123 $users = [];
2124 $set = $ilDB->query(
2125 'SELECT usr_id FROM usr_pref ' .
2126 ' WHERE keyword = ' . $ilDB->quote($a_keyword, 'text') .
2127 ' AND ' . $ilDB->in('usr_id', $a_user_ids, false, 'integer') .
2128 ' AND value = ' . $ilDB->quote($a_val, 'text')
2129 );
2130 while ($rec = $ilDB->fetchAssoc($set)) {
2131 $users[] = $rec['usr_id'];
2132 }
2133 return $users;
2134 }
2135
2136 public static function _getLoginAttempts(
2137 int $a_usr_id
2138 ): int {
2139 global $DIC;
2140 $ilDB = $DIC['ilDB'];
2141
2142 $query = 'SELECT login_attempts FROM usr_data WHERE usr_id = %s';
2143 $result = $ilDB->queryF($query, ['integer'], [$a_usr_id]);
2144 $record = $ilDB->fetchAssoc($result);
2145 return (int) ($record['login_attempts'] ?? 0);
2146 }
2147
2148 public static function _incrementLoginAttempts(
2149 int $a_usr_id
2150 ): bool {
2151 global $DIC;
2152 $ilDB = $DIC['ilDB'];
2153
2154 $query = 'UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s';
2155 $affected = $ilDB->manipulateF($query, ['integer'], [$a_usr_id]);
2156
2157 if ($affected) {
2158 return true;
2159 } else {
2160 return false;
2161 }
2162 }
2163
2164 public static function _setUserInactive(
2165 int $a_usr_id
2166 ): bool {
2167 global $DIC;
2168 $ilDB = $DIC['ilDB'];
2169
2170 $query = 'UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s';
2171 $affected = $ilDB->manipulateF($query, ['timestamp', 'integer'], [ilUtil::now(), $a_usr_id]);
2172
2173 if ($affected) {
2174 return true;
2175 } else {
2176 return false;
2177 }
2178 }
2179
2180 public static function _getUsersOnline(
2181 int $a_user_id = 0,
2182 bool $a_no_anonymous = false
2183 ): array {
2184 global $DIC;
2185 $ilDB = $DIC['ilDB'];
2186
2188
2189 $pd_set = new ilSetting('pd');
2190 $atime = $pd_set->get('user_activity_time') * 60;
2191 $ctime = time();
2192
2193 $where = [];
2194
2195 if ($a_user_id === 0) {
2196 $where[] = 'user_id > 0';
2197 } else {
2198 $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
2199 }
2200
2201 if ($a_no_anonymous) {
2202 $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
2203 }
2204
2205 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
2206 $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
2207 }
2208
2209 $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
2210 $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
2211
2212 $where = 'WHERE ' . implode(' AND ', $where);
2213
2214 $r = $ilDB->queryF(
2215 $q = "
2216 SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, context, agree_date
2217 FROM usr_session
2218 LEFT JOIN usr_data u
2219 ON user_id = u.usr_id
2220 LEFT JOIN usr_pref p
2221 ON (p.usr_id = u.usr_id AND p.keyword = %s)
2222 {$where}
2223 GROUP BY user_id, firstname, lastname, title, login, last_login, context, agree_date
2224 ORDER BY lastname, firstname
2225 ",
2226 ['text'],
2227 ['hide_own_online_status']
2228 );
2229
2230 $log->debug('Query: ' . $q);
2231
2232 $users = [];
2233 while ($user = $ilDB->fetchAssoc($r)) {
2234 if ($atime <= 0 || $user['ctime'] + $atime > $ctime) {
2235 $users[$user['user_id']] = $user;
2236 }
2237 }
2238
2239 $log->debug('Found users: ' . count($users));
2240
2241 $hide_users = $DIC['legalDocuments']->usersWithHiddenOnlineStatus(array_map(intval(...), array_column($users, 'user_id')));
2242 $users = array_filter(
2243 $users,
2244 fn($user) => !in_array((int) $user['user_id'], $hide_users, true)
2245 );
2246
2247 return $users;
2248 }
2249
2250 public static function getUserIdsByInactivityPeriod(
2251 int $periodInDays
2252 ): array {
2253 global $DIC;
2254 $ilDB = $DIC['ilDB'];
2255
2256 if ($periodInDays < 1) {
2257 throw new ilException('Invalid period given');
2258 }
2259
2260 $date = date('Y-m-d H:i:s', (time() - ($periodInDays * 24 * 60 * 60)));
2261
2262 $query = 'SELECT usr_id FROM usr_data WHERE last_login IS NOT NULL AND last_login < %s';
2263
2264 $ids = [];
2265
2266 $types = ['timestamp'];
2267 $values = [$date];
2268
2269 $res = $ilDB->queryF($query, $types, $values);
2270 while ($row = $ilDB->fetchAssoc($res)) {
2271 $ids[] = (int) $row['usr_id'];
2272 }
2273
2274 return $ids;
2275 }
2276
2277 public static function getUserIdsNeverLoggedIn(
2278 int $thresholdInDays
2279 ): array {
2280 global $DIC;
2281 $ilDB = $DIC['ilDB'];
2282
2283 $date = date('Y-m-d H:i:s', (time() - ($thresholdInDays * 24 * 60 * 60)));
2284
2285 $query = 'SELECT usr_id FROM usr_data WHERE last_login IS NULL AND create_date < %s';
2286
2287 $ids = [];
2288
2289 $types = ['timestamp'];
2290 $values = [$date];
2291
2292 $res = $ilDB->queryF($query, $types, $values);
2293 while ($row = $ilDB->fetchAssoc($res)) {
2294 $ids[] = (int) $row['usr_id'];
2295 }
2296
2297 return $ids;
2298 }
2299
2300 public static function _getUserIdsByInactivationPeriod(
2301 int $period
2302 ): array {
2303 if (!$period) {
2304 throw new ilException('no valid period given');
2305 }
2306
2307 global $DIC;
2308 $db = $DIC['ilDB'];
2309
2310 $res = $db->queryF(
2311 'SELECT usr_id FROM usr_data WHERE inactivation_date < %s AND active = %s',
2312 ['timestamp', 'integer'],
2313 [
2314 date('Y-m-d H:i:s', (time() - ($period * 24 * 60 * 60))),
2315 0
2316 ]
2317 );
2318
2319 $ids = [];
2320 while ($row = $db->fetchObject($res)) {
2321 $ids[] = (int) $row->usr_id;
2322 }
2323
2324 return $ids;
2325 }
2326
2327 public static function getFirstLettersOfLastnames(
2328 ?array $user_ids = null
2329 ): array {
2330 global $DIC;
2331 $ilDB = $DIC['ilDB'];
2332
2333 $q = 'SELECT DISTINCT ' . $ilDB->upper($ilDB->substr('lastname', 1, 1)) . ' let' .
2334 ' FROM usr_data' .
2335 ' WHERE usr_id <> ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer') .
2336 ($user_ids !== null ? ' AND ' . $ilDB->in('usr_id', $user_ids, false, 'integer') : '') .
2337 ' ORDER BY let';
2338 $let_set = $ilDB->query($q);
2339
2340 $let = [];
2341 while ($let_rec = $ilDB->fetchAssoc($let_set)) {
2342 $let[$let_rec['let']] = $let_rec['let'];
2343 }
2344 return $let;
2345 }
2346
2347 public static function userExists(
2348 array $a_usr_ids = []
2349 ): bool {
2350 global $DIC;
2351 $ilDB = $DIC['ilDB'];
2352
2353 $query = 'SELECT count(*) num FROM object_data od ' .
2354 'JOIN usr_data ud ON obj_id = usr_id ' .
2355 'WHERE ' . $ilDB->in('obj_id', $a_usr_ids, false, 'integer') . ' ';
2356 $res = $ilDB->query($query);
2357 $num_rows = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
2358 return $num_rows == count($a_usr_ids);
2359 }
2360
2361 public static function _doesLoginnameExistInHistory(string $a_login): bool
2362 {
2363 global $DIC;
2364 $ilDB = $DIC['ilDB'];
2365
2366 $res = $ilDB->queryF(
2367 '
2368 SELECT * FROM loginname_history
2369 WHERE login = %s',
2370 ['text'],
2371 [$a_login]
2372 );
2373
2374 return (bool) $ilDB->fetchAssoc($res);
2375 }
2376
2377 public static function _lookupPref(
2378 int $a_usr_id,
2379 string $a_keyword
2380 ): ?string {
2381 global $DIC;
2382 $ilDB = $DIC['ilDB'];
2383
2384 $query = 'SELECT * FROM usr_pref WHERE usr_id = ' . $ilDB->quote($a_usr_id, 'integer') . ' ' .
2385 'AND keyword = ' . $ilDB->quote($a_keyword, 'text');
2386 $res = $ilDB->query($query);
2387
2388 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2389 return $row->value;
2390 }
2391 return null;
2392 }
2393
2394 public static function lookupMatriculation(int $a_usr_id): string
2395 {
2396 global $DIC;
2397 $ilDB = $DIC['ilDB'];
2398
2399 $query = 'SELECT matriculation FROM usr_data ' .
2400 'WHERE usr_id = ' . $ilDB->quote($a_usr_id);
2401 $res = $ilDB->query($query);
2402 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
2403 return $row->matriculation ?: '';
2404 }
2405
2406 public static function findInterests(
2407 string $a_term,
2408 ?int $a_user_id = null,
2409 ?string $a_field_id = null
2410 ): array {
2411 global $DIC;
2412 $ilDB = $DIC['ilDB'];
2413
2414 $res = [];
2415
2416 $sql = 'SELECT DISTINCT(value)' .
2417 ' FROM usr_profile_data' .
2418 ' WHERE ' . $ilDB->like('value', 'text', '%' . $a_term . '%');
2419 if ($a_field_id) {
2420 $sql .= ' AND field_id = ' . $ilDB->quote($a_field_id, 'text');
2421 }
2422 if ($a_user_id) {
2423 $sql .= ' AND usr_id <> ' . $ilDB->quote($a_user_id, 'integer');
2424 }
2425 $sql .= ' ORDER BY value';
2426 $set = $ilDB->query($sql);
2427 while ($row = $ilDB->fetchAssoc($set)) {
2428 $res[] = $row['value'];
2429 }
2430
2431 return $res;
2432 }
2433
2434 public static function getProfileStatusOfUsers(
2435 array $a_user_ids
2436 ): array {
2437 global $DIC;
2438 $ilDB = $DIC->database();
2439
2440 $set = $ilDB->query(
2441 'SELECT * FROM usr_pref ' .
2442 ' WHERE keyword = ' . $ilDB->quote('public_profile', 'text') .
2443 ' AND ' . $ilDB->in('usr_id', $a_user_ids, false, 'integer')
2444 );
2445 $r = [
2446 'global' => [],
2447 'local' => [],
2448 'public' => [],
2449 'not_public' => []
2450 ];
2451 while ($rec = $ilDB->fetchAssoc($set)) {
2452 if ($rec['value'] == 'g') {
2453 $r['global'][] = $rec['usr_id'];
2454 $r['public'][] = $rec['usr_id'];
2455 }
2456 if ($rec['value'] == 'y') {
2457 $r['local'][] = $rec['usr_id'];
2458 $r['public'][] = $rec['usr_id'];
2459 }
2460 }
2461 foreach ($a_user_ids as $id) {
2462 if (!in_array($id, $r['public'])) {
2463 $r['not_public'][] = $id;
2464 }
2465 }
2466
2467 return $r;
2468 }
2469
2470 private static function _lookup(
2471 int $a_user_id,
2472 string $a_field
2473 ): ?string {
2474 global $DIC;
2475 $ilDB = $DIC['ilDB'];
2476
2477 $res = $ilDB->queryF(
2478 'SELECT ' . $a_field . ' FROM usr_data WHERE usr_id = %s',
2479 ['integer'],
2480 [$a_user_id]
2481 );
2482
2483 while ($set = $ilDB->fetchAssoc($res)) {
2484 return $set[$a_field];
2485 }
2486 return null;
2487 }
2488
2489 public static function _lookupFullname(int $a_user_id): string
2490 {
2491 global $DIC;
2492 $ilDB = $DIC['ilDB'];
2493
2494 $fullname = '';
2495
2496 $set = $ilDB->queryF(
2497 'SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s',
2498 ['integer'],
2499 [$a_user_id]
2500 );
2501
2502 if ($rec = $ilDB->fetchAssoc($set)) {
2503 if ($rec['title']) {
2504 $fullname = $rec['title'] . ' ';
2505 }
2506 if ($rec['firstname']) {
2507 $fullname .= $rec['firstname'] . ' ';
2508 }
2509 if ($rec['lastname']) {
2510 $fullname .= $rec['lastname'];
2511 }
2512 }
2513 return $fullname;
2514 }
2515
2516 public static function _lookupEmail(int $a_user_id): string
2517 {
2518 return self::_lookup($a_user_id, 'email') ?? '';
2519 }
2520
2521 public static function _lookupGender(int $a_user_id): string
2522 {
2523 return (string) self::_lookup($a_user_id, 'gender') ?? '';
2524 }
2525
2526 public static function _lookupClientIP(int $a_user_id): string
2527 {
2528 return self::_lookup($a_user_id, 'client_ip') ?? '';
2529 }
2530
2531 public static function _lookupName(int $a_user_id): array
2532 {
2533 global $DIC;
2534 $ilDB = $DIC['ilDB'];
2535
2536 $res = $ilDB->queryF(
2537 'SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s',
2538 ['integer'],
2539 [$a_user_id]
2540 );
2541 if (($user_rec = $ilDB->fetchAssoc($res))) {
2542 return ['user_id' => $a_user_id,
2543 'firstname' => $user_rec['firstname'],
2544 'lastname' => $user_rec['lastname'],
2545 'title' => $user_rec['title'],
2546 'login' => $user_rec['login']
2547 ];
2548 }
2549 return ['user_id' => 0,
2550 'firstname' => '',
2551 'lastname' => '',
2552 'title' => '',
2553 'login' => ''
2554 ];
2555 }
2556
2557 public static function _lookupLanguage(int $a_usr_id): string
2558 {
2559 global $DIC;
2560 $ilDB = $DIC['ilDB'];
2561 $lng = $DIC['lng'];
2562
2563 $q = 'SELECT value FROM usr_pref WHERE usr_id= ' .
2564 $ilDB->quote($a_usr_id, 'integer') . ' AND keyword = ' .
2565 $ilDB->quote('language', 'text');
2566 $r = $ilDB->query($q);
2567
2568 while ($row = $ilDB->fetchAssoc($r)) {
2569 return (string) $row['value'];
2570 }
2571 if (is_object($lng)) {
2572 return $lng->getDefaultLanguage();
2573 }
2574 return 'en';
2575 }
2576
2577 public static function _writeExternalAccount(
2578 int $a_usr_id,
2579 string $a_ext_id
2580 ): void {
2581 global $DIC;
2582 $ilDB = $DIC['ilDB'];
2583
2584 $ilDB->manipulateF(
2585 'UPDATE usr_data ' .
2586 ' SET ext_account = %s WHERE usr_id = %s',
2587 ['text', 'integer'],
2588 [$a_ext_id, $a_usr_id]
2589 );
2590 }
2591
2592 public static function _writeAuthMode(int $a_usr_id, string $a_auth_mode): void
2593 {
2594 global $DIC;
2595 $ilDB = $DIC['ilDB'];
2596
2597 $ilDB->manipulateF(
2598 'UPDATE usr_data ' .
2599 ' SET auth_mode = %s WHERE usr_id = %s',
2600 ['text', 'integer'],
2601 [$a_auth_mode, $a_usr_id]
2602 );
2603 }
2604
2608 public static function _lookupFields(int $a_user_id): array // Missing array type.
2609 {
2610 global $DIC;
2611 $ilDB = $DIC['ilDB'];
2612
2613 $res = $ilDB->queryF(
2614 'SELECT * FROM usr_data WHERE usr_id = %s',
2615 ['integer'],
2616 [$a_user_id]
2617 );
2618 $user_rec = $ilDB->fetchAssoc($res);
2619 return $user_rec;
2620 }
2621
2622 public static function _lookupActive(int $a_usr_id): bool
2623 {
2624 global $DIC;
2625 $ilDB = $DIC['ilDB'];
2626
2627 $query = 'SELECT usr_id FROM usr_data ' .
2628 'WHERE active = ' . $ilDB->quote(1, 'integer') . ' ' .
2629 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
2630 $res = $ilDB->query($query);
2631 while ($res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2632 return true;
2633 }
2634 return false;
2635 }
2636
2637 public static function _lookupLogin(int $a_user_id): string
2638 {
2639 return (string) self::_lookup($a_user_id, 'login') ?? '';
2640 }
2641
2642 public static function _lookupExternalAccount(int $a_user_id): string
2643 {
2644 return (string) self::_lookup($a_user_id, 'ext_account') ?? '';
2645 }
2646
2653 public static function _getExternalAccountsByAuthMode(
2654 string $a_auth_mode,
2655 bool $a_read_auth_default = false
2656 ): array {
2657 global $DIC;
2658
2659 $ilDB = $DIC['ilDB'];
2660 $ilSetting = $DIC['ilSetting'];
2661
2662 $q = 'SELECT login,usr_id,ext_account,auth_mode FROM usr_data ' .
2663 'WHERE auth_mode = %s';
2664 $types[] = 'text';
2665 $values[] = $a_auth_mode;
2666 if ($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode', ilAuthUtils::AUTH_LOCAL)) == $a_auth_mode) {
2667 $q .= ' OR auth_mode = %s ';
2668 $types[] = 'text';
2669 $values[] = 'default';
2670 }
2671
2672 $res = $ilDB->queryF($q, $types, $values);
2673 $accounts = [];
2674 while ($row = $ilDB->fetchObject($res)) {
2675 if ($row->auth_mode == 'default') {
2676 $accounts[$row->usr_id] = $row->login;
2677 } else {
2678 $accounts[$row->usr_id] = $row->ext_account;
2679 }
2680 }
2681 return $accounts;
2682 }
2683
2684 public static function _toggleActiveStatusOfUsers(
2685 array $a_usr_ids,
2686 bool $a_status
2687 ): void {
2688 global $DIC;
2689
2690 $ilDB = $DIC['ilDB'];
2691
2692 if ($a_status) {
2693 $q = 'UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ' .
2694 $ilDB->in('usr_id', $a_usr_ids, false, 'integer');
2695 $ilDB->manipulate($q);
2696 } else {
2697 $usrId_IN_usrIds = $ilDB->in('usr_id', $a_usr_ids, false, 'integer');
2698
2699 $q = 'UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds';
2700 $ilDB->manipulate($q);
2701
2702 $queryString = '
2703 UPDATE usr_data
2704 SET inactivation_date = %s
2705 WHERE inactivation_date IS NULL
2706 AND $usrId_IN_usrIds
2707 ';
2708 $ilDB->manipulateF($queryString, ['timestamp'], [ilUtil::now()]);
2709 }
2710 }
2711
2712 public static function _lookupAuthMode(int $a_usr_id): string
2713 {
2714 return (string) self::_lookup($a_usr_id, 'auth_mode');
2715 }
2716
2721 public static function _checkExternalAuthAccount(
2722 string $a_auth,
2723 string $a_account,
2724 bool $tryFallback = true
2725 ): ?string {
2726 $db = $GLOBALS['DIC']->database();
2727 $settings = $GLOBALS['DIC']->settings();
2728
2729 // Check directly with auth_mode
2730 $r = $db->queryF(
2731 'SELECT * FROM usr_data WHERE ' .
2732 ' ext_account = %s AND auth_mode = %s',
2733 ['text', 'text'],
2734 [$a_account, $a_auth]
2735 );
2736 if ($usr = $db->fetchAssoc($r)) {
2737 return $usr['login'];
2738 }
2739
2740 if (!$tryFallback) {
2741 return null;
2742 }
2743
2744 // For compatibility, check for login (no ext_account entry given)
2745 $res = $db->queryF(
2746 'SELECT login FROM usr_data ' .
2747 'WHERE login = %s AND auth_mode = %s AND (ext_account IS NULL OR ext_account = "") ',
2748 ['text', 'text'],
2749 [$a_account, $a_auth]
2750 );
2751 if ($usr = $db->fetchAssoc($res)) {
2752 return $usr['login'];
2753 }
2754
2755 // If auth_default == $a_auth => check for login
2756 if (ilAuthUtils::_getAuthModeName($settings->get('auth_mode')) == $a_auth) {
2757 $res = $db->queryF(
2758 'SELECT login FROM usr_data WHERE ' .
2759 ' ext_account = %s AND auth_mode = %s',
2760 ['text', 'text'],
2761 [$a_account, 'default']
2762 );
2763 if ($usr = $db->fetchAssoc($res)) {
2764 return $usr['login'];
2765 }
2766 // Search for login (no ext_account given)
2767 $res = $db->queryF(
2768 'SELECT login FROM usr_data ' .
2769 'WHERE login = %s AND (ext_account IS NULL OR ext_account = "") AND auth_mode = %s',
2770 ['text', 'text'],
2771 [$a_account, 'default']
2772 );
2773 if ($usr = $db->fetchAssoc($res)) {
2774 return $usr['login'];
2775 }
2776 }
2777 return null;
2778 }
2779
2780 public static function getUserIdByLogin(string $a_login): int
2781 {
2782 return (int) self::_lookupId($a_login);
2783 }
2784
2785 public static function getUserIdsByEmail(string $a_email): array
2786 {
2787 global $DIC;
2788 $ilDB = $DIC['ilDB'];
2789
2790 $res = $ilDB->queryF(
2791 'SELECT usr_id FROM usr_data ' .
2792 'WHERE email = %s and active = 1',
2793 ['text'],
2794 [$a_email]
2795 );
2796 $ids = [];
2797 while ($row = $ilDB->fetchObject($res)) {
2798 $ids[] = (int) $row->usr_id;
2799 }
2800
2801 return $ids;
2802 }
2803
2804 public static function getUserLoginsByEmail(string $a_email): array
2805 {
2806 global $DIC;
2807 $ilDB = $DIC['ilDB'];
2808
2809 $res = $ilDB->queryF(
2810 'SELECT login FROM usr_data ' .
2811 'WHERE email = %s and active = 1',
2812 ['text'],
2813 [$a_email]
2814 );
2815 $ids = [];
2816 while ($row = $ilDB->fetchObject($res)) {
2817 $ids[] = $row->login;
2818 }
2819
2820 return $ids;
2821 }
2822
2823 public static function _lookupId(
2824 string|array $a_user_str
2825 ): int|null|array {
2826 global $DIC;
2827 $ilDB = $DIC['ilDB'];
2828
2829 if (!is_array($a_user_str)) {
2830 $res = $ilDB->queryF(
2831 'SELECT usr_id FROM usr_data WHERE login = %s',
2832 ['text'],
2833 [$a_user_str]
2834 );
2835
2836 $user_rec = $ilDB->fetchAssoc($res);
2837 if (is_array($user_rec)) {
2838 return (int) $user_rec['usr_id'];
2839 }
2840
2841 return null;
2842 }
2843
2844 $set = $ilDB->query(
2845 'SELECT usr_id FROM usr_data ' .
2846 ' WHERE ' . $ilDB->in('login', $a_user_str, false, 'text')
2847 );
2848
2849 $ids = [];
2850 while ($rec = $ilDB->fetchAssoc($set)) {
2851 $ids[] = (int) $rec['usr_id'];
2852 }
2853
2854 return $ids;
2855 }
2856
2857 public static function _lookupLastLogin(int $a_user_id): string
2858 {
2859 return self::_lookup($a_user_id, 'last_login') ?? '';
2860 }
2861
2862 public static function _lookupFirstLogin(int $a_user_id): string
2863 {
2864 return self::_lookup($a_user_id, 'first_login') ?? '';
2865 }
2866
2867 public static function hasActiveSession(
2868 int $a_user_id,
2869 string $a_session_id
2870 ): bool {
2871 global $DIC;
2872 $ilDB = $DIC['ilDB'];
2873
2874 $set = $ilDB->queryf(
2875 '
2876 SELECT COUNT(*) session_count
2877 FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2878 ['integer', 'integer', 'text'],
2879 [$a_user_id, time(), $a_session_id]
2880 );
2881 $row = $ilDB->fetchAssoc($set);
2882 return (bool) $row['session_count'];
2883 }
2884
2885 public static function _readUsersProfileData(array $a_user_ids): array
2886 {
2887 global $DIC;
2888 $ilDB = $DIC['ilDB'];
2889
2890 $res = $ilDB->query('SELECT * FROM usr_data WHERE ' .
2891 $ilDB->in('usr_id', $a_user_ids, false, 'integer'));
2892 $user_data = [];
2893 while ($row = $ilDB->fetchAssoc($res)) {
2894 $user_data[$row['usr_id']] = $row;
2895 }
2896 return $user_data;
2897 }
2898
2899 public static function _getNumberOfUsersForStyle(
2900 string $a_skin,
2901 string $a_style
2902 ): int {
2903 global $DIC;
2904 $ilDB = $DIC['ilDB'];
2905
2906 $q = 'SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ' .
2907 ' WHERE up1.keyword= ' . $ilDB->quote('style', 'text') .
2908 ' AND up1.value= ' . $ilDB->quote($a_style, 'text') .
2909 ' AND up2.keyword= ' . $ilDB->quote('skin', 'text') .
2910 ' AND up2.value= ' . $ilDB->quote($a_skin, 'text') .
2911 ' AND up1.usr_id = up2.usr_id ';
2912
2913 $cnt_set = $ilDB->query($q);
2914
2915 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2916
2917 return (int) $cnt_rec['cnt'];
2918 }
2919
2920 public static function _getAllUserAssignedStyles(): array
2921 {
2922 global $DIC;
2923 $ilDB = $DIC['ilDB'];
2924
2925 $q = 'SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ' .
2926 ' WHERE up1.keyword = ' . $ilDB->quote('style', 'text') .
2927 ' AND up2.keyword = ' . $ilDB->quote('skin', 'text') .
2928 ' AND up1.usr_id = up2.usr_id';
2929
2930 $sty_set = $ilDB->query($q);
2931
2932 $styles = [];
2933 while ($sty_rec = $ilDB->fetchAssoc($sty_set)) {
2934 $styles[] = $sty_rec['skin'] . ':' . $sty_rec['style'];
2935 }
2936
2937 return $styles;
2938 }
2939
2943 public static function _getNumberOfUsersPerAuthMode(): array // Missing array type.
2944 {
2945 global $DIC;
2946
2947 $ilDB = $DIC['ilDB'];
2948
2949 $r = $ilDB->query('SELECT count(*) AS cnt, auth_mode FROM usr_data ' .
2950 'GROUP BY auth_mode');
2951 $cnt_arr = [];
2952 while ($cnt = $ilDB->fetchAssoc($r)) {
2953 $cnt_arr[$cnt['auth_mode']] = (int) $cnt['cnt'];
2954 }
2955
2956 return $cnt_arr;
2957 }
2958
2959 public static function _getLocalAccountsForEmail(string $a_email): array // Missing array type.
2960 {
2961 global $DIC;
2962
2963 $ilDB = $DIC['ilDB'];
2964 $ilSetting = $DIC['ilSetting'];
2965
2966 // default set to local (1)?
2967
2968 $q = 'SELECT * FROM usr_data WHERE ' .
2969 ' email = %s AND (auth_mode = %s ';
2970 $types = ['text', 'text'];
2971 $values = [$a_email, 'local'];
2972
2973 if ($ilSetting->get('auth_mode') == 1) {
2974 $q .= ' OR auth_mode = %s';
2975 $types[] = 'text';
2976 $values[] = 'default';
2977 }
2978
2979 $q .= ')';
2980
2981 $users = [];
2982 $usr_set = $ilDB->queryF($q, $types, $values);
2983 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
2984 $users[$usr_rec['usr_id']] = $usr_rec['login'];
2985 }
2986
2987 return $users;
2988 }
2989
2990 public static function _moveUsersToStyle(
2991 string $a_from_skin,
2992 string $a_from_style,
2993 string $a_to_skin,
2994 string $a_to_style
2995 ): void {
2996 global $DIC;
2997 $ilDB = $DIC['ilDB'];
2998
2999 $q = 'SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ' .
3000 ' WHERE up1.keyword= ' . $ilDB->quote('style', 'text') .
3001 ' AND up1.value= ' . $ilDB->quote($a_from_style, 'text') .
3002 ' AND up2.keyword= ' . $ilDB->quote('skin', 'text') .
3003 ' AND up2.value= ' . $ilDB->quote($a_from_skin, 'text') .
3004 ' AND up1.usr_id = up2.usr_id ';
3005
3006 $usr_set = $ilDB->query($q);
3007
3008 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3009 $ilDB->replace(
3010 'usr_pref',
3011 [
3012 'usr_id' => [ilDBConstants::T_INTEGER, $usr_rec['usr_id']],
3013 'keyword' => [ilDBConstants::T_TEXT, 'skin'],
3014 ],
3015 [
3016 'value' => [ilDBConstants::T_TEXT, $a_to_skin]
3017 ]
3018 );
3019 $ilDB->replace(
3020 'usr_pref',
3021 [
3022 'usr_id' => [ilDBConstants::T_INTEGER, $usr_rec['usr_id']],
3023 'keyword' => [ilDBConstants::T_TEXT, 'style'],
3024 ],
3025 [
3026 'value' => [ilDBConstants::T_TEXT, $a_to_style]
3027 ]
3028 );
3029 }
3030 }
3031
3032 public static function _getUsersForClipboadObject(
3033 string $a_type,
3034 int $a_id
3035 ): array {
3036 global $DIC;
3037 $ilDB = $DIC['ilDB'];
3038
3039 $q = 'SELECT DISTINCT user_id FROM personal_clipboard WHERE ' .
3040 'item_id = ' . $ilDB->quote($a_id, 'integer') . ' AND ' .
3041 'type = ' . $ilDB->quote($a_type, 'text');
3042 $user_set = $ilDB->query($q);
3043 $users = [];
3044 while ($user_rec = $ilDB->fetchAssoc($user_set)) {
3045 $users[] = (int) $user_rec['user_id'];
3046 }
3047
3048 return $users;
3049 }
3050
3051 public static function _getImportedUserId(
3052 string $i2_id
3053 ): int {
3054 global $DIC;
3055 $ilDB = $DIC['ilDB'];
3056
3057 $query = 'SELECT obj_id FROM object_data WHERE import_id = ' .
3058 $ilDB->quote($i2_id, 'text');
3059
3060 $res = $ilDB->query($query);
3061 $id = 0;
3062 while ($row = $ilDB->fetchObject($res)) {
3063 $id = (int) $row->obj_id;
3064 }
3065 return $id;
3066 }
3067
3068 public static function lookupOrgUnitsRepresentation(
3069 int $a_usr_id
3070 ): string {
3071 return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3072 }
3073
3074 public static function _getAvatar(int $a_usr_id): Avatar
3075 {
3076 $define = new ilUserAvatarResolver($a_usr_id ?: ANONYMOUS_USER_ID);
3077 $define->setSize('xsmall');
3078 return $define->getAvatar();
3079 }
3080
3081 public static function _getPersonalPicturePath(
3082 int $usr_id,
3083 string $size = 'small',
3084 bool $force_pic = false
3085 ): string {
3086 $define = new ilUserAvatarResolver($usr_id);
3087 $define->setForcePicture($force_pic);
3088 $define->setSize($size);
3089 return $define->getLegacyPictureURL();
3090 }
3091
3092 public static function copyProfilePicturesToDirectory(
3093 int $a_user_id,
3094 string $a_dir
3095 ): void {
3096 global $DIC;
3097 $irss = $DIC->resourceStorage();
3098
3099 $clean_dir = trim(str_replace('..', '', $a_dir));
3100 if ($clean_dir == '' || !is_dir($clean_dir)) {
3101 return;
3102 }
3103 $avatar_rid = (new ilObjUser($a_user_id))->getAvatarRid();
3104 if ($avatar_rid === null) {
3105 return;
3106 }
3107
3108 file_put_contents(
3109 $clean_dir . '/usr_' . $a_user_id . '.jpg',
3110 $irss->consume()->stream($avatar_rid)->getStream()->getContents()
3111 );
3112 }
3113
3114 public static function _lookupFeedHash(
3115 int $a_user_id,
3116 bool $a_create = false
3117 ): ?string {
3118 global $DIC;
3119 $ilDB = $DIC['ilDB'];
3120
3121 if ($a_user_id > 0) {
3122 $set = $ilDB->queryF(
3123 'SELECT feed_hash from usr_data WHERE usr_id = %s',
3124 ['integer'],
3125 [$a_user_id]
3126 );
3127 if ($rec = $ilDB->fetchAssoc($set)) {
3128 if (strlen($rec['feed_hash']) == 32) {
3129 return $rec['feed_hash'];
3130 } elseif ($a_create) {
3131 $hash = md5(random_int(1, 9999999) + str_replace(' ', '', microtime()));
3132 $ilDB->manipulateF(
3133 'UPDATE usr_data SET feed_hash = %s' .
3134 ' WHERE usr_id = %s',
3135 ['text', 'integer'],
3136 [$hash, $a_user_id]
3137 );
3138 return $hash;
3139 }
3140 }
3141 }
3142 return null;
3143 }
3144
3145 public static function _getFeedPass(
3146 int $a_user_id
3147 ): ?string {
3148 if ($a_user_id > 0) {
3149 return self::_lookupPref($a_user_id, 'priv_feed_pass');
3150 }
3151 return null;
3152 }
3153}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:27
Builds data types.
Definition: Factory.php:36
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
const IL_CAL_UNIX
const IL_CAL_DATETIME
const int AUTH_LOCAL
static _needsExternalAccountByAuthMode($a_auth_mode)
Check if chosen auth mode needs an external account entry.
static _getAuthMode(?string $a_auth_mode)
static _getAuthModeName($a_auth_key)
static deleteByUserId(int $a_user_id)
static _deleteSettingsOfUser(int $a_user)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
static resetToDefaults()
reset to defaults
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
static setLanguage(ilLanguage $a_lng)
@classDescription Date and time handling
static _deleteByUser(int $a_usr_id)
Base class for ILIAS Exception handling.
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
Import class.
addSkipImporter(string $a_component, bool $skip=true)
static _getInstance()
Get singleton instance of this class.
static getLogger(string $a_component_id)
Get component logger.
static lookupTitle(int $a_page_id)
static removeForUser(int $user_id)
Remove all notifications for given user.
static _deleteUser(int $a_usr_id)
static deleteUserPortfolios(int $a_user_id)
Delete all portfolio data for user.
static _removeTrackingDataForUser(int $user_id)
to be called from IlObjUser
static _deleteUser(int $a_usr_id)
User class.
static _lookupLanguage(int $a_usr_id)
DataFactory $data_factory
__construct(int $a_user_id=0, bool $a_call_by_reference=false)
setLastProfilePrompt(string $date)
static getUserIdsNeverLoggedIn(int $thresholdInDays)
updateLastVisited(array $last_visited)
static _isAnonymous(int $usr_id)
getClipboardObjects(string $a_type='', bool $a_top_nodes_only=false)
get all clipboard objects of user and specified type
setGender(string $gender_string)
getPersonalPicturePath(string $a_size='small', bool $a_force_pic=false)
assignSystemInformationFromDB(array $data)
string $last_login
static _getUsersOnline(int $a_user_id=0, bool $a_no_anonymous=false)
static _lookup(int $a_user_id, string $a_field)
StreamDelivery $delivery
setAvatarRid(?ResourceIdentification $avatar_rid)
getOfferingHelpAsText()
Get help offering as plain text.
setPhoneMobile(string $phone)
static lookupMatriculation(int $a_usr_id)
static getUserLoginsByEmail(string $a_email)
string $client_ip
setIsSelfRegistered(bool $status)
setPref(string $a_keyword, ?string $a_value)
setLongitude(?string $longitude)
setLanguage(string $language)
buildTextFromArray(array $a_attr)
deletePref(string $key)
const DATABASE_DATE_FORMAT
setAuthMode(?string $a_str)
addToPCClipboard(string $a_content, string $a_time, int $a_nr)
Add a page content item to PC clipboard (should go to another class)
getAuthMode(bool $a_auth_key=false)
setLogin(string $login)
setStreet(string $street)
static _getUsersForIds(array $a_mem_ids, int $active=-1, int $timelimitowner=-1)
setEmail(string $email)
setLastLogin(string $a_str)
setCity(string $city)
setFirstLogin(string $date)
static _getPersonalPicturePath(int $usr_id, string $size='small', bool $force_pic=false)
static userExists(array $a_usr_ids=[])
clipboardHasObjectsOfType(string $a_type)
Check whether clipboard has objects of a certain type.
array $last_visited
string $password_encoding_type
writeHistory(string $login)
setInactivationDate(?string $inactivation_date)
setTimeLimitUntil(?int $a_until)
static _lookupActive(int $a_usr_id)
prepareAndRetrievePasswordForStorage()
static _externalAccountExists(string $a_external_account, string $a_auth_mode)
setPasswordSalt(?string $password_salt)
setLastPasswordChangeTS(int $a_last_password_change_ts)
string $agree_date
bool $is_self_registered
setTimeLimitFrom(?int $a_from)
string $inactivation_date
getCurrentLanguage()
returns the current language (may differ from user's pref setting!)
setLatitude(?string $latitude)
static _getLoginAttempts(int $a_usr_id)
setPhoneHome(string $phone)
static _toggleActiveStatusOfUsers(array $a_usr_ids, bool $a_status)
setPasswordEncodingType(?string $password_encryption_type)
static _lookupFullname(int $a_user_id)
static _writeExternalAccount(int $a_usr_id, string $a_ext_id)
const PASSWD_CRYPTED
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
static _getLocalAccountsForEmail(string $a_email)
getProfileAsString(Language $language)
Get formatted mail body text of user profile data.
getFullname(int $max_strlen=0)
bool $time_limit_unlimited
bool $passwd_policy_reset
static _getUserData(array $a_internalids)
setHobby(string $hobby)
int $time_limit_from
int $last_password_change_ts
setFax(string $fax)
setPasswordPolicyResetStatus(bool $status)
string $first_login
static _getAllUserAssignedStyles()
updateLogin(string $login, Context $context)
setMatriculation(string $matriculation)
setComment(string $referral_comment)
setPasswd(string $a_str, string $a_type=ilObjUser::PASSWD_PLAIN)
string $ext_account
static getUserIdsByEmail(string $a_email)
static _lookupExternalAccount(int $a_user_id)
string $approve_date
ProfileConfigurationRepository $profile_configuration_repository
setActive(bool $active, int $owner=0)
set user active state and updates system fields appropriately
static _lookupFirstLogin(int $a_user_id)
string $passwd_type
static _getNumberOfUsersPerAuthMode()
get number of users per auth mode
static _lookupAuthMode(int $a_usr_id)
getPasswordPolicyResetStatus()
setSecondEmail(?string $email)
setZipcode(string $zipcode)
setTimeLimitOwner(int $a_owner)
setLastname(string $lastname)
array $user_settings
static findInterests(string $a_term, ?int $a_user_id=null, ?string $a_field_id=null)
Data $profile_data
setLookingForHelp(?array $value=null)
setCountry(string $country)
const PASSWD_PLAIN
static _getUsersForClipboadObject(string $a_type, int $a_id)
ilSetting $ilias_settings
int $time_limit_until
static _incrementLoginAttempts(int $a_usr_id)
static _lookupName(int $a_user_id)
setBirthday(?string $birthday)
withProfileData(Data $profile_data)
static _lookupId(string|array $a_user_str)
string $password_salt
static _lookupFeedHash(int $a_user_id, bool $a_create=false)
retrieveAgreeDateForStorage()
setLocationZoom(?int $zoom)
static _getUsersForFolder(int $ref_id, int $active)
Services $irss
static _moveUsersToStyle(string $a_from_skin, string $a_from_style, string $a_to_skin, string $a_to_style)
int $time_limit_owner
removeObjectFromClipboard(int $a_item_id, string $a_type)
writePref(string $key, string $value)
setDepartment(string $department)
getPref(string $keyword)
static getProfileStatusOfUsers(array $a_user_ids)
static _lookupPref(int $a_usr_id, string $a_keyword)
clipboardDeleteObjectsOfType(string $a_type)
static _getImportedUserId(string $i2_id)
setPhoneOffice(string $phone)
buildSystemInformationArrayForDB()
static _lookupLastLogin(int $a_user_id)
string $passwd
ilAuthSession $auth_session
setGeneralInterests(?array $value=null)
setProfileIncomplete(bool $a_prof_inc)
setLastUpdate(string $date)
setExternalAccount(string $a_str)
static hasActiveSession(int $a_user_id, string $a_session_id)
addObjectToClipboard(int $a_item_id, string $a_type, string $a_title, int $a_parent=0, string $a_time='', int $a_order_nr=0)
add an item to user's personal clipboard
static _getUsersForGroup(array $a_mem_ids, int $active=-1)
static _lookupFields(int $a_user_id)
setAgreeDate(?string $date)
string $last_profile_prompt
static _getExternalAccountsByAuthMode(string $a_auth_mode, bool $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
setTimeLimitUnlimited(bool $unlimited)
static getUserIdByLogin(string $a_login)
static _getFeedPass(int $a_user_id)
static _lookupClientIP(int $a_user_id)
static _lookupLogin(int $a_user_id)
string $fullname
string $auth_mode
bool $profile_incomplete
resetPassword(string $new_raw_password)
setLastPasswordChangeToNow()
setLoginAttempts(int $a_login_attempts)
static _writeAuthMode(int $a_usr_id, string $a_auth_mode)
static _lookupGender(int $a_user_id)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
static _getUsersForRole(int $role_id, int $active=-1)
static _loginExists(string $a_login, int $a_user_id=0)
static lookupOrgUnitsRepresentation(int $a_usr_id)
getGeneralInterestsAsText()
Get general interests as plain text.
setFeedPass(string $a_password)
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
static _doesLoginnameExistInHistory(string $a_login)
static _setUserInactive(int $a_usr_id)
setOfferingHelp(?array $value=null)
getClipboardChilds(int $a_parent, string $a_insert_time)
Get children of an item.
uploadPersonalPicture(string $tmp_file)
static getUserSubsetByPreferenceValue(array $a_user_ids, string $a_keyword, string $a_val)
setClientIP(string $a_str)
setInstitution(string $instituion)
static getUserIdsByInactivityPeriod(int $periodInDays)
setFirstname(string $firstname)
static _readUsersProfileData(array $a_user_ids)
setCurrentLanguage(string $language)
Set current language.
static array $personal_image_cache
static getFirstLettersOfLastnames(?array $user_ids=null)
SettingsDataRepository $settings_data_repository
setUTitle(string $user_title)
This sets the USER's title NOT the OBJECT's title!
importPersonalData(array $a_file, bool $a_profile_data, bool $a_settings, bool $a_notes, bool $a_calendar)
static _getAvatar(int $a_usr_id)
static copyProfilePicturesToDirectory(int $a_user_id, string $a_dir)
ProfileDataRepository $profile_data_repository
setApproveDate(?string $a_str)
set date the user account was activated null indicates that the user has not yet been activated
ilCronDeleteInactiveUserReminderMail $cron_delete_user_reminder_mail
static _lookupEmail(int $a_user_id)
static _getUserIdsByInactivationPeriod(int $period)
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
string $create_date
updateOwner()
update owner of object in db
setId(int $id)
string $last_update
static _lookupTitle(int $obj_id)
Class ilOrgUnitPathStorage.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static _removeTrackingDataForUser(int $user_id)
static _getInstance()
Get instance of ilSecuritySettings.
static _destroyByUserId(int $a_user_id)
Destroy session.
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
ILIAS Setting Class.
static skinExists(string $skin_id, ?ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
static styleExists(string $style_id)
static styleExistsForSkinId(string $skin_id, string $style_id)
Class ilUserAvatarResolver.
setForcePicture(bool $force_image)
There are places where we want wo show the Profile Picture of a User, even if the user doesn't want t...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static now()
Return current timestamp in Y-m-d H:i:s format.
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const USER_FOLDER_ID
Definition: constants.php:33
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const IL_INST_ID
Definition: constants.php:40
const ANONYMOUS_USER_ID
Definition: constants.php:27
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadLanguageModule(string $a_module)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
This describes how a letter or a picture avatar could be modified during construction of UI.
Definition: Avatar.php:29
$ref_id
Definition: ltiauth.php:66
$log
Definition: ltiresult.php:34
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilObjForumAdministration.
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23
$GLOBALS["DIC"]
Definition: wac.php:54
$context
Definition: webdav.php:31