ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilUserProfileBadge.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  public function getId(): string
28  {
29  return 'profile';
30  }
31 
32  public function getCaption(): string
33  {
34  global $DIC;
35 
36  $lng = $DIC['lng'];
37  return $lng->txt('badge_user_profile');
38  }
39 
40  public function isSingleton(): bool
41  {
42  return false;
43  }
44 
45  public function getValidObjectTypes(): array // Missing array type.
46  {
47  return ['bdga'];
48  }
49 
51  {
52  return new ilUserProfileBadgeGUI();
53  }
54 
55  public function evaluate(int $user_id, array $params, ?array $config): bool // Missing array type.
56  {
57  global $DIC;
58 
59  $ilSetting = $DIC['ilSetting'];
60 
61  $user = new ilObjUser($user_id);
62 
63  // active profile portfolio?
64  $has_prtf = false;
65  if ($ilSetting->get('user_portfolios')) {
66  $has_prtf = ilObjPortfolio::getDefaultPortfolio($user_id);
67  }
68 
69  if (!$has_prtf) {
70  // is profile public?
71  if (!in_array($user->getPref('public_profile'), ['y', 'g'])) {
72  return false;
73  }
74  }
75 
76  // use getter mapping from user profile
77  $up = new ilUserProfile();
78  $pfields = $up->getStandardFields();
79 
80  // check for value AND publication status
81 
82  if ($config !== null && isset($config['profile'])) {
83  foreach ($config['profile'] as $field) {
84  $field = substr($field, 4);
85 
86  if (substr($field, 0, 4) === 'udf_') {
87  $udf_field_id = substr($field, 4);
88  if ($user->getPref('public_udf_' . $udf_field_id) !== 'y') {
89  return false;
90  }
91  $udf = $user->getUserDefinedData();
92  if ($udf['f_' . $udf_field_id] == '') {
93  return false;
94  }
95  } else {
96  if ($user->getPref('public_' . $field) !== 'y') {
97  return false;
98  }
99 
100  if ($field === 'upload') {
101  if (!$user->hasProfilePicture()) {
102  return false;
103  }
104  } elseif (isset($pfields[$field]['method'])) {
105  // use profile mapping if possible
106  $m = $pfields[$field]['method'];
107  if (!$user->{$m}()) {
108  return false;
109  }
110  }
111  }
112  }
113  }
114 
115  return true;
116  }
117 }
evaluate(int $user_id, array $params, ?array $config)
Evaluate if given user has earned badge.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getDefaultPortfolio(int $a_user_id)
Class ilUserProfile.
getId()
Get typ id (unique for component)
Class ilUserProfileBadge.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isSingleton()
Can only be created once?
global $DIC
Definition: shib_login.php:22
getValidObjectTypes()
Get valid (repository) "parent" object types.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getConfigGUIInstance()
Get GUI config instance.
global $ilSetting
Definition: privfeed.php:31
global $lng
Definition: privfeed.php:31