ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
UserIsPublic.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\User\Settings\Settings as UserPreferences;
24use ilObjUser;
25use ILIAS\User\Profile\Profile as UserProfile;
26
27class UserIsPublic implements Criterion
28{
29 protected array $preloaded_profile_data = [];
30
31 public function __construct(
32 protected UserPreferences $user_preferences,
33 protected UserProfile $user_profile
34 ) {
35 }
36
37 public function preloadData(int ...$ids): void
38 {
39 foreach ($this->user_profile->getDataForMultiple($ids) as $data) {
40 $system_info = $data->getSystemInformation();
41 $id = $data->getId();
42 $this->preloaded_profile_data[$id]['active'] = $system_info['active'];
43 $this->preloaded_profile_data[$id]['time_limit_unlimited'] = $system_info['time_limit_unlimited'];
44 $this->preloaded_profile_data[$id]['time_limit_from'] = $system_info['time_limit_from'];
45 $this->preloaded_profile_data[$id]['time_limit_until'] = $system_info['time_limit_until'];
46 }
47 }
48
49 public function doesFulfill(int $id): bool
50 {
51 if ($id === ANONYMOUS_USER_ID) {
52 return false;
53 }
54
55 $public_profile = $this->user_preferences->getSettingValueFor($id, 'public_profile') ?? '';
56 if ($public_profile !== 'y' && $public_profile !== 'g') {
57 return false;
58 }
59
60 if (!($this->preloaded_profile_data[$id]['active'] ?? false)) {
61 return false;
62 }
63
64 if (
65 !($this->preloaded_profile_data[$id]['time_limit_unlimited'] ?? false) &&
66 (
67 ($this->preloaded_profile_data[$id]['time_limit_from'] ?? 0) >= time() ||
68 ($this->preloaded_profile_data[$id]['time_limit_until'] ?? 0) <= time()
69 )
70 ) {
71 return false;
72 }
73
74 return true;
75 }
76}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(protected UserPreferences $user_preferences, protected UserProfile $user_profile)
User class.
const ANONYMOUS_USER_ID
Definition: constants.php:27
$data
Definition: storeScorm.php:45