ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserProfileBadge.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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 $a_user_id, array $a_params, ?array $a_config): bool // Missing array type.
56  {
57  global $DIC;
58 
59  $ilSetting = $DIC['ilSetting'];
60 
61  $user = new ilObjUser($a_user_id);
62 
63  // active profile portfolio?
64  $has_prtf = false;
65  if ($ilSetting->get('user_portfolios')) {
66  $has_prtf = ilObjPortfolio::getDefaultPortfolio($a_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 ($a_config !== null && isset($a_config['profile'])) {
83  foreach ($a_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 (!ilObjUser::_getPersonalPicturePath($a_user_id, 'xsmall', true, true)) {
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 $a_user_id, array $a_params, ?array $a_config)
Evaluate if given user has earned badge.
$lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getDefaultPortfolio(int $a_user_id)
Get default portfolio of user.
Class ilUserProfile.
getId()
Get typ id (unique for component)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isSingleton()
Can only be created once?
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.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
global $ilSetting
Definition: privfeed.php:17