ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
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 return;
1064 }
1065
1066 $this->active = 0;
1067 $this->setApproveDate(null);
1068
1069 if ($this->getId() > 0 && $current_active !== $active) {
1070 $this->setInactivationDate(ilUtil::now());
1071 }
1072 }
1073
1074 public function getActive(): bool
1075 {
1076 return $this->active === 1;
1077 }
1078
1079 public function getSkin(): string
1080 {
1081 return $this->user_settings['skin'];
1082 }
1083
1084 public function setTimeLimitOwner(int $a_owner): void
1085 {
1086 $this->time_limit_owner = $a_owner;
1087 }
1088
1089 public function getTimeLimitOwner(): int
1090 {
1091 return $this->time_limit_owner;
1092 }
1093
1094 public function setTimeLimitFrom(?int $a_from): void
1095 {
1096 $this->time_limit_from = $a_from;
1097 }
1098
1099 public function getTimeLimitFrom(): ?int
1100 {
1101 return $this->time_limit_from;
1102 }
1103
1104 public function setTimeLimitUntil(?int $a_until): void
1105 {
1106 $this->time_limit_until = $a_until;
1107 }
1108
1109 public function getTimeLimitUntil(): ?int
1110 {
1111 return $this->time_limit_until;
1112 }
1113
1114 public function setTimeLimitUnlimited(bool $unlimited): void
1115 {
1116 $this->time_limit_unlimited = $unlimited;
1117 }
1118
1119 public function getTimeLimitUnlimited(): bool
1120 {
1121 return $this->time_limit_unlimited;
1122 }
1123
1124 public function setLoginAttempts(int $a_login_attempts): void
1125 {
1126 $this->login_attempts = $a_login_attempts;
1127 }
1128
1129 public function getLoginAttempts(): int
1130 {
1131 return $this->login_attempts;
1132 }
1133
1134 public function checkTimeLimit(): bool
1135 {
1136 if ($this->getTimeLimitUnlimited()) {
1137 return true;
1138 }
1139 if ($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time()) {
1140 return true;
1141 }
1142 return false;
1143 }
1144
1145 public function setProfileIncomplete(bool $a_prof_inc): void
1146 {
1147 $this->profile_incomplete = $a_prof_inc;
1148 }
1149
1150 public function getProfileIncomplete(): bool
1151 {
1152 if ($this->id == ANONYMOUS_USER_ID) {
1153 return false;
1154 }
1155 return $this->profile_incomplete;
1156 }
1157
1158 public function isPasswordChangeDemanded(): bool
1159 {
1160 if ($this->id === ANONYMOUS_USER_ID) {
1161 return false;
1162 }
1163
1164 if ($this->id === SYSTEM_USER_ID) {
1165 if (LocalUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI='))
1166 && !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))
1167 ) {
1168 return true;
1169 }
1170 return false;
1171 }
1172
1173 return !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))
1174 && ($this->getPasswordPolicyResetStatus()
1175 || ilSecuritySettings::_getInstance()->isPasswordChangeOnFirstLoginEnabled()
1176 && $this->getLastPasswordChangeTS() === 0
1177 && $this->is_self_registered === false);
1178 }
1179
1180 public function isPasswordExpired(): bool
1181 {
1182 if ($this->id === ANONYMOUS_USER_ID
1183 || $this->getLastPasswordChangeTS() === 0) {
1184 return false;
1185 }
1186
1187 $max_pass_age_in_seconds = ilSecuritySettings::_getInstance()->getPasswordMaxAge() * 86400;
1188 if ($max_pass_age_in_seconds === 0) {
1189 return false;
1190 }
1191
1192 if (time() - $this->getLastPasswordChangeTS() > $max_pass_age_in_seconds
1193 && !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true))) {
1194 return true;
1195 }
1196
1197 return false;
1198 }
1199
1200 public function getPasswordAgeInDays(): int
1201 {
1202 return (int) floor((time() - $this->getLastPasswordChangeTS()) / 86400);
1203 }
1204
1205 public function setLastPasswordChangeToNow(): void
1206 {
1207 $this->last_password_change_ts = time();
1208 }
1209
1210 public function resetLastPasswordChange(): void
1211 {
1212 $this->last_password_change_ts = 0;
1213 }
1214
1215 public function setAuthMode(?string $a_str): void
1216 {
1217 $this->auth_mode = $a_str;
1218 }
1219
1220 public function getAuthMode(bool $a_auth_key = false): ?string
1221 {
1222 if (!$a_auth_key) {
1223 return $this->auth_mode;
1224 }
1225 return ilAuthUtils::_getAuthMode($this->auth_mode);
1226 }
1227
1228 public function setExternalAccount(string $a_str): void
1229 {
1230 $this->ext_account = $a_str;
1231 }
1232
1233 public function getExternalAccount(): string
1234 {
1235 return $this->ext_account;
1236 }
1237
1244 public function addObjectToClipboard(
1245 int $a_item_id,
1246 string $a_type,
1247 string $a_title,
1248 int $a_parent = 0,
1249 string $a_time = '',
1250 int $a_order_nr = 0
1251 ): void {
1252 global $DIC;
1253
1254 $ilDB = $DIC['ilDB'];
1255
1256 if ($a_time === '') {
1257 $a_time = date('Y-m-d H:i:s');
1258 }
1259
1260 $item_set = $ilDB->queryF(
1261 'SELECT * FROM personal_clipboard WHERE ' .
1262 'parent = %s AND item_id = %s AND type = %s AND user_id = %s',
1263 ['integer', 'integer', 'text', 'integer'],
1264 [0, $a_item_id, $a_type, $this->getId()]
1265 );
1266
1267 // only insert if item is not already in clipboard
1268 if (!$item_set->fetchRow()) {
1269 $ilDB->manipulateF(
1270 'INSERT INTO personal_clipboard ' .
1271 '(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ' .
1272 ' (%s,%s,%s,%s,%s,%s,%s)',
1273 ['integer', 'text', 'integer', 'text', 'integer', 'timestamp', 'integer'],
1274 [$a_item_id, $a_type, $this->getId(), $a_title, $a_parent, $a_time, $a_order_nr]
1275 );
1276 } else {
1277 $ilDB->manipulateF(
1278 'UPDATE personal_clipboard SET insert_time = %s ' .
1279 'WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0',
1280 ['timestamp', 'integer', 'integer', 'text'],
1281 [$a_time, $this->getId(), $a_item_id, $a_type]
1282 );
1283 }
1284 }
1285
1290 public function addToPCClipboard(
1291 string $a_content,
1292 string $a_time,
1293 int $a_nr
1294 ): void {
1295 $ilDB = $this->db;
1296 if ($a_time == 0) {
1297 $a_time = date('Y-m-d H:i:s');
1298 }
1299 ilSession::set('user_pc_clip', true);
1300 $ilDB->insert('personal_pc_clipboard', [
1301 'user_id' => ['integer', $this->getId()],
1302 'content' => ['clob', $a_content],
1303 'insert_time' => ['timestamp', $a_time],
1304 'order_nr' => ['integer', $a_nr]
1305 ]);
1306 }
1307
1312 public function getPCClipboardContent(): array // Missing array type.
1313 {
1314 $ilDB = $this->db;
1315
1316 if (!ilSession::get('user_pc_clip')) {
1317 return [];
1318 }
1319
1320 $set = $ilDB->queryF('SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ' .
1321 ' WHERE user_id = %s', ['integer'], [$this->getId()]);
1322 $row = $ilDB->fetchAssoc($set);
1323
1324 $set = $ilDB->queryF(
1325 'SELECT * FROM personal_pc_clipboard ' .
1326 ' WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC',
1327 ['integer', 'timestamp'],
1328 [$this->getId(), $row['mtime']]
1329 );
1330 $content = [];
1331 while ($row = $ilDB->fetchAssoc($set)) {
1332 $content[] = $row['content'];
1333 }
1334
1335 return $content;
1336 }
1337
1341 public function clipboardHasObjectsOfType(string $a_type): bool
1342 {
1343 global $DIC;
1344
1345 $ilDB = $DIC['ilDB'];
1346
1347 $set = $ilDB->queryF(
1348 'SELECT * FROM personal_clipboard WHERE ' .
1349 'parent = %s AND type = %s AND user_id = %s',
1350 ['integer', 'text', 'integer'],
1351 [0, $a_type, $this->getId()]
1352 );
1353 if ($ilDB->fetchAssoc($set)) {
1354 return true;
1355 }
1356
1357 return false;
1358 }
1359
1360 public function clipboardDeleteObjectsOfType(string $a_type): void
1361 {
1362 $ilDB = $this->db;
1363
1364 $ilDB->manipulateF(
1365 'DELETE FROM personal_clipboard WHERE ' .
1366 'type = %s AND user_id = %s',
1367 ['text', 'integer'],
1368 [$a_type, $this->getId()]
1369 );
1370 }
1371
1372 public function clipboardDeleteAll(): void
1373 {
1374 global $DIC;
1375
1376 $ilDB = $DIC['ilDB'];
1377
1378 $ilDB->manipulateF('DELETE FROM personal_clipboard WHERE ' .
1379 'user_id = %s', ['integer'], [$this->getId()]);
1380 }
1381
1385 public function getClipboardObjects(
1386 string $a_type = '',
1387 bool $a_top_nodes_only = false
1388 ): array {
1389 global $DIC;
1390
1391 $ilDB = $DIC['ilDB'];
1392
1393 $par = '';
1394 if ($a_top_nodes_only) {
1395 $par = ' AND parent = ' . $ilDB->quote(0, 'integer') . ' ';
1396 }
1397
1398 $type_str = ($a_type != '')
1399 ? ' AND type = ' . $ilDB->quote($a_type, 'text') . ' '
1400 : '';
1401 $q = 'SELECT * FROM personal_clipboard WHERE ' .
1402 'user_id = ' . $ilDB->quote($this->getId(), 'integer') . ' ' .
1403 $type_str . $par .
1404 ' ORDER BY order_nr';
1405 $objs = $ilDB->query($q);
1406 $objects = [];
1407 while ($obj = $ilDB->fetchAssoc($objs)) {
1408 if ($obj['type'] == 'mob') {
1409 $obj['title'] = ilObject::_lookupTitle($obj['item_id']);
1410 if (ilObject::_lookupType((int) $obj['item_id']) !== 'mob') {
1411 continue;
1412 }
1413 }
1414 if ($obj['type'] == 'incl') {
1415 $obj['title'] = ilMediaPoolPage::lookupTitle($obj['item_id']);
1416 if (!ilPageObject::_exists('mep', (int) $obj['item_id'], '-')) {
1417 continue;
1418 }
1419 }
1420 $objects[] = ['id' => $obj['item_id'],
1421 'type' => $obj['type'], 'title' => $obj['title'],
1422 'insert_time' => $obj['insert_time']];
1423 }
1424 return $objects;
1425 }
1426
1430 public function getClipboardChilds(
1431 int $a_parent,
1432 string $a_insert_time
1433 ): array {
1434 global $DIC;
1435
1436 $ilDB = $DIC['ilDB'];
1437 $ilUser = $DIC['ilUser'];
1438
1439 $objs = $ilDB->queryF(
1440 'SELECT * FROM personal_clipboard WHERE ' .
1441 'user_id = %s AND parent = %s AND insert_time = %s ' .
1442 ' ORDER BY order_nr',
1443 ['integer', 'integer', 'timestamp'],
1444 [$ilUser->getId(), $a_parent, $a_insert_time]
1445 );
1446 $objects = [];
1447 while ($obj = $ilDB->fetchAssoc($objs)) {
1448 if ($obj['type'] == 'mob') {
1449 $obj['title'] = ilObject::_lookupTitle($obj['item_id']);
1450 }
1451 $objects[] = ['id' => $obj['item_id'],
1452 'type' => $obj['type'], 'title' => $obj['title'], 'insert_time' => $obj['insert_time']];
1453 }
1454 return $objects;
1455 }
1456
1458 int $a_item_id,
1459 string $a_type
1460 ): void {
1461 $ilDB = $this->db;
1462
1463 $q = 'DELETE FROM personal_clipboard WHERE ' .
1464 'item_id = ' . $ilDB->quote($a_item_id, 'integer') .
1465 ' AND type = ' . $ilDB->quote($a_type, 'text') . ' ' .
1466 ' AND user_id = ' . $ilDB->quote($this->getId(), 'integer');
1467 $ilDB->manipulate($q);
1468 }
1469
1470 public function getOrgUnitsRepresentation(): string
1471 {
1472 return self::lookupOrgUnitsRepresentation($this->getId());
1473 }
1474
1479 public function getPersonalPicturePath(
1480 string $a_size = 'small',
1481 bool $a_force_pic = false
1482 ): string {
1483 if (isset(self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic])) {
1484 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
1485 }
1486
1487 self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic] = self::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
1488
1489 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
1490 }
1491
1492 public function hasProfilePicture(): bool
1493 {
1494 return (new ilUserAvatarResolver($this->getId()))->hasProfilePicture();
1495 }
1496
1497 public function getAvatar(): Avatar
1498 {
1499 return self::_getAvatar($this->getId());
1500 }
1501
1502 public function removeUserPicture(): void
1503 {
1504 if ($this->getAvatarRid() !== null) {
1505 $this->irss->manage()->remove($this->getAvatarRid(), new ilUserProfilePictureStakeholder());
1506 }
1507
1508 $this->profile_data = $this->profile_data->withAvatarRid(null);
1509 $this->update();
1510 }
1511
1516 public function getProfileAsString(Language $language): string
1517 {
1518 global $DIC;
1519 $rbacreview = $DIC['rbacreview'];
1520 $profile = $DIC['user']->getProfile();
1521
1522 $language->loadLanguageModule('registration');
1523 $language->loadLanguageModule('crs');
1524
1525 $body = "{$language->txt('login')}: {$this->getLogin()}\n";
1526
1527 if ($this->profile_data->getTitle() !== '') {
1528 $body .= "{$language->txt('title')}: {$this->profile_data->getTitle()}\n";
1529 }
1530 if ($this->getGender() !== '') {
1531 $body .= ($language->txt('gender') . ': ' . $language->txt('gender_' . strtolower($this->getGender())) . "\n");
1532 }
1533 if ($this->getFirstname() !== '') {
1534 $body .= ($language->txt('firstname') . ': ' . $this->getFirstname() . "\n");
1535 }
1536 if ($this->getLastname() !== '') {
1537 $body .= ($language->txt('lastname') . ': ' . $this->getLastname() . "\n");
1538 }
1539 if ($this->getInstitution() !== '') {
1540 $body .= ($language->txt('institution') . ': ' . $this->getInstitution() . "\n");
1541 }
1542 if ($this->getDepartment() !== '') {
1543 $body .= ($language->txt('department') . ': ' . $this->getDepartment() . "\n");
1544 }
1545 if ($this->getStreet() !== '') {
1546 $body .= ($language->txt('street') . ': ' . $this->getStreet() . "\n");
1547 }
1548 if ($this->getCity() !== '') {
1549 $body .= ($language->txt('city') . ': ' . $this->getCity() . "\n");
1550 }
1551 if ($this->getZipcode() !== '') {
1552 $body .= ($language->txt('zipcode') . ': ' . $this->getZipcode() . "\n");
1553 }
1554 if ($this->getCountry() !== '') {
1555 $body .= ($language->txt('country') . ': ' . $this->getCountry() . "\n");
1556 }
1557 if ($this->getPhoneOffice() !== '') {
1558 $body .= ($language->txt('phone_office') . ': ' . $this->getPhoneOffice() . "\n");
1559 }
1560 if ($this->getPhoneHome() !== '') {
1561 $body .= ($language->txt('phone_home') . ': ' . $this->getPhoneHome() . "\n");
1562 }
1563 if ($this->getPhoneMobile() !== '') {
1564 $body .= ($language->txt('phone_mobile') . ': ' . $this->getPhoneMobile() . "\n");
1565 }
1566 if ($this->getFax() !== '') {
1567 $body .= ($language->txt('fax') . ': ' . $this->getFax() . "\n");
1568 }
1569 if ($this->getEmail() !== '') {
1570 $body .= ($language->txt('email') . ': ' . $this->getEmail() . "\n");
1571 }
1572 if ($this->getSecondEmail() !== null
1573 && $this->getSecondEmail() !== '') {
1574 $body .= ($language->txt('second_email') . ': ' . $this->getSecondEmail() . "\n");
1575 }
1576 if ($this->getHobby() !== '') {
1577 $body .= ($language->txt('hobby') . ': ' . $this->getHobby() . "\n");
1578 }
1579 if ($this->getComment() !== '') {
1580 $body .= ($language->txt('referral_comment') . ': ' . $this->getComment() . "\n");
1581 }
1582 if ($this->getMatriculation() !== '') {
1583 $body .= ($language->txt('matriculation') . ': ' . $this->getMatriculation() . "\n");
1584 }
1585 if ($this->getCreateDate() !== '') {
1588 $date = ilDatePresentation::formatDate(new ilDateTime($this->getCreateDate(), IL_CAL_DATETIME));
1590
1591 $body .= ($language->txt('create_date') . ': ' . $date . "\n");
1592 }
1593
1594 $gr = [];
1595 foreach ($rbacreview->getGlobalRoles() as $role) {
1596 if ($rbacreview->isAssigned($this->getId(), $role)) {
1597 $gr[] = ilObjRole::_lookupTitle($role);
1598 }
1599 }
1600 if (count($gr)) {
1601 $body .= ($language->txt('reg_role_info') . ': ' . implode(',', $gr) . "\n");
1602 }
1603
1604 // Time limit
1605 if ($this->getTimeLimitUnlimited()) {
1606 $body .= ($language->txt('time_limit') . ': ' . $language->txt('crs_unlimited') . "\n");
1607 } else {
1611 new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX),
1612 new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX)
1613 );
1615
1616 $start = new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX);
1617 $end = new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX);
1618
1619 $body .= $language->txt('time_limit') . ': ' .
1620 $language->txt('from') . ' ' .
1621 $start->get(IL_CAL_DATETIME) . ' ';
1622 $body .= $language->txt('to') . ' ' . $end->get(IL_CAL_DATETIME) . "\n";
1623 }
1624
1625 foreach ($profile->getAllUserDefinedFields() as $field) {
1626 $data = $field->retrieveValueFromUser($this);
1627 if ($data !== '') {
1628 $body .= "{$field->getLabel($this->lng)}: {$data}\n";
1629 }
1630 }
1631
1632 return $body;
1633 }
1634
1635 public function setFeedPass(
1636 string $a_password
1637 ): void {
1638 $this->writePref(
1639 'priv_feed_pass',
1640 ($a_password == '') ? '' : md5($a_password)
1641 );
1642 }
1643
1644 public function hasPublicProfile(): bool
1645 {
1646 return in_array($this->getPref('public_profile'), ['y', 'g']);
1647 }
1648
1649 public function getPublicName(): string
1650 {
1651 if ($this->hasPublicProfile()) {
1652 return $this->getFirstname() . ' ' . $this->getLastname() . ' (' . $this->getLogin() . ')';
1653 }
1654
1655 return $this->getLogin();
1656 }
1657
1658 public function resetOwner(): void
1659 {
1660 $ilDB = $this->db;
1661
1662 $query = 'UPDATE object_data SET owner = 0 ' .
1663 'WHERE owner = ' . $ilDB->quote($this->getId(), 'integer');
1664 $ilDB->query($query);
1665 }
1666
1667
1668 public function exportPersonalData(): void
1669 {
1670 if (!isset($this->user)) {
1671 global $DIC;
1672 $this->user = $DIC->user();
1673 }
1674 $export_consumer = (new ExportFactory())->consumer()->handler();
1675 $configs = $export_consumer->exportConfig()->allExportConfigs();
1677 $config = $configs->getElementByClassName('ilUserExportConfig');
1678 $config->setExportType('personal_data');
1679 $export = $export_consumer->createStandardExportByObject(
1680 $this->user->getId(),
1681 $this,
1682 $configs
1683 );
1684 $stream = Streams::ofString($export->getIRSSInfo()->getStream()->getContents());
1685 $file_name = $export->getIRSSInfo()->getFileName();
1686 $export->getIRSS()->delete($export_consumer->exportStakeholderHandler());
1687 $this->delivery->deliver($stream, $file_name);
1688 }
1689
1690 public function getPersonalDataExportFile(): string
1691 {
1692 $dir = ilExport::_getExportDirectory($this->getId(), 'xml', 'usr', 'personal_data');
1693 if (!is_dir($dir)) {
1694 return '';
1695 }
1696 foreach (ilFileUtils::getDir($dir) as $entry) {
1697 if (is_int(strpos($entry['entry'], '.zip'))) {
1698 return $entry['entry'];
1699 }
1700 }
1701
1702 return '';
1703 }
1704
1705 public function sendPersonalDataFile(): void
1706 {
1707 $file = ilExport::_getExportDirectory($this->getId(), 'xml', 'usr', 'personal_data') .
1708 '/' . $this->getPersonalDataExportFile();
1709 if (is_file($file)) {
1710 ilFileDelivery::deliverFileLegacy($file, $this->getPersonalDataExportFile());
1711 }
1712 }
1713
1714 public function importPersonalData(
1715 array $a_file,
1716 bool $a_profile_data,
1717 bool $a_settings,
1718 bool $a_notes,
1719 bool $a_calendar
1720 ): void {
1721 $imp = new ilImport();
1722 // bookmarks need to be skipped, importer does not exist anymore
1723 $imp->addSkipImporter('components/ILIAS/Bookmarks');
1724 if (!$a_profile_data) {
1725 $imp->addSkipEntity('components/ILIAS/User', 'usr_profile');
1726 }
1727 if (!$a_settings) {
1728 $imp->addSkipEntity('components/ILIAS/User', 'usr_setting');
1729 }
1730 if (!$a_notes) {
1731 $imp->addSkipEntity('components/ILIAS/Notes', 'user_notes');
1732 }
1733 if (!$a_calendar) {
1734 $imp->addSkipEntity('components/ILIAS/Calendar', 'calendar');
1735 }
1736 $imp->importEntity(
1737 $a_file['tmp_name'],
1738 $a_file['name'],
1739 'usr',
1740 'components/ILIAS/User'
1741 );
1742 }
1743
1744 public function setInactivationDate(?string $inactivation_date): void
1745 {
1746 $this->inactivation_date = $inactivation_date;
1747 }
1748
1749 public function getInactivationDate(): ?string
1750 {
1751 return $this->inactivation_date;
1752 }
1753
1754 public function isAnonymous(): bool
1755 {
1756 return self::_isAnonymous($this->getId());
1757 }
1758
1759 public static function _isAnonymous(int $usr_id): bool
1760 {
1761 return $usr_id == ANONYMOUS_USER_ID;
1762 }
1763
1764 public function activateDeletionFlag(): void
1765 {
1766 $this->writePref('delete_flag', true);
1767 }
1768
1769 public function removeDeletionFlag(): void
1770 {
1771 $this->writePref('delete_flag', false);
1772 }
1773
1774 public function hasDeletionFlag(): bool
1775 {
1776 return (bool) $this->getPref('delete_flag');
1777 }
1778
1779 public function setIsSelfRegistered(bool $status): void
1780 {
1781 $this->is_self_registered = $status;
1782 }
1783
1784 public function isSelfRegistered(): bool
1785 {
1786 return $this->is_self_registered;
1787 }
1788
1792 public function setGeneralInterests(?array $value = null): void
1793 {
1794 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1795 $this->profile_configuration_repository->getByClass(Interests::class)->getIdentifier(),
1796 $value ?? []
1797 );
1798 }
1799
1803 public function getGeneralInterests(): array
1804 {
1805 return $this->profile_data->getAdditionalFieldByIdentifier(
1806 $this->profile_configuration_repository->getByClass(Interests::class)->getIdentifier()
1807 ) ?? [];
1808 }
1809
1813 public function getGeneralInterestsAsText(): string
1814 {
1815 return $this->buildTextFromArray($this->getGeneralInterests());
1816 }
1817
1821 public function setOfferingHelp(?array $value = null): void
1822 {
1823 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1824 $this->profile_configuration_repository->getByClass(HelpOffered::class)->getIdentifier(),
1825 $value ?? []
1826 );
1827 }
1828
1832 public function getOfferingHelp(): array
1833 {
1834 return $this->profile_data->getAdditionalFieldByIdentifier(
1835 $this->profile_configuration_repository->getByClass(HelpOffered::class)->getIdentifier()
1836 ) ?? [];
1837 }
1838
1842 public function getOfferingHelpAsText(): string
1843 {
1844 return $this->buildTextFromArray($this->getOfferingHelp());
1845 }
1846
1847 public function setLookingForHelp(?array $value = null): void
1848 {
1849 $this->profile_data = $this->profile_data->withAdditionalFieldByIdentifier(
1850 $this->profile_configuration_repository->getByClass(HelpLookedFor::class)->getIdentifier(),
1851 $value ?? []
1852 );
1853 }
1854
1855 public function getLookingForHelp(): array
1856 {
1857 return $this->profile_data->getAdditionalFieldByIdentifier(
1858 $this->profile_configuration_repository->getByClass(HelpLookedFor::class)->getIdentifier()
1859 ) ?? [];
1860 }
1861
1862 public function getLookingForHelpAsText(): string
1863 {
1864 return $this->buildTextFromArray($this->getLookingForHelp());
1865 }
1866
1867
1868 public function uploadPersonalPicture(
1869 string $tmp_file
1870 ): void {
1871 $stakeholder = new ilUserProfilePictureStakeholder();
1872 $stakeholder->setOwner($this->getId());
1873 $stream = Streams::ofResource(fopen($tmp_file, 'rb'));
1874
1875 if ($this->getAvatarRid() !== null) {
1876 // append profile picture
1877 $this->irss->manage()->replaceWithStream(
1878 $this->getAvatarRid(),
1879 $stream,
1880 $stakeholder
1881 );
1882 } else {
1883 // new profile picture
1884 $rid = $this->irss->manage()->stream(
1885 $stream,
1886 $stakeholder
1887 );
1888 }
1889
1890 $this->setAvatarRid($rid);
1891 $this->update();
1892 }
1893
1894 private function buildTextFromArray(array $a_attr): string
1895 {
1896 if (count($a_attr) > 0) {
1897 return implode(', ', $a_attr);
1898 }
1899 return '';
1900 }
1901
1902 /*
1903 * 2025-07-16, sw: Hic sunt dracones. Static methods that need to be gone!
1904 */
1905
1906 public static function _loginExists(
1907 string $a_login,
1908 int $a_user_id = 0
1909 ): ?int {
1910 global $DIC;
1911 $ilDB = $DIC['ilDB'];
1912
1913 $q = 'SELECT DISTINCT login, usr_id FROM usr_data ' .
1914 'WHERE login = %s';
1915 $types[] = 'text';
1916 $values[] = $a_login;
1917
1918 if ($a_user_id != 0) {
1919 $q .= ' AND usr_id != %s ';
1920 $types[] = 'integer';
1921 $values[] = $a_user_id;
1922 }
1923
1924 $r = $ilDB->queryF($q, $types, $values);
1925
1926 if (($row = $ilDB->fetchAssoc($r))) {
1927 return (int) $row['usr_id'];
1928 }
1929 return null;
1930 }
1931
1932 public static function _externalAccountExists(
1933 string $a_external_account,
1934 string $a_auth_mode
1935 ): bool {
1936 global $DIC;
1937 $ilDB = $DIC['ilDB'];
1938
1939 $res = $ilDB->queryF(
1940 'SELECT * FROM usr_data ' .
1941 'WHERE ext_account = %s AND auth_mode = %s',
1942 ['text', 'text'],
1943 [$a_external_account, $a_auth_mode]
1944 );
1945 return (bool) $ilDB->fetchAssoc($res);
1946 }
1947
1948 public static function _getUsersForRole(
1949 int $role_id,
1950 int $active = -1
1951 ): array {
1952 global $DIC;
1953 $ilDB = $DIC['ilDB'];
1954 $rbacreview = $DIC['rbacreview'];
1955
1956 $ids = $rbacreview->assignedUsers($role_id);
1957
1958 if (count($ids) == 0) {
1959 $ids = [-1];
1960 }
1961
1962 $query = 'SELECT usr_data.*, usr_pref.value AS language
1963 FROM usr_data
1964 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
1965 WHERE ' . $ilDB->in('usr_data.usr_id', $ids, false, 'integer');
1966 $values[] = 'language';
1967 $types[] = 'text';
1968
1969
1970 if (is_numeric($active) && $active > -1) {
1971 $query .= ' AND usr_data.active = %s';
1972 $values[] = $active;
1973 $types[] = 'integer';
1974 }
1975
1976 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
1977
1978 $r = $ilDB->queryF($query, $types, $values);
1979 $data = [];
1980 while ($row = $ilDB->fetchAssoc($r)) {
1981 $data[] = $row;
1982 }
1983 return $data;
1984 }
1985
1986 public static function _getUsersForFolder(
1987 int $ref_id,
1988 int $active
1989 ): array {
1990 global $DIC;
1991 $ilDB = $DIC['ilDB'];
1992
1993 $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';
1994 $types[] = 'text';
1995 $values[] = 'language';
1996
1997 if (is_numeric($active) && $active > -1) {
1998 $query .= ' AND usr_data.active = %s';
1999 $values[] = $active;
2000 $types[] = 'integer';
2001 }
2002
2003 if ($ref_id != USER_FOLDER_ID) {
2004 $query .= ' AND usr_data.time_limit_owner = %s';
2005 $values[] = $ref_id;
2006 $types[] = 'integer';
2007 }
2008
2009 $query .= ' AND usr_data.usr_id != %s ';
2010 $values[] = ANONYMOUS_USER_ID;
2011 $types[] = 'integer';
2012
2013 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2014
2015 $result = $ilDB->queryF($query, $types, $values);
2016 $data = [];
2017 while ($row = $ilDB->fetchAssoc($result)) {
2018 $data[] = $row;
2019 }
2020
2021 return $data;
2022 }
2023
2024 public static function _getUsersForGroup(
2025 array $a_mem_ids,
2026 int $active = -1
2027 ): array {
2028 return self::_getUsersForIds($a_mem_ids, $active);
2029 }
2030
2031 public static function _getUsersForIds(
2032 array $a_mem_ids,
2033 int $active = -1,
2034 int $timelimitowner = -1
2035 ): array {
2036 global $DIC;
2037 $ilDB = $DIC['ilDB'];
2038
2039 $query = 'SELECT usr_data.*, usr_pref.value AS language
2040 FROM usr_data
2041 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
2042 WHERE ' . $ilDB->in('usr_data.usr_id', $a_mem_ids, false, 'integer') . '
2043 AND usr_data.usr_id != %s';
2044 $values[] = 'language';
2045 $types[] = 'text';
2046 $values[] = ANONYMOUS_USER_ID;
2047 $types[] = 'integer';
2048
2049 if (is_numeric($active) && $active > -1) {
2050 $query .= ' AND active = %s';
2051 $values[] = $active;
2052 $types[] = 'integer';
2053 }
2054
2055 if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1) {
2056 $query .= ' AND usr_data.time_limit_owner = %s';
2057 $values[] = $timelimitowner;
2058 $types[] = 'integer';
2059 }
2060
2061 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2062
2063 $result = $ilDB->queryF($query, $types, $values);
2064 $mem_arr = [];
2065 while ($row = $ilDB->fetchAssoc($result)) {
2066 $mem_arr[] = $row;
2067 }
2068
2069 return $mem_arr;
2070 }
2071
2072 public static function _getUserData(array $a_internalids): array
2073 {
2074 global $DIC;
2075 $ilDB = $DIC['ilDB'];
2076
2077 $ids = [];
2078 if (is_array($a_internalids)) {
2079 foreach ($a_internalids as $internalid) {
2080 if (is_numeric($internalid)) {
2081 $ids[] = $internalid;
2082 } else {
2083 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
2084 if (is_numeric($parsedid) && $parsedid > 0) {
2085 $ids[] = $parsedid;
2086 }
2087 }
2088 }
2089 }
2090 if (count($ids) == 0) {
2091 $ids [] = -1;
2092 }
2093
2094 $query = 'SELECT usr_data.*, usr_pref.value AS language
2095 FROM usr_data
2096 LEFT JOIN usr_pref
2097 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
2098 WHERE ' . $ilDB->in('usr_data.usr_id', $ids, false, 'integer');
2099 $values[] = 'language';
2100 $types[] = 'text';
2101
2102 $query .= ' ORDER BY usr_data.lastname, usr_data.firstname ';
2103
2104 $data = [];
2105 $result = $ilDB->queryF($query, $types, $values);
2106 while ($row = $ilDB->fetchAssoc($result)) {
2107 $data[] = $row;
2108 }
2109 return $data;
2110 }
2111
2112 public static function getUserSubsetByPreferenceValue(
2113 array $a_user_ids,
2114 string $a_keyword,
2115 string $a_val
2116 ): array {
2117 global $DIC;
2118 $ilDB = $DIC['ilDB'];
2119
2120 $users = [];
2121 $set = $ilDB->query(
2122 'SELECT usr_id FROM usr_pref ' .
2123 ' WHERE keyword = ' . $ilDB->quote($a_keyword, 'text') .
2124 ' AND ' . $ilDB->in('usr_id', $a_user_ids, false, 'integer') .
2125 ' AND value = ' . $ilDB->quote($a_val, 'text')
2126 );
2127 while ($rec = $ilDB->fetchAssoc($set)) {
2128 $users[] = $rec['usr_id'];
2129 }
2130 return $users;
2131 }
2132
2133 public static function _getLoginAttempts(
2134 int $a_usr_id
2135 ): int {
2136 global $DIC;
2137 $ilDB = $DIC['ilDB'];
2138
2139 $query = 'SELECT login_attempts FROM usr_data WHERE usr_id = %s';
2140 $result = $ilDB->queryF($query, ['integer'], [$a_usr_id]);
2141 $record = $ilDB->fetchAssoc($result);
2142 return (int) ($record['login_attempts'] ?? 0);
2143 }
2144
2145 public static function _incrementLoginAttempts(
2146 int $a_usr_id
2147 ): bool {
2148 global $DIC;
2149 $ilDB = $DIC['ilDB'];
2150
2151 $query = 'UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s';
2152 $affected = $ilDB->manipulateF($query, ['integer'], [$a_usr_id]);
2153
2154 if ($affected) {
2155 return true;
2156 } else {
2157 return false;
2158 }
2159 }
2160
2161 public static function _setUserInactive(
2162 int $a_usr_id
2163 ): bool {
2164 global $DIC;
2165 $ilDB = $DIC['ilDB'];
2166
2167 $query = 'UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s';
2168 $affected = $ilDB->manipulateF($query, ['timestamp', 'integer'], [ilUtil::now(), $a_usr_id]);
2169
2170 if ($affected) {
2171 return true;
2172 } else {
2173 return false;
2174 }
2175 }
2176
2177 public static function _getUsersOnline(
2178 int $a_user_id = 0,
2179 bool $a_no_anonymous = false
2180 ): array {
2181 global $DIC;
2182 $ilDB = $DIC['ilDB'];
2183
2185
2186 $pd_set = new ilSetting('pd');
2187 $atime = $pd_set->get('user_activity_time') * 60;
2188 $ctime = time();
2189
2190 $where = [];
2191
2192 if ($a_user_id === 0) {
2193 $where[] = 'user_id > 0';
2194 } else {
2195 $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
2196 }
2197
2198 if ($a_no_anonymous) {
2199 $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
2200 }
2201
2202 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
2203 $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
2204 }
2205
2206 $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
2207 $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
2208
2209 $where = 'WHERE ' . implode(' AND ', $where);
2210
2211 $r = $ilDB->queryF(
2212 $q = "
2213 SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, context, agree_date
2214 FROM usr_session
2215 LEFT JOIN usr_data u
2216 ON user_id = u.usr_id
2217 LEFT JOIN usr_pref p
2218 ON (p.usr_id = u.usr_id AND p.keyword = %s)
2219 {$where}
2220 GROUP BY user_id, firstname, lastname, title, login, last_login, context, agree_date
2221 ORDER BY lastname, firstname
2222 ",
2223 ['text'],
2224 ['hide_own_online_status']
2225 );
2226
2227 $log->debug('Query: ' . $q);
2228
2229 $users = [];
2230 while ($user = $ilDB->fetchAssoc($r)) {
2231 if ($atime <= 0 || $user['ctime'] + $atime > $ctime) {
2232 $users[$user['user_id']] = $user;
2233 }
2234 }
2235
2236 $log->debug('Found users: ' . count($users));
2237
2238 $hide_users = $DIC['legalDocuments']->usersWithHiddenOnlineStatus(array_map(intval(...), array_column($users, 'user_id')));
2239 $users = array_filter(
2240 $users,
2241 fn($user) => !in_array((int) $user['user_id'], $hide_users, true)
2242 );
2243
2244 return $users;
2245 }
2246
2247 public static function getUserIdsByInactivityPeriod(
2248 int $periodInDays
2249 ): array {
2250 global $DIC;
2251 $ilDB = $DIC['ilDB'];
2252
2253 if ($periodInDays < 1) {
2254 throw new ilException('Invalid period given');
2255 }
2256
2257 $date = date('Y-m-d H:i:s', (time() - ($periodInDays * 24 * 60 * 60)));
2258
2259 $query = 'SELECT usr_id FROM usr_data WHERE last_login IS NOT NULL AND last_login < %s';
2260
2261 $ids = [];
2262
2263 $types = ['timestamp'];
2264 $values = [$date];
2265
2266 $res = $ilDB->queryF($query, $types, $values);
2267 while ($row = $ilDB->fetchAssoc($res)) {
2268 $ids[] = (int) $row['usr_id'];
2269 }
2270
2271 return $ids;
2272 }
2273
2274 public static function getUserIdsNeverLoggedIn(
2275 int $thresholdInDays
2276 ): array {
2277 global $DIC;
2278 $ilDB = $DIC['ilDB'];
2279
2280 $date = date('Y-m-d H:i:s', (time() - ($thresholdInDays * 24 * 60 * 60)));
2281
2282 $query = 'SELECT usr_id FROM usr_data WHERE last_login IS NULL AND create_date < %s';
2283
2284 $ids = [];
2285
2286 $types = ['timestamp'];
2287 $values = [$date];
2288
2289 $res = $ilDB->queryF($query, $types, $values);
2290 while ($row = $ilDB->fetchAssoc($res)) {
2291 $ids[] = (int) $row['usr_id'];
2292 }
2293
2294 return $ids;
2295 }
2296
2297 public static function _getUserIdsByInactivationPeriod(
2298 int $period
2299 ): array {
2300 if (!$period) {
2301 throw new ilException('no valid period given');
2302 }
2303
2304 global $DIC;
2305 $db = $DIC['ilDB'];
2306
2307 $res = $db->queryF(
2308 'SELECT usr_id FROM usr_data WHERE inactivation_date < %s AND active = %s',
2309 ['timestamp', 'integer'],
2310 [
2311 date('Y-m-d H:i:s', (time() - ($period * 24 * 60 * 60))),
2312 0
2313 ]
2314 );
2315
2316 $ids = [];
2317 while ($row = $db->fetchObject($res)) {
2318 $ids[] = (int) $row->usr_id;
2319 }
2320
2321 return $ids;
2322 }
2323
2324 public static function getFirstLettersOfLastnames(
2325 ?array $user_ids = null
2326 ): array {
2327 global $DIC;
2328 $ilDB = $DIC['ilDB'];
2329
2330 $q = 'SELECT DISTINCT ' . $ilDB->upper($ilDB->substr('lastname', 1, 1)) . ' let' .
2331 ' FROM usr_data' .
2332 ' WHERE usr_id <> ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer') .
2333 ($user_ids !== null ? ' AND ' . $ilDB->in('usr_id', $user_ids, false, 'integer') : '') .
2334 ' ORDER BY let';
2335 $let_set = $ilDB->query($q);
2336
2337 $let = [];
2338 while ($let_rec = $ilDB->fetchAssoc($let_set)) {
2339 $let[$let_rec['let']] = $let_rec['let'];
2340 }
2341 return $let;
2342 }
2343
2344 public static function userExists(
2345 array $a_usr_ids = []
2346 ): bool {
2347 global $DIC;
2348 $ilDB = $DIC['ilDB'];
2349
2350 $query = 'SELECT count(*) num FROM object_data od ' .
2351 'JOIN usr_data ud ON obj_id = usr_id ' .
2352 'WHERE ' . $ilDB->in('obj_id', $a_usr_ids, false, 'integer') . ' ';
2353 $res = $ilDB->query($query);
2354 $num_rows = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
2355 return $num_rows == count($a_usr_ids);
2356 }
2357
2358 public static function _doesLoginnameExistInHistory(string $a_login): bool
2359 {
2360 global $DIC;
2361 $ilDB = $DIC['ilDB'];
2362
2363 $res = $ilDB->queryF(
2364 '
2365 SELECT * FROM loginname_history
2366 WHERE login = %s',
2367 ['text'],
2368 [$a_login]
2369 );
2370
2371 return (bool) $ilDB->fetchAssoc($res);
2372 }
2373
2374 public static function _lookupPref(
2375 int $a_usr_id,
2376 string $a_keyword
2377 ): ?string {
2378 global $DIC;
2379 $ilDB = $DIC['ilDB'];
2380
2381 $query = 'SELECT * FROM usr_pref WHERE usr_id = ' . $ilDB->quote($a_usr_id, 'integer') . ' ' .
2382 'AND keyword = ' . $ilDB->quote($a_keyword, 'text');
2383 $res = $ilDB->query($query);
2384
2385 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2386 return $row->value;
2387 }
2388 return null;
2389 }
2390
2391 public static function lookupMatriculation(int $a_usr_id): string
2392 {
2393 global $DIC;
2394 $ilDB = $DIC['ilDB'];
2395
2396 $query = 'SELECT matriculation FROM usr_data ' .
2397 'WHERE usr_id = ' . $ilDB->quote($a_usr_id);
2398 $res = $ilDB->query($query);
2399 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
2400 return $row->matriculation ?: '';
2401 }
2402
2403 public static function findInterests(
2404 string $a_term,
2405 ?int $a_user_id = null,
2406 ?string $a_field_id = null
2407 ): array {
2408 global $DIC;
2409 $ilDB = $DIC['ilDB'];
2410
2411 $res = [];
2412
2413 $sql = 'SELECT DISTINCT(value)' .
2414 ' FROM usr_profile_data' .
2415 ' WHERE ' . $ilDB->like('value', 'text', '%' . $a_term . '%');
2416 if ($a_field_id) {
2417 $sql .= ' AND field_id = ' . $ilDB->quote($a_field_id, 'text');
2418 }
2419 if ($a_user_id) {
2420 $sql .= ' AND usr_id <> ' . $ilDB->quote($a_user_id, 'integer');
2421 }
2422 $sql .= ' ORDER BY value';
2423 $set = $ilDB->query($sql);
2424 while ($row = $ilDB->fetchAssoc($set)) {
2425 $res[] = $row['value'];
2426 }
2427
2428 return $res;
2429 }
2430
2431 public static function getProfileStatusOfUsers(
2432 array $a_user_ids
2433 ): array {
2434 global $DIC;
2435 $ilDB = $DIC->database();
2436
2437 $set = $ilDB->query(
2438 'SELECT * FROM usr_pref ' .
2439 ' WHERE keyword = ' . $ilDB->quote('public_profile', 'text') .
2440 ' AND ' . $ilDB->in('usr_id', $a_user_ids, false, 'integer')
2441 );
2442 $r = [
2443 'global' => [],
2444 'local' => [],
2445 'public' => [],
2446 'not_public' => []
2447 ];
2448 while ($rec = $ilDB->fetchAssoc($set)) {
2449 if ($rec['value'] == 'g') {
2450 $r['global'][] = $rec['usr_id'];
2451 $r['public'][] = $rec['usr_id'];
2452 }
2453 if ($rec['value'] == 'y') {
2454 $r['local'][] = $rec['usr_id'];
2455 $r['public'][] = $rec['usr_id'];
2456 }
2457 }
2458 foreach ($a_user_ids as $id) {
2459 if (!in_array($id, $r['public'])) {
2460 $r['not_public'][] = $id;
2461 }
2462 }
2463
2464 return $r;
2465 }
2466
2467 private static function _lookup(
2468 int $a_user_id,
2469 string $a_field
2470 ): ?string {
2471 global $DIC;
2472 $ilDB = $DIC['ilDB'];
2473
2474 $res = $ilDB->queryF(
2475 'SELECT ' . $a_field . ' FROM usr_data WHERE usr_id = %s',
2476 ['integer'],
2477 [$a_user_id]
2478 );
2479
2480 while ($set = $ilDB->fetchAssoc($res)) {
2481 return $set[$a_field];
2482 }
2483 return null;
2484 }
2485
2486 public static function _lookupFullname(int $a_user_id): string
2487 {
2488 global $DIC;
2489 $ilDB = $DIC['ilDB'];
2490
2491 $fullname = '';
2492
2493 $set = $ilDB->queryF(
2494 'SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s',
2495 ['integer'],
2496 [$a_user_id]
2497 );
2498
2499 if ($rec = $ilDB->fetchAssoc($set)) {
2500 if ($rec['title']) {
2501 $fullname = $rec['title'] . ' ';
2502 }
2503 if ($rec['firstname']) {
2504 $fullname .= $rec['firstname'] . ' ';
2505 }
2506 if ($rec['lastname']) {
2507 $fullname .= $rec['lastname'];
2508 }
2509 }
2510 return $fullname;
2511 }
2512
2513 public static function _lookupEmail(int $a_user_id): string
2514 {
2515 return self::_lookup($a_user_id, 'email') ?? '';
2516 }
2517
2518 public static function _lookupGender(int $a_user_id): string
2519 {
2520 return (string) self::_lookup($a_user_id, 'gender') ?? '';
2521 }
2522
2523 public static function _lookupClientIP(int $a_user_id): string
2524 {
2525 return self::_lookup($a_user_id, 'client_ip') ?? '';
2526 }
2527
2528 public static function _lookupName(int $a_user_id): array
2529 {
2530 global $DIC;
2531 $ilDB = $DIC['ilDB'];
2532
2533 $res = $ilDB->queryF(
2534 'SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s',
2535 ['integer'],
2536 [$a_user_id]
2537 );
2538 if (($user_rec = $ilDB->fetchAssoc($res))) {
2539 return ['user_id' => $a_user_id,
2540 'firstname' => $user_rec['firstname'],
2541 'lastname' => $user_rec['lastname'],
2542 'title' => $user_rec['title'],
2543 'login' => $user_rec['login']
2544 ];
2545 }
2546 return ['user_id' => 0,
2547 'firstname' => '',
2548 'lastname' => '',
2549 'title' => '',
2550 'login' => ''
2551 ];
2552 }
2553
2554 public static function _lookupLanguage(int $a_usr_id): string
2555 {
2556 global $DIC;
2557 $ilDB = $DIC['ilDB'];
2558 $lng = $DIC['lng'];
2559
2560 $q = 'SELECT value FROM usr_pref WHERE usr_id= ' .
2561 $ilDB->quote($a_usr_id, 'integer') . ' AND keyword = ' .
2562 $ilDB->quote('language', 'text');
2563 $r = $ilDB->query($q);
2564
2565 while ($row = $ilDB->fetchAssoc($r)) {
2566 return (string) $row['value'];
2567 }
2568 if (is_object($lng)) {
2569 return $lng->getDefaultLanguage();
2570 }
2571 return 'en';
2572 }
2573
2574 public static function _writeExternalAccount(
2575 int $a_usr_id,
2576 string $a_ext_id
2577 ): void {
2578 global $DIC;
2579 $ilDB = $DIC['ilDB'];
2580
2581 $ilDB->manipulateF(
2582 'UPDATE usr_data ' .
2583 ' SET ext_account = %s WHERE usr_id = %s',
2584 ['text', 'integer'],
2585 [$a_ext_id, $a_usr_id]
2586 );
2587 }
2588
2589 public static function _writeAuthMode(int $a_usr_id, string $a_auth_mode): void
2590 {
2591 global $DIC;
2592 $ilDB = $DIC['ilDB'];
2593
2594 $ilDB->manipulateF(
2595 'UPDATE usr_data ' .
2596 ' SET auth_mode = %s WHERE usr_id = %s',
2597 ['text', 'integer'],
2598 [$a_auth_mode, $a_usr_id]
2599 );
2600 }
2601
2605 public static function _lookupFields(int $a_user_id): array // Missing array type.
2606 {
2607 global $DIC;
2608 $ilDB = $DIC['ilDB'];
2609
2610 $res = $ilDB->queryF(
2611 'SELECT * FROM usr_data WHERE usr_id = %s',
2612 ['integer'],
2613 [$a_user_id]
2614 );
2615 $user_rec = $ilDB->fetchAssoc($res);
2616 return $user_rec;
2617 }
2618
2619 public static function _lookupActive(int $a_usr_id): bool
2620 {
2621 global $DIC;
2622 $ilDB = $DIC['ilDB'];
2623
2624 $query = 'SELECT usr_id FROM usr_data ' .
2625 'WHERE active = ' . $ilDB->quote(1, 'integer') . ' ' .
2626 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
2627 $res = $ilDB->query($query);
2628 while ($res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2629 return true;
2630 }
2631 return false;
2632 }
2633
2634 public static function _lookupLogin(int $a_user_id): string
2635 {
2636 return (string) self::_lookup($a_user_id, 'login') ?? '';
2637 }
2638
2639 public static function _lookupExternalAccount(int $a_user_id): string
2640 {
2641 return (string) self::_lookup($a_user_id, 'ext_account') ?? '';
2642 }
2643
2650 public static function _getExternalAccountsByAuthMode(
2651 string $a_auth_mode,
2652 bool $a_read_auth_default = false
2653 ): array {
2654 global $DIC;
2655
2656 $ilDB = $DIC['ilDB'];
2657 $ilSetting = $DIC['ilSetting'];
2658
2659 $q = 'SELECT login,usr_id,ext_account,auth_mode FROM usr_data ' .
2660 'WHERE auth_mode = %s';
2661 $types[] = 'text';
2662 $values[] = $a_auth_mode;
2663 if ($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode', ilAuthUtils::AUTH_LOCAL)) == $a_auth_mode) {
2664 $q .= ' OR auth_mode = %s ';
2665 $types[] = 'text';
2666 $values[] = 'default';
2667 }
2668
2669 $res = $ilDB->queryF($q, $types, $values);
2670 $accounts = [];
2671 while ($row = $ilDB->fetchObject($res)) {
2672 if ($row->auth_mode == 'default') {
2673 $accounts[$row->usr_id] = $row->login;
2674 } else {
2675 $accounts[$row->usr_id] = $row->ext_account;
2676 }
2677 }
2678 return $accounts;
2679 }
2680
2681 public static function _toggleActiveStatusOfUsers(
2682 array $a_usr_ids,
2683 bool $a_status
2684 ): void {
2685 global $DIC;
2686
2687 $ilDB = $DIC['ilDB'];
2688
2689 if ($a_status) {
2690 $q = 'UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ' .
2691 $ilDB->in('usr_id', $a_usr_ids, false, 'integer');
2692 $ilDB->manipulate($q);
2693 } else {
2694 $usrId_IN_usrIds = $ilDB->in('usr_id', $a_usr_ids, false, 'integer');
2695
2696 $q = 'UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds';
2697 $ilDB->manipulate($q);
2698
2699 $queryString = '
2700 UPDATE usr_data
2701 SET inactivation_date = %s
2702 WHERE inactivation_date IS NULL
2703 AND $usrId_IN_usrIds
2704 ';
2705 $ilDB->manipulateF($queryString, ['timestamp'], [ilUtil::now()]);
2706 }
2707 }
2708
2709 public static function _lookupAuthMode(int $a_usr_id): string
2710 {
2711 return (string) self::_lookup($a_usr_id, 'auth_mode');
2712 }
2713
2718 public static function _checkExternalAuthAccount(
2719 string $a_auth,
2720 string $a_account,
2721 bool $tryFallback = true
2722 ): ?string {
2723 $db = $GLOBALS['DIC']->database();
2724 $settings = $GLOBALS['DIC']->settings();
2725
2726 // Check directly with auth_mode
2727 $r = $db->queryF(
2728 'SELECT * FROM usr_data WHERE ' .
2729 ' ext_account = %s AND auth_mode = %s',
2730 ['text', 'text'],
2731 [$a_account, $a_auth]
2732 );
2733 if ($usr = $db->fetchAssoc($r)) {
2734 return $usr['login'];
2735 }
2736
2737 if (!$tryFallback) {
2738 return null;
2739 }
2740
2741 // For compatibility, check for login (no ext_account entry given)
2742 $res = $db->queryF(
2743 'SELECT login FROM usr_data ' .
2744 'WHERE login = %s AND auth_mode = %s AND (ext_account IS NULL OR ext_account = "") ',
2745 ['text', 'text'],
2746 [$a_account, $a_auth]
2747 );
2748 if ($usr = $db->fetchAssoc($res)) {
2749 return $usr['login'];
2750 }
2751
2752 // If auth_default == $a_auth => check for login
2753 if (ilAuthUtils::_getAuthModeName($settings->get('auth_mode')) == $a_auth) {
2754 $res = $db->queryF(
2755 'SELECT login FROM usr_data WHERE ' .
2756 ' ext_account = %s AND auth_mode = %s',
2757 ['text', 'text'],
2758 [$a_account, 'default']
2759 );
2760 if ($usr = $db->fetchAssoc($res)) {
2761 return $usr['login'];
2762 }
2763 // Search for login (no ext_account given)
2764 $res = $db->queryF(
2765 'SELECT login FROM usr_data ' .
2766 'WHERE login = %s AND (ext_account IS NULL OR ext_account = "") AND auth_mode = %s',
2767 ['text', 'text'],
2768 [$a_account, 'default']
2769 );
2770 if ($usr = $db->fetchAssoc($res)) {
2771 return $usr['login'];
2772 }
2773 }
2774 return null;
2775 }
2776
2777 public static function getUserIdByLogin(string $a_login): int
2778 {
2779 return (int) self::_lookupId($a_login);
2780 }
2781
2782 public static function getUserIdsByEmail(string $a_email): array
2783 {
2784 global $DIC;
2785 $ilDB = $DIC['ilDB'];
2786
2787 $res = $ilDB->queryF(
2788 'SELECT usr_id FROM usr_data ' .
2789 'WHERE email = %s and active = 1',
2790 ['text'],
2791 [$a_email]
2792 );
2793 $ids = [];
2794 while ($row = $ilDB->fetchObject($res)) {
2795 $ids[] = (int) $row->usr_id;
2796 }
2797
2798 return $ids;
2799 }
2800
2801 public static function getUserLoginsByEmail(string $a_email): array
2802 {
2803 global $DIC;
2804 $ilDB = $DIC['ilDB'];
2805
2806 $res = $ilDB->queryF(
2807 'SELECT login FROM usr_data ' .
2808 'WHERE email = %s and active = 1',
2809 ['text'],
2810 [$a_email]
2811 );
2812 $ids = [];
2813 while ($row = $ilDB->fetchObject($res)) {
2814 $ids[] = $row->login;
2815 }
2816
2817 return $ids;
2818 }
2819
2820 public static function _lookupId(
2821 string|array $a_user_str
2822 ): int|null|array {
2823 global $DIC;
2824 $ilDB = $DIC['ilDB'];
2825
2826 if (!is_array($a_user_str)) {
2827 $res = $ilDB->queryF(
2828 'SELECT usr_id FROM usr_data WHERE login = %s',
2829 ['text'],
2830 [$a_user_str]
2831 );
2832
2833 $user_rec = $ilDB->fetchAssoc($res);
2834 if (is_array($user_rec)) {
2835 return (int) $user_rec['usr_id'];
2836 }
2837
2838 return null;
2839 }
2840
2841 $set = $ilDB->query(
2842 'SELECT usr_id FROM usr_data ' .
2843 ' WHERE ' . $ilDB->in('login', $a_user_str, false, 'text')
2844 );
2845
2846 $ids = [];
2847 while ($rec = $ilDB->fetchAssoc($set)) {
2848 $ids[] = (int) $rec['usr_id'];
2849 }
2850
2851 return $ids;
2852 }
2853
2854 public static function _lookupLastLogin(int $a_user_id): string
2855 {
2856 return self::_lookup($a_user_id, 'last_login') ?? '';
2857 }
2858
2859 public static function _lookupFirstLogin(int $a_user_id): string
2860 {
2861 return self::_lookup($a_user_id, 'first_login') ?? '';
2862 }
2863
2864 public static function hasActiveSession(
2865 int $a_user_id,
2866 string $a_session_id
2867 ): bool {
2868 global $DIC;
2869 $ilDB = $DIC['ilDB'];
2870
2871 $set = $ilDB->queryf(
2872 '
2873 SELECT COUNT(*) session_count
2874 FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2875 ['integer', 'integer', 'text'],
2876 [$a_user_id, time(), $a_session_id]
2877 );
2878 $row = $ilDB->fetchAssoc($set);
2879 return (bool) $row['session_count'];
2880 }
2881
2882 public static function _readUsersProfileData(array $a_user_ids): array
2883 {
2884 global $DIC;
2885 $ilDB = $DIC['ilDB'];
2886
2887 $res = $ilDB->query('SELECT * FROM usr_data WHERE ' .
2888 $ilDB->in('usr_id', $a_user_ids, false, 'integer'));
2889 $user_data = [];
2890 while ($row = $ilDB->fetchAssoc($res)) {
2891 $user_data[$row['usr_id']] = $row;
2892 }
2893 return $user_data;
2894 }
2895
2896 public static function _getNumberOfUsersForStyle(
2897 string $a_skin,
2898 string $a_style
2899 ): int {
2900 global $DIC;
2901 $ilDB = $DIC['ilDB'];
2902
2903 $q = 'SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ' .
2904 ' WHERE up1.keyword= ' . $ilDB->quote('style', 'text') .
2905 ' AND up1.value= ' . $ilDB->quote($a_style, 'text') .
2906 ' AND up2.keyword= ' . $ilDB->quote('skin', 'text') .
2907 ' AND up2.value= ' . $ilDB->quote($a_skin, 'text') .
2908 ' AND up1.usr_id = up2.usr_id ';
2909
2910 $cnt_set = $ilDB->query($q);
2911
2912 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2913
2914 return (int) $cnt_rec['cnt'];
2915 }
2916
2917 public static function _getAllUserAssignedStyles(): array
2918 {
2919 global $DIC;
2920 $ilDB = $DIC['ilDB'];
2921
2922 $q = 'SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ' .
2923 ' WHERE up1.keyword = ' . $ilDB->quote('style', 'text') .
2924 ' AND up2.keyword = ' . $ilDB->quote('skin', 'text') .
2925 ' AND up1.usr_id = up2.usr_id';
2926
2927 $sty_set = $ilDB->query($q);
2928
2929 $styles = [];
2930 while ($sty_rec = $ilDB->fetchAssoc($sty_set)) {
2931 $styles[] = $sty_rec['skin'] . ':' . $sty_rec['style'];
2932 }
2933
2934 return $styles;
2935 }
2936
2940 public static function _getNumberOfUsersPerAuthMode(): array // Missing array type.
2941 {
2942 global $DIC;
2943
2944 $ilDB = $DIC['ilDB'];
2945
2946 $r = $ilDB->query('SELECT count(*) AS cnt, auth_mode FROM usr_data ' .
2947 'GROUP BY auth_mode');
2948 $cnt_arr = [];
2949 while ($cnt = $ilDB->fetchAssoc($r)) {
2950 $cnt_arr[$cnt['auth_mode']] = (int) $cnt['cnt'];
2951 }
2952
2953 return $cnt_arr;
2954 }
2955
2956 public static function _getLocalAccountsForEmail(string $a_email): array // Missing array type.
2957 {
2958 global $DIC;
2959
2960 $ilDB = $DIC['ilDB'];
2961 $ilSetting = $DIC['ilSetting'];
2962
2963 // default set to local (1)?
2964
2965 $q = 'SELECT * FROM usr_data WHERE ' .
2966 ' email = %s AND (auth_mode = %s ';
2967 $types = ['text', 'text'];
2968 $values = [$a_email, 'local'];
2969
2970 if ($ilSetting->get('auth_mode') == 1) {
2971 $q .= ' OR auth_mode = %s';
2972 $types[] = 'text';
2973 $values[] = 'default';
2974 }
2975
2976 $q .= ')';
2977
2978 $users = [];
2979 $usr_set = $ilDB->queryF($q, $types, $values);
2980 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
2981 $users[$usr_rec['usr_id']] = $usr_rec['login'];
2982 }
2983
2984 return $users;
2985 }
2986
2987 public static function _moveUsersToStyle(
2988 string $a_from_skin,
2989 string $a_from_style,
2990 string $a_to_skin,
2991 string $a_to_style
2992 ): void {
2993 global $DIC;
2994 $ilDB = $DIC['ilDB'];
2995
2996 $q = 'SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ' .
2997 ' WHERE up1.keyword= ' . $ilDB->quote('style', 'text') .
2998 ' AND up1.value= ' . $ilDB->quote($a_from_style, 'text') .
2999 ' AND up2.keyword= ' . $ilDB->quote('skin', 'text') .
3000 ' AND up2.value= ' . $ilDB->quote($a_from_skin, 'text') .
3001 ' AND up1.usr_id = up2.usr_id ';
3002
3003 $usr_set = $ilDB->query($q);
3004
3005 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3006 $ilDB->replace(
3007 'usr_pref',
3008 [
3009 'usr_id' => [ilDBConstants::T_INTEGER, $usr_rec['usr_id']],
3010 'keyword' => [ilDBConstants::T_TEXT, 'skin'],
3011 ],
3012 [
3013 'value' => [ilDBConstants::T_TEXT, $a_to_skin]
3014 ]
3015 );
3016 $ilDB->replace(
3017 'usr_pref',
3018 [
3019 'usr_id' => [ilDBConstants::T_INTEGER, $usr_rec['usr_id']],
3020 'keyword' => [ilDBConstants::T_TEXT, 'style'],
3021 ],
3022 [
3023 'value' => [ilDBConstants::T_TEXT, $a_to_style]
3024 ]
3025 );
3026 }
3027 }
3028
3029 public static function _getUsersForClipboadObject(
3030 string $a_type,
3031 int $a_id
3032 ): array {
3033 global $DIC;
3034 $ilDB = $DIC['ilDB'];
3035
3036 $q = 'SELECT DISTINCT user_id FROM personal_clipboard WHERE ' .
3037 'item_id = ' . $ilDB->quote($a_id, 'integer') . ' AND ' .
3038 'type = ' . $ilDB->quote($a_type, 'text');
3039 $user_set = $ilDB->query($q);
3040 $users = [];
3041 while ($user_rec = $ilDB->fetchAssoc($user_set)) {
3042 $users[] = (int) $user_rec['user_id'];
3043 }
3044
3045 return $users;
3046 }
3047
3048 public static function _getImportedUserId(
3049 string $i2_id
3050 ): int {
3051 global $DIC;
3052 $ilDB = $DIC['ilDB'];
3053
3054 $query = 'SELECT obj_id FROM object_data WHERE import_id = ' .
3055 $ilDB->quote($i2_id, 'text');
3056
3057 $res = $ilDB->query($query);
3058 $id = 0;
3059 while ($row = $ilDB->fetchObject($res)) {
3060 $id = (int) $row->obj_id;
3061 }
3062 return $id;
3063 }
3064
3065 public static function lookupOrgUnitsRepresentation(
3066 int $a_usr_id
3067 ): string {
3068 return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3069 }
3070
3071 public static function _getAvatar(int $a_usr_id): Avatar
3072 {
3073 $define = new ilUserAvatarResolver($a_usr_id ?: ANONYMOUS_USER_ID);
3074 $define->setSize('xsmall');
3075 return $define->getAvatar();
3076 }
3077
3078 public static function _getPersonalPicturePath(
3079 int $usr_id,
3080 string $size = 'small',
3081 bool $force_pic = false
3082 ): string {
3083 $define = new ilUserAvatarResolver($usr_id);
3084 $define->setForcePicture($force_pic);
3085 $define->setSize($size);
3086 return $define->getLegacyPictureURL();
3087 }
3088
3089 public static function copyProfilePicturesToDirectory(
3090 int $a_user_id,
3091 string $a_dir
3092 ): void {
3093 global $DIC;
3094 $irss = $DIC->resourceStorage();
3095
3096 $clean_dir = trim(str_replace('..', '', $a_dir));
3097 if ($clean_dir == '' || !is_dir($clean_dir)) {
3098 return;
3099 }
3100 $avatar_rid = (new ilObjUser($a_user_id))->getAvatarRid();
3101 if ($avatar_rid === null) {
3102 return;
3103 }
3104
3105 file_put_contents(
3106 $clean_dir . '/usr_' . $a_user_id . '.jpg',
3107 $irss->consume()->stream($avatar_rid)->getStream()->getContents()
3108 );
3109 }
3110
3111 public static function _lookupFeedHash(
3112 int $a_user_id,
3113 bool $a_create = false
3114 ): ?string {
3115 global $DIC;
3116 $ilDB = $DIC['ilDB'];
3117
3118 if ($a_user_id > 0) {
3119 $set = $ilDB->queryF(
3120 'SELECT feed_hash from usr_data WHERE usr_id = %s',
3121 ['integer'],
3122 [$a_user_id]
3123 );
3124 if ($rec = $ilDB->fetchAssoc($set)) {
3125 if (strlen($rec['feed_hash']) == 32) {
3126 return $rec['feed_hash'];
3127 } elseif ($a_create) {
3128 $hash = md5(random_int(1, 9999999) + str_replace(' ', '', microtime()));
3129 $ilDB->manipulateF(
3130 'UPDATE usr_data SET feed_hash = %s' .
3131 ' WHERE usr_id = %s',
3132 ['text', 'integer'],
3133 [$hash, $a_user_id]
3134 );
3135 return $hash;
3136 }
3137 }
3138 }
3139 return null;
3140 }
3141
3142 public static function _getFeedPass(
3143 int $a_user_id
3144 ): ?string {
3145 if ($a_user_id > 0) {
3146 return self::_lookupPref($a_user_id, 'priv_feed_pass');
3147 }
3148 return null;
3149 }
3150}
$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.
const FETCHMODE_OBJECT
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:26
global $ilSetting
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:25
$GLOBALS["DIC"]
Definition: wac.php:54